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

feat(wasm-builder): add support for new wasm32v1-none target #7008

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

StackOverflowExcept1on
Copy link

@StackOverflowExcept1on StackOverflowExcept1on commented Dec 27, 2024

Description

Resolves #5777

Previously wasm-builder used hacks such as -Zbuild-std (required rust-src component) and RUSTC_BOOTSTRAP=1 to build WASM runtime without WASM features: sign-ext, multivalue and reference-types, but since Rust 1.84 (will be stable on 9 January, 2025) the situation has improved as there is new wasm32v1-none target that disables all "post-MVP" WASM features except mutable-globals.

Previously, your rust-toolchain.toml looked like this:

[toolchain]
channel = "stable"
components = ["rust-src"]
targets = ["wasm32-unknown-unknown"]
profile = "default"

It should now be updated to something like this:

[toolchain]
channel = "beta"
targets = ["wasm32v1-none"]
profile = "default"

To build the runtime:

cargo build --package minimal-template-runtime --release

Integration

If you are using Rust 1.84 and above, then install the wasm32v1-none target instead of wasm32-unknown-unknown as shown above. You can also remove the unnecessary rust-src component.

Also note the slight differences in conditional compilation:

  • wasm32-unknown-unknown: #[cfg(all(target_family = "wasm", target_os = "unknown"))]
  • wasm32v1-none: #[cfg(all(target_family = "wasm", target_os = "none"))]

Avoid using target_os = "unknown" in #[cfg(...)] or #[cfg_attr(...)] and instead use target_family = "wasm" or target_arch = "wasm32" in the runtime code.

Review Notes

Wasm builder requires the following prerequisites for building the WASM binary:

  • Rust >= 1.68 and Rust < 1.84:
    • wasm32-unknown-unknown target
    • rust-src component
  • Rust >= 1.84:
    • wasm32v1-none target
    • no more -Zbuild-std and RUSTC_BOOTSTRAP=1 hacks and rust-src component requirements!

@bkchr bkchr added the T17-primitives Changes to primitives that are not covered by any other label. label Dec 27, 2024
@github-actions github-actions bot requested a review from bkchr December 27, 2024 19:24
Copy link

Review required! Latest push from author must always be reviewed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T17-primitives Changes to primitives that are not covered by any other label.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider removing useless -sign-ext flag in substrate-wasm-builder
2 participants