Great post thank you! I always have wondered how to get that wasm-enabled Rust compiler and use it to successfully build a wasm binary
Do you have planned followups around this?
Thinking like making this easier for everyone by making wasm compilation first class in nixpkgs
I just tried some of those examples out:
nix build "https://flakehub.com/f/DeterminateSystems/nix-wasm-example/*.tar.gz#hello-wasm"
error:
… while updating the lock file of flake 'https://api.flakehub.com/f/pinned/DeterminateSystems/nix-wasm-example/0.1.60%252Brev-59f7311f76192b9dae3a2ceb7a86d955d125c198/018ff317-76e2-75f8-854d-2b78e045aaf5/source.tar.gz?narHash=sha256-FQ76BsTfNEV3H3g1XXrbXHQZzd1L02n4jxRL1tAD/m0%3D'
error: unsupported tarball input attribute 'lastModified'
(deleting the flake.lock
worked and produced a diff with out the lastModified field - is this a nix version thing?)
Yes, this is definitely a Nix version thing that I’ve encountered as well, although sadly I’m not quite sure which exact versions will work
No, I don’t have any specific follow-up planned. My helper functions worked well enough for my example and I’m not sure what a more generalized, cross-language solution for Nixpkgs would look like.
Check out this PR I’ve been working on recently to add support for wasm to buildRustCrate/crate2nix (offers much faster build time compared to naersk or buildRustPackage) buildRustCrate: add support for compiling to wasm32-unknown-unknown by Kranzes · Pull Request #319153 · NixOS/nixpkgs · GitHub
For something like buildRustPackage which uses Cargo to build your simply have to pass --target via cargoBuildFlags and add pkgs.rustc.llvmPackages.lld to nativeBuildInputs, the reason this works is because the rustc in nixpkgs is built with support for targeting wasm32-unknown-unknown out of the box. For Wasi you might need to configure it a bit differently though.
Awesome thank you for working on this!
I’d be more interested by wasi than wasm but this is a good start