Using the 'rustc' command to target wasm32-unknown-unknown

Hi,

I have the 'rust' and 'rust-src' packages installed (not rustup). I understand that it's possible to target wasm32-unknown-unknown just using the 'rustc' command. I think that I need to use the '-L' path option to be able to point to the right directories. It's the standard library that's important here, right?

You can install std for wasm with rustup component add rust-std-wasm32-unknown-unknown.

You'll need the standard library for wasm32-unknown-unknown, but I don't know where you can download it.

They do not use Rustup. I'm not sure how to cross-compile anything without it, though.

I have the 'rust-src' package which is the "source code for the Rust standard library". Also, 'rust-src' is a dependency for the 'rust-analyzer' package which requires the standard library, I believe. Wouldn't that have the needed directories for the '-L' option when using 'rustc'?

https://archlinux.org/packages/extra/x86_64/rust-src/

Here are the Wasm related directories from the 'rust-src' package:

  • usr/lib/rustlib/src/rust/library/stdarch/crates/core_arch/src/wasm32/
  • usr/lib/rustlib/src/rust/library/stdarch/crates/core_arch/src/wasm32/atomic.rs
  • usr/lib/rustlib/src/rust/library/stdarch/crates/core_arch/src/wasm32/memory.rs
  • usr/lib/rustlib/src/rust/library/stdarch/crates/core_arch/src/wasm32/mod.rs
  • usr/lib/rustlib/src/rust/library/stdarch/crates/core_arch/src/wasm32/relaxed_simd.rs
  • usr/lib/rustlib/src/rust/library/stdarch/crates/core_arch/src/wasm32/simd128.rs
  • usr/lib/rustlib/src/rust/library/portable-simd/crates/core_simd/src/vendor/wasm32.rs
  • usr/lib/rustlib/src/rust/library/stdarch/ci/docker/wasm32-wasip1/
  • usr/lib/rustlib/src/rust/library/stdarch/ci/docker/wasm32-wasip1/Dockerfile

Rustc doesn't have builtin knowledge on how to build the standard library from source. It expects a pre-compiled version in it's sysroot. Cargo has support for building the standard library behind the -Zbuild-std flag, but this is only available on nightly rustc due to being unstable.

Assuming you installed rustc from using ArchLinux's pacman, you can install the rust-wasm package for a precompiled standard library for both wasm32-unknown-unknown and wasm32-wasi.

1 Like

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.