-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(wasm-builder): add support for new wasm32v1-none target
#7008
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
Changes from 9 commits
78c5f4c
dcfbeb7
03714a0
2410530
575d805
8fffe18
ce0fb1d
3d26ce9
4c3b0ea
486be73
21245bc
d044efc
1f34087
8ae5e7b
f154742
6bfea51
5838f1e
b21ffdf
3628105
a804037
d8b1363
929e755
94e1fd1
f5fa789
6c058a9
3bab473
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 | ||
| # See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json | ||
|
|
||
| title: 'feat(wasm-builder): add support for new `wasm32v1-none` target' | ||
| doc: | ||
| - audience: Runtime Dev | ||
| description: | | ||
| Resolves [#5777](https://github.com/paritytech/polkadot-sdk/issues/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`](https://doc.rust-lang.org/beta/rustc/platform-support/wasm32v1-none.html) target that disables all "post-MVP" WASM features except `mutable-globals`. | ||
|
|
||
| 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! | ||
|
|
||
| crates: | ||
| - name: substrate-wasm-builder | ||
| bump: minor | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,22 +90,55 @@ impl<'a> DummyCrate<'a> { | |
| fs::create_dir_all(project_dir.join("src")).expect("Creating src dir does not fail; qed"); | ||
|
|
||
| let manifest_path = project_dir.join("Cargo.toml"); | ||
| write_file_if_changed( | ||
| &manifest_path, | ||
| r#" | ||
| [package] | ||
| name = "dummy-crate" | ||
| version = "1.0.0" | ||
| edition = "2021" | ||
|
|
||
| [workspace] | ||
| "#, | ||
| ); | ||
| match target { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't compile
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so i just decided to compile no_std cdylib with empty panic handler (runtime does the same thing, see wasm_project.rs file) |
||
| RuntimeTarget::Wasm => { | ||
| write_file_if_changed( | ||
| &manifest_path, | ||
| r#" | ||
| [package] | ||
| name = "dummy-crate" | ||
| version = "1.0.0" | ||
| edition = "2021" | ||
|
|
||
| [lib] | ||
| crate-type = ["cdylib"] | ||
|
|
||
| [workspace] | ||
| "#, | ||
| ); | ||
|
|
||
| write_file_if_changed( | ||
| project_dir.join("src/lib.rs"), | ||
| r#" | ||
| #![no_std] | ||
|
|
||
| #[panic_handler] | ||
| fn panic(_: &core::panic::PanicInfo<'_>) -> ! { | ||
| loop {} | ||
| } | ||
| "#, | ||
| ); | ||
| }, | ||
| RuntimeTarget::Riscv => { | ||
| write_file_if_changed( | ||
| &manifest_path, | ||
| r#" | ||
| [package] | ||
| name = "dummy-crate" | ||
| version = "1.0.0" | ||
| edition = "2021" | ||
|
|
||
| [workspace] | ||
| "#, | ||
| ); | ||
|
|
||
| write_file_if_changed( | ||
| project_dir.join("src/main.rs"), | ||
| "#![allow(missing_docs)] fn main() {}", | ||
| ); | ||
| }, | ||
| } | ||
|
|
||
| write_file_if_changed( | ||
| project_dir.join("src/main.rs"), | ||
| "#![allow(missing_docs)] fn main() {}", | ||
| ); | ||
| DummyCrate { cargo_command, temp, manifest_path, target } | ||
| } | ||
|
|
||
|
|
@@ -115,7 +148,7 @@ impl<'a> DummyCrate<'a> { | |
| // by accident - it can happen in some CI environments. | ||
| cmd.current_dir(&self.temp); | ||
| cmd.arg(subcommand) | ||
| .arg(format!("--target={}", self.target.rustc_target())) | ||
| .arg(format!("--target={}", self.target.rustc_target(self.cargo_command))) | ||
| .args(&["--manifest-path", &self.manifest_path.display().to_string()]); | ||
|
|
||
| if super::color_output_enabled() { | ||
|
|
@@ -172,7 +205,10 @@ impl<'a> DummyCrate<'a> { | |
| fn check_wasm_toolchain_installed( | ||
| cargo_command: CargoCommand, | ||
| ) -> Result<CargoCommandVersioned, String> { | ||
| let dummy_crate = DummyCrate::new(&cargo_command, RuntimeTarget::Wasm); | ||
| let target = RuntimeTarget::Wasm; | ||
| let rustc_target = target.rustc_target(&cargo_command); | ||
|
|
||
| let dummy_crate = DummyCrate::new(&cargo_command, target); | ||
|
|
||
| if let Err(error) = dummy_crate.try_build() { | ||
| let toolchain = dummy_crate.get_toolchain().unwrap_or("<unknown>".to_string()); | ||
|
|
@@ -181,9 +217,9 @@ fn check_wasm_toolchain_installed( | |
| ); | ||
| return match error { | ||
| None => Err(basic_error_message), | ||
| Some(error) if error.contains("the `wasm32-unknown-unknown` target may not be installed") => { | ||
| Err(colorize_error_message(&format!("Cannot compile the WASM runtime: the `wasm32-unknown-unknown` target is not installed!\n\ | ||
| You can install it with `rustup target add wasm32-unknown-unknown --toolchain {toolchain}` if you're using `rustup`."))) | ||
| Some(error) if error.contains(&format!("the `{rustc_target}` target may not be installed")) => { | ||
| Err(colorize_error_message(&format!("Cannot compile the WASM runtime: the `{rustc_target}` target is not installed!\n\ | ||
| You can install it with `rustup target add {rustc_target} --toolchain {toolchain}` if you're using `rustup`."))) | ||
| }, | ||
| // Apparently this can happen when we're running on a non Tier 1 platform. | ||
| Some(ref error) if error.contains("linker `rust-lld` not found") => | ||
|
|
@@ -203,7 +239,7 @@ fn check_wasm_toolchain_installed( | |
|
|
||
| let target = RuntimeTarget::new(); | ||
| assert!(target == RuntimeTarget::Wasm); | ||
| if target.rustc_target_build_std().is_some() { | ||
| if target.rustc_target_build_std(&cargo_command).is_some() { | ||
| if let Some(sysroot) = dummy_crate.get_sysroot() { | ||
| let src_path = | ||
| Path::new(sysroot.trim()).join("lib").join("rustlib").join("src").join("rust"); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.