mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 04:01:10 +00:00
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:
@@ -13,7 +13,7 @@ A project that should be compiled as a Wasm binary needs to:
|
||||
|
||||
The `build.rs` file needs to contain the following code:
|
||||
|
||||
```rust
|
||||
```rust,no_run
|
||||
fn main() {
|
||||
#[cfg(feature = "std")]
|
||||
{
|
||||
@@ -32,7 +32,7 @@ fn main() {
|
||||
|
||||
As the final step, you need to add the following to your project:
|
||||
|
||||
```rust
|
||||
```rust,ignore
|
||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
```
|
||||
|
||||
@@ -63,11 +63,17 @@ By using environment variables, you can configure which Wasm binaries are built
|
||||
- `WASM_TARGET_DIRECTORY` - Will copy any build Wasm binary to the given directory. The path needs to be absolute.
|
||||
- `WASM_BUILD_TOOLCHAIN` - The toolchain that should be used to build the Wasm binaries. The format needs to be the same
|
||||
as used by cargo, e.g. `nightly-2020-02-20`.
|
||||
- `WASM_BUILD_WORKSPACE_HINT` - Hint the workspace that is being built. This is normally not required as we walk up from
|
||||
the target directory until we find a `Cargo.toml`. If the target directory is changed for
|
||||
the build, this environment variable can be used to point to the actual workspace.
|
||||
- `WASM_BUILD_STD` - Sets whether the Rust's standard library crates will also be built. This is necessary to make sure
|
||||
the standard library crates only use the exact WASM feature set that our executor supports.
|
||||
Enabled by default.
|
||||
- `CARGO_NET_OFFLINE` - If `true`, `--offline` will be passed to all processes launched to prevent network access.
|
||||
Useful in offline environments.
|
||||
|
||||
Each project can be skipped individually by using the environment variable `SKIP_PROJECT_NAME_WASM_BUILD`. Where
|
||||
`PROJECT_NAME` needs to be replaced by the name of the cargo project, e.g. `node-runtime` will be `NODE_RUNTIME`.
|
||||
`PROJECT_NAME` needs to be replaced by the name of the cargo project, e.g. `kitchensink-runtime` will be `NODE_RUNTIME`.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
|
||||
Reference in New Issue
Block a user