Build the standard library crates when building the runtimes (#2217)

Our executor currently only supports the WASM MVP feature set, however
nowadays when compiling WASM the Rust compiler has more features enabled
by default.

We do set the `-C target-cpu=mvp` flag to make sure that *our* code gets
compiled in a way that is compatible with our executor, however this
doesn't affect Rust's standard library crates (`std`, `core` and
`alloc`) which are by default precompiled and still can make use of
these extra features.

So in this PR we force the compiler to also compile the standard library
crates for us to make sure that they also only use the MVP features.

I've added the `WASM_BUILD_STD` environment variable which can be used
to disable this behavior if set to `0`.

Unfortunately this *will* slow down the compile times when building
runtimes, but there isn't much that we can do about that.

Fixes https://github.com/paritytech/polkadot-sdk/issues/1755

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Koute
2023-11-27 19:40:27 +09:00
committed by GitHub
parent 0317501758
commit 2610450a18
6 changed files with 158 additions and 201 deletions
@@ -750,6 +750,25 @@ fn build_bloaty_blob(
build_cmd.arg("--offline");
}
// Our executor currently only supports the WASM MVP feature set, however nowadays
// when compiling WASM the Rust compiler has more features enabled by default.
//
// We do set the `-C target-cpu=mvp` flag to make sure that *our* code gets compiled
// in a way that is compatible with our executor, however this doesn't affect Rust's
// standard library crates (`std`, `core` and `alloc`) which are by default precompiled
// and still can make use of these extra features.
//
// So here we force the compiler to also compile the standard library crates for us
// to make sure that they also only use the MVP features.
if crate::build_std_required() {
// Unfortunately this is still a nightly-only flag, but FWIW it is pretty widely used
// so it's unlikely to break without a replacement.
build_cmd.arg("-Z").arg("build-std");
if !cargo_cmd.supports_nightly_features() {
build_cmd.env("RUSTC_BOOTSTRAP", "1");
}
}
println!("{}", colorize_info_message("Information that should be included in a bug report."));
println!("{} {:?}", colorize_info_message("Executing build command:"), build_cmd);
println!("{} {}", colorize_info_message("Using rustc version:"), cargo_cmd.rustc_version());
@@ -952,6 +971,7 @@ fn generate_rerun_if_changed_instructions(
println!("cargo:rerun-if-env-changed={}", crate::WASM_BUILD_RUSTFLAGS_ENV);
println!("cargo:rerun-if-env-changed={}", crate::WASM_TARGET_DIRECTORY);
println!("cargo:rerun-if-env-changed={}", crate::WASM_BUILD_TOOLCHAIN);
println!("cargo:rerun-if-env-changed={}", crate::WASM_BUILD_STD);
}
/// Track files and paths related to the given package to rerun `build.rs` on any relevant change.