feat(wasm-builder): add support for new wasm32v1-none
target
#7008
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Resolves #5777
Previously
wasm-builder
used hacks such as-Zbuild-std
(requiredrust-src
component) andRUSTC_BOOTSTRAP=1
to build WASM runtime without WASM features:sign-ext
,multivalue
andreference-types
, but since Rust 1.84 (will be stable on 9 January, 2025) the situation has improved as there is newwasm32v1-none
target that disables all "post-MVP" WASM features exceptmutable-globals
.Previously, your
rust-toolchain.toml
looked like this:It should now be updated to something like this:
To build the runtime:
Integration
If you are using Rust 1.84 and above, then install the
wasm32v1-none
target instead ofwasm32-unknown-unknown
as shown above. You can also remove the unnecessaryrust-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 usetarget_family = "wasm"
ortarget_arch = "wasm32"
in the runtime code.Review Notes
Wasm builder requires the following prerequisites for building the WASM binary:
wasm32-unknown-unknown
targetrust-src
componentwasm32v1-none
target-Zbuild-std
andRUSTC_BOOTSTRAP=1
hacks andrust-src
component requirements!