Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wasm32-unknown-unknown to the Rust toolchain. #42613

Open
szilardszaloki opened this issue Dec 2, 2024 · 0 comments
Open

Add wasm32-unknown-unknown to the Rust toolchain. #42613

szilardszaloki opened this issue Dec 2, 2024 · 0 comments

Comments

@szilardszaloki
Copy link
Contributor

We want to use wasm-pack, which uses wasm-bindgen, which, in turn, uses the wasm32-unknown-unknown target.

  1. wasm32-unknown-unknown does not support the profiler. Chromium has it enabled under [build] in config.toml, but thankfully, there's a per-target option we can use to disable it for wasm32-unknown-unknown.

In config.toml.template:

[target.wasm32-unknown-unknown]
profiler = false
  1. wasm32-unknown-unknown uses rust-lld. Chromium doesn't explicitly specify in config.toml that it needs it, and even though it does show up at a couple locations:
third_party/rust-src/build/aarch64-apple-darwin/stage0/lib/rustlib/aarch64-apple-darwin/bin/rust-lld
third_party/rust-src/build/aarch64-apple-darwin/rustfmt/lib/rustlib/aarch64-apple-darwin/bin/rust-lld
third_party/rust-src/build/aarch64-apple-darwin/stage0-sysroot/lib/rustlib/aarch64-apple-darwin/bin/rust-lld

as a side-effect of building Rust, we are the ones who have to make sure it gets compiled by the stage 1 compiler and is available for wasm32-unknown-unknown.

In config.toml.template:

[rust]
lld = true

Now, since we want to use x.py's build subcommand which defaults to the stage 1 compiler, we need to have the stage 1 rustc compiler built first. The rustc toolchain needs to be built against Chromium's LLVM version, so we'll have to go through the same exact steps as they do.
The best shortcut I could find is to use their build_rust.py script's --prepare-run-xpy and --run-xpy flags.

  1. tools/rust % ./build_rust.py --prepare-run-xpy — this prepares the environment for x.py (checks out Rust, builds the LLVM libraries, adds CMake to the path, generates config.toml, etc.)

  2. tools/rust % ./build_rust.py --run-xpy build --build aarch64-apple-darwin --target aarch64-apple-darwin,wasm32-unknown-unknown --stage 1

  3. move build artifacts:

third_party/rust-src/build/aarch64-apple-darwin/stage1/lib/rustlib/aarch64-apple-darwin/bin/rust-lld ==> third_party/rust-toolchain/bin/rust-lld
third_party/rust-src/build/aarch64-apple-darwin/stage1/lib/rustlib/wasm32-unknown-unknown ==> third_party/rust-toolchain/lib/rustlib/wasm32-unknown-unknown

Obviously, compiling the above with every single build is not at all reasonable, so I suggest that we do what Chromium does with their Rust tooling: build it centrally and distribute it via gclient sync(-like mechanism).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants