From d8f3bc781aa9b523e01f660a061041cd1f2b763d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Thu, 21 Mar 2024 11:00:31 +0100 Subject: [PATCH 1/2] wasm-builder: Also set `mcpu` for c deps --- substrate/utils/wasm-builder/src/wasm_project.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/substrate/utils/wasm-builder/src/wasm_project.rs b/substrate/utils/wasm-builder/src/wasm_project.rs index 13db9fce4310..b17a0d55d85c 100644 --- a/substrate/utils/wasm-builder/src/wasm_project.rs +++ b/substrate/utils/wasm-builder/src/wasm_project.rs @@ -848,6 +848,9 @@ fn build_bloaty_blob( if !cargo_cmd.supports_nightly_features() { build_cmd.env("RUSTC_BOOTSTRAP", "1"); } + + // Also tell the C deps. + build_cmd.env("CFLAGS", "-mcpu=mvp"); } println!("{}", colorize_info_message("Information that should be included in a bug report.")); From cdb693bf46bbc1895d3af3566cbcf1b8ae455226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Thu, 18 Jul 2024 10:10:31 +0200 Subject: [PATCH 2/2] Just lower the sign-ext to the MVP set. --- .../utils/wasm-builder/src/wasm_project.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/substrate/utils/wasm-builder/src/wasm_project.rs b/substrate/utils/wasm-builder/src/wasm_project.rs index c0db448b35c9..20fa9fc1aa33 100644 --- a/substrate/utils/wasm-builder/src/wasm_project.rs +++ b/substrate/utils/wasm-builder/src/wasm_project.rs @@ -245,6 +245,12 @@ fn maybe_compact_and_compress_wasm( compact_blob_path.as_ref().and_then(|p| try_compress_blob(&p.0, blob_name)); (compact_blob_path, compact_compressed_blob_path) } else { + // We at least want to lower the `sign-ext` code to `mvp`. + wasm_opt::OptimizationOptions::new_opt_level_0() + .add_pass(wasm_opt::Pass::SignextLowering) + .run(bloaty_blob_binary.bloaty_path(), bloaty_blob_binary.bloaty_path()) + .expect("Failed to lower sign-ext in WASM binary."); + (None, None) }; @@ -783,9 +789,7 @@ impl BuildConfiguration { (None, false) => { let profile = Profile::Release; build_helper::warning!( - "Unknown cargo profile `{}`. Defaulted to `{:?}` for the runtime build.", - name, - profile, + "Unknown cargo profile `{name}`. Defaulted to `{profile:?}` for the runtime build.", ); profile }, @@ -793,8 +797,7 @@ impl BuildConfiguration { (None, true) => { // We use println! + exit instead of a panic in order to have a cleaner output. println!( - "Unexpected profile name: `{}`. One of the following is expected: {:?}", - name, + "Unexpected profile name: `{name}`. One of the following is expected: {:?}", Profile::iter().map(|p| p.directory()).collect::>(), ); process::exit(1); @@ -894,9 +897,6 @@ fn build_bloaty_blob( if !cargo_cmd.supports_nightly_features() { build_cmd.env("RUSTC_BOOTSTRAP", "1"); } - - // Also tell the C deps. - build_cmd.env("CFLAGS", "-mcpu=mvp"); } println!("{}", colorize_info_message("Information that should be included in a bug report.")); @@ -966,13 +966,16 @@ fn compact_wasm( .mvp_features_only() .debug_info(true) .add_pass(wasm_opt::Pass::StripDwarf) + .add_pass(wasm_opt::Pass::SignextLowering) .run(bloaty_binary.bloaty_path(), &wasm_compact_path) .expect("Failed to compact generated WASM binary."); + println!( "{} {}", colorize_info_message("Compacted wasm in"), colorize_info_message(format!("{:?}", start.elapsed()).as_str()) ); + Some(WasmBinary(wasm_compact_path)) }