naersk icon indicating copy to clipboard operation
naersk copied to clipboard

Support compiling to WASM

Open kevincox opened this issue 5 years ago • 2 comments

I see that this is on your radar but opened an issue to track any progress.

Requirements:

  • WASM binaries can be produced.
  • These binaries can be loaded and run in the web browser.

kevincox avatar Oct 01 '20 15:10 kevincox

Slowly making my way in this repo: https://github.com/ldesgoui/tf2.link My goal is to produce terraform configurations able to deploy Cloudflare Worker scripts with wasm attachments I've analyzed wrangler (the Cloudflare tool to deploy Worker scripts), which shell out to wasm-pack, which shells out to the version of wasm-bindgen that matches the one in your Cargo.toml. Instead of going through all these impure hoops, I lock the version of wasm-bindgen (with wasm-bindgen = "= 0.2.67") and packaged the cli at that exact version. I also plan on having multiple wasm binaries and decided that I might as well compile and process them together (they're packaged together anyways, they will share lots of dependencies so compilation times should be shorter) but that probably will hurt incremental compilation

ldesgoui avatar Nov 01 '20 23:11 ldesgoui

I think that since Cargo is doing all the heavy lifting for us, we basically already have WASM support. You just need to set CARGO_BUILD_TARGET to wasm32-unknown-unknown and maybe use lld as the linker. ~What doesn't work currently is copying the generated .wasm file to the derivation output path (I think you can work around that using a hacky postInstall hook. Haven't tried yet).~ You have to enable copyLibs.

I'm not sure if calling wasm-bindgen is in scope of this project, since you can easily do it yourself once you have the WASM module.

malte-v avatar Mar 04 '21 14:03 malte-v