Target wasm32-unknown-unknown without wasm-pack?

Is there a simple way to use target wasm32-unknown-unknown to generate a wasm to load in index.html without wasm-pack?

Problem I am facing:

  1. cargo build --target wasm32-unknown-unknown --release is very fast

  2. wasm-pack --dev generates very slow binaries

  3. wasm-pack --release takes lots of compile time (much longer than 1)

Thus, if there was some way to just use the wasm from step (1) would be ideal.

EDIT: in the end, I need to run everything in the browserr

You absolutely can load the wasm generated by cargo build --target … verbatim. It won't be as optimized though, since wasm-pack runs some external tools to postprocess/post-LTO the binary.

@ZiCog linked this a while back, and it helped me build a few scripts to use wasm-in-a-browser without tools that I felt performed too much magic.

Ah yes, forgot about that.

I have a fully working example here: GitHub - ZiCog/insane-british-anagram-rust: Rust program to find anagrams in the Debian british-english-insane dictionary file.

That is a Rust program that finds all the anagrams in the English dictionary (as found in Debian's dictionary fie). It runs as a regular executable, under node.js and in the browser.

WARNING! That was about my first attempts at writing Rust at all so it's probably wise to ignore most of the Rust code as far as any useful example. But it does interface between Rust and Javascript.

See the file for how to compile it with Cargo and bind it with wasm-bindgen.
See index/index.html for how that gets loaded and used from JS in the browser.

I'm totally with you on the "magic" that is rife in the web world. You find yourself persuaded to use webpack, wasm-pack, this-pack, other-pack. I once needed up with a web page using React and webpack that took forever to figure out how to configure it to build and took longer to "pack" than most C++ and Rust programs I write. Which is totally abhorrent considering we are using a scripting language that was designed to be easy to use and have no build time.

1 Like

@ZiCog 's worked. Thanks everyone!

Great to hear. Now I just have to remind myself how it all hangs together.

Wow, that was nearly three years ago. And I have still barely scratched the surface of Rust.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.