mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-09 22:18:00 +00:00
Implement color output for wasm builder (#4004)
* Implement color output for wasm builder * Fix `Cargo.lock`
This commit is contained in:
@@ -51,7 +51,7 @@ variables:
|
||||
- /^[0-9]+$/ # PRs
|
||||
retry:
|
||||
max: 2
|
||||
when:
|
||||
when:
|
||||
- runner_system_failure
|
||||
- unknown_failure
|
||||
- api_failure
|
||||
@@ -133,7 +133,7 @@ test-linux-stable: &test-linux
|
||||
variables:
|
||||
- $DEPLOY_TAG
|
||||
script:
|
||||
- time cargo test --all --release --verbose --locked |
|
||||
- WASM_BUILD_NO_COLOR=1 time cargo test --all --release --verbose --locked |
|
||||
tee output.log
|
||||
- sccache -s
|
||||
after_script:
|
||||
@@ -159,7 +159,7 @@ test-srml-staking: &test-srml-staking
|
||||
- $DEPLOY_TAG
|
||||
script:
|
||||
- cd srml/staking/
|
||||
- time cargo test --release --verbose --no-default-features --features std
|
||||
- WASM_BUILD_NO_COLOR=1 time cargo test --release --verbose --no-default-features --features std
|
||||
- sccache -s
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ test-linux-stable-int:
|
||||
script:
|
||||
- echo "___Logs will be partly shown at the end in case of failure.___"
|
||||
- echo "___Full log will be saved to the job artifacts only in case of failure.___"
|
||||
- RUST_LOG=sync=trace,consensus=trace,client=trace,state-db=trace,db=trace,forks=trace,state_db=trace,storage_cache=trace
|
||||
- WASM_BUILD_NO_COLOR=1 RUST_LOG=sync=trace,consensus=trace,client=trace,state-db=trace,db=trace,forks=trace,state_db=trace,storage_cache=trace
|
||||
time cargo test -p node-cli --release --verbose --locked -- --ignored --test-threads=1
|
||||
&> ${CI_COMMIT_SHORT_SHA}_int_failure.log
|
||||
- sccache -s
|
||||
@@ -230,7 +230,7 @@ build-linux-substrate:
|
||||
variables:
|
||||
- $DEPLOY_TAG
|
||||
script:
|
||||
- time cargo build --release --verbose
|
||||
- WASM_BUILD_NO_COLOR=1 time cargo build --release --verbose
|
||||
- mkdir -p ./artifacts/substrate/
|
||||
- mv ./target/release/substrate ./artifacts/substrate/.
|
||||
- echo -n "Substrate version = "
|
||||
|
||||
Generated
+10
-9
@@ -380,7 +380,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "cargo_metadata"
|
||||
version = "0.8.2"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -3300,7 +3300,7 @@ name = "proc-macro-crate"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6149,11 +6149,12 @@ dependencies = [
|
||||
name = "substrate-wasm-builder"
|
||||
version = "1.0.8"
|
||||
dependencies = [
|
||||
"atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"build-helper 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cargo_metadata 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cargo_metadata 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasm-gc-api 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@@ -6580,7 +6581,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.3"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -6664,7 +6665,7 @@ dependencies = [
|
||||
"serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7037,7 +7038,7 @@ dependencies = [
|
||||
"serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"zstd 0.4.28+zstd.1.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@@ -7358,7 +7359,7 @@ dependencies = [
|
||||
"checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c"
|
||||
"checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101"
|
||||
"checksum c_linked_list 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4964518bd3b4a8190e832886cdc0da9794f12e8e6c1613a9e90ff331c4c8724b"
|
||||
"checksum cargo_metadata 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "700b3731fd7d357223d0000f4dbf1808401b694609035c3c411fbc0cd375c426"
|
||||
"checksum cargo_metadata 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8d2d1617e838936c0d2323a65cc151e03ae19a7678dd24f72bccf27119b90a5d"
|
||||
"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427"
|
||||
"checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be"
|
||||
"checksum cexpr 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7fa24eb00d5ffab90eaeaf1092ac85c04c64aaf358ea6f84505b8116d24c6af"
|
||||
@@ -7770,7 +7771,7 @@ dependencies = [
|
||||
"checksum tokio-tls 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "354b8cd83825b3c20217a9dc174d6a0c67441a2fae5c41bcb1ea6679f6ae0f7c"
|
||||
"checksum tokio-udp 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f02298505547f73e60f568359ef0d016d5acd6e830ab9bc7c4a5b3403440121b"
|
||||
"checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445"
|
||||
"checksum toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c7aabe75941d914b72bf3e5d3932ed92ce0664d49d8432305a8b547c37227724"
|
||||
"checksum toml 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c04dffffeac90885436d23c692517bb5b8b3f8863e4afc15023628d067d667b7"
|
||||
"checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079"
|
||||
"checksum trie-bench 0.16.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3073600c543ed001319d7e092c46dfd8c245af1a218ec5c75eb01582660a2b3e"
|
||||
"checksum trie-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d0b62d27e8aa1c07414549ac872480ac82380bab39e730242ab08d82d7cc098a"
|
||||
|
||||
@@ -323,6 +323,8 @@ we support multiple environment variables:
|
||||
this environment variable should only be required in certain circumstances.
|
||||
* `WASM_TARGET_DIRECTORY` - Will copy any build WASM binary to the given directory. The path needs
|
||||
to be absolute.
|
||||
* `WASM_BUILD_RUSTFLAGS` - Extend `RUSTFLAGS` given to `cargo build` while building the wasm binary.
|
||||
* `WASM_BUILD_NO_COLOR` - Disable color output of the wasm build.
|
||||
|
||||
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
|
||||
|
||||
@@ -10,9 +10,10 @@ license = "GPL-3.0"
|
||||
|
||||
[dependencies]
|
||||
build-helper = "0.1.1"
|
||||
cargo_metadata = "0.8.2"
|
||||
cargo_metadata = "0.9.0"
|
||||
tempfile = "3.1.0"
|
||||
toml = "0.5.3"
|
||||
toml = "0.5.4"
|
||||
walkdir = "2.2.9"
|
||||
fs2 = "0.4.3"
|
||||
wasm-gc-api = "0.1.11"
|
||||
atty = "0.2.13"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
## WASM builder is a utility for building a project as a WASM binary
|
||||
# WASM builder is a utility for building a project as a WASM binary
|
||||
|
||||
The WASM builder is a tool that integrates the process of building the WASM binary of your project into the main
|
||||
`cargo` build process.
|
||||
|
||||
### Project setup
|
||||
## Project setup
|
||||
|
||||
A project that should be compiled as a WASM binary needs to:
|
||||
|
||||
@@ -34,25 +34,28 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
This will include the generated WASM binary as two constants `WASM_BINARY` and `WASM_BINARY_BLOATY`.
|
||||
The former is a compact WASM binary and the latter is not compacted.
|
||||
|
||||
### Environment variables
|
||||
## Environment variables
|
||||
|
||||
By using environment variables, you can configure which WASM binaries are built and how:
|
||||
|
||||
- `SKIP_WASM_BUILD` - Skips building any WASM binary. This is useful when only native should be recompiled.
|
||||
- `BUILD_DUMMY_WASM_BINARY` - Builds dummy WASM binaries. These dummy binaries are empty and useful
|
||||
- `SKIP_WASM_BUILD` - Skips building any wasm binary. This is useful when only native should be recompiled.
|
||||
- `BUILD_DUMMY_WASM_BINARY` - Builds dummy wasm binaries. These dummy binaries are empty and useful
|
||||
for `cargo check` runs.
|
||||
- `WASM_BUILD_TYPE` - Sets the build type for building WASM binaries. Supported values are `release` or `debug`.
|
||||
- `WASM_BUILD_TYPE` - Sets the build type for building wasm binaries. Supported values are `release` or `debug`.
|
||||
By default the build type is equal to the build type used by the main build.
|
||||
- `TRIGGER_WASM_BUILD` - Can be set to trigger a WASM build. On subsequent calls the value of the variable
|
||||
- `TRIGGER_WASM_BUILD` - Can be set to trigger a wasm build. On subsequent calls the value of the variable
|
||||
needs to change. As WASM builder instructs `cargo` to watch for file changes
|
||||
this environment variable should only be required in certain circumstances.
|
||||
- `WASM_BUILD_RUSTFLAGS` - Extend `RUSTFLAGS` given to `cargo build` while building the WASM binary.
|
||||
- `WASM_BUILD_RUSTFLAGS` - Extend `RUSTFLAGS` given to `cargo build` while building the wasm binary.
|
||||
- `WASM_BUILD_NO_COLOR` - Disable color output of the wasm build.
|
||||
- `WASM_TARGET_DIRECTORY` - Will copy any build wasm binary to the given directory. The path needs
|
||||
to be absolute.
|
||||
|
||||
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`.
|
||||
|
||||
### Prerequisites:
|
||||
## Prerequisites:
|
||||
|
||||
WASM builder requires the following prerequisities for building the WASM binary:
|
||||
|
||||
|
||||
@@ -54,16 +54,17 @@
|
||||
//!
|
||||
//! By using environment variables, you can configure which WASM binaries are built and how:
|
||||
//!
|
||||
//! - `SKIP_WASM_BUILD` - Skips building any WASM binary. This is useful when only native should be recompiled.
|
||||
//! - `BUILD_DUMMY_WASM_BINARY` - Builds dummy WASM binaries. These dummy binaries are empty and useful
|
||||
//! - `SKIP_WASM_BUILD` - Skips building any wasm binary. This is useful when only native should be recompiled.
|
||||
//! - `BUILD_DUMMY_WASM_BINARY` - Builds dummy wasm binaries. These dummy binaries are empty and useful
|
||||
//! for `cargo check` runs.
|
||||
//! - `WASM_BUILD_TYPE` - Sets the build type for building WASM binaries. Supported values are `release` or `debug`.
|
||||
//! - `WASM_BUILD_TYPE` - Sets the build type for building wasm binaries. Supported values are `release` or `debug`.
|
||||
//! By default the build type is equal to the build type used by the main build.
|
||||
//! - `TRIGGER_WASM_BUILD` - Can be set to trigger a WASM build. On subsequent calls the value of the variable
|
||||
//! - `TRIGGER_WASM_BUILD` - Can be set to trigger a wasm build. On subsequent calls the value of the variable
|
||||
//! needs to change. As WASM builder instructs `cargo` to watch for file changes
|
||||
//! this environment variable should only be required in certain circumstances.
|
||||
//! - `WASM_BUILD_RUSTFLAGS` - Extend `RUSTFLAGS` given to `cargo build` while building the WASM binary.
|
||||
//! - `WASM_TARGET_DIRECTORY` - Will copy any build WASM binary to the given directory. The path needs
|
||||
//! - `WASM_BUILD_RUSTFLAGS` - Extend `RUSTFLAGS` given to `cargo build` while building the wasm binary.
|
||||
//! - `WASM_BUILD_NO_COLOR` - Disable color output of the wasm build.
|
||||
//! - `WASM_TARGET_DIRECTORY` - Will copy any build wasm binary to the given directory. The path needs
|
||||
//! to be absolute.
|
||||
//!
|
||||
//! Each project can be skipped individually by using the environment variable `SKIP_PROJECT_NAME_WASM_BUILD`.
|
||||
@@ -82,24 +83,27 @@ use std::{env, fs, path::PathBuf, process::{Command, Stdio, self}};
|
||||
mod prerequisites;
|
||||
mod wasm_project;
|
||||
|
||||
/// Environment variable that tells us to skip building the WASM binary.
|
||||
/// Environment variable that tells us to skip building the wasm binary.
|
||||
const SKIP_BUILD_ENV: &str = "SKIP_WASM_BUILD";
|
||||
|
||||
/// Environment variable to force a certain build type when building the WASM binary.
|
||||
/// Environment variable to force a certain build type when building the wasm binary.
|
||||
/// Expects "debug" or "release" as value.
|
||||
///
|
||||
/// By default the WASM binary uses the same build type as the main cargo build.
|
||||
const WASM_BUILD_TYPE_ENV: &str = "WASM_BUILD_TYPE";
|
||||
|
||||
/// Environment variable to extend the `RUSTFLAGS` variable given to the WASM build.
|
||||
/// Environment variable to extend the `RUSTFLAGS` variable given to the wasm build.
|
||||
const WASM_BUILD_RUSTFLAGS_ENV: &str = "WASM_BUILD_RUSTFLAGS";
|
||||
|
||||
/// Environment variable to set the target directory to copy the final WASM binary.
|
||||
/// Environment variable to set the target directory to copy the final wasm binary.
|
||||
///
|
||||
/// The directory needs to be an absolute path.
|
||||
const WASM_TARGET_DIRECTORY: &str = "WASM_TARGET_DIRECTORY";
|
||||
|
||||
/// Build the currently built project as WASM binary.
|
||||
/// Environment variable to disable color output of the wasm build.
|
||||
const WASM_BUILD_NO_COLOR: &str = "WASM_BUILD_NO_COLOR";
|
||||
|
||||
/// Build the currently built project as wasm binary.
|
||||
///
|
||||
/// The current project is determined by using the `CARGO_MANIFEST_DIR` environment variable.
|
||||
///
|
||||
@@ -110,7 +114,7 @@ pub fn build_project(file_name: &str, cargo_manifest: &str) {
|
||||
build_project_with_default_rustflags(file_name, cargo_manifest, "");
|
||||
}
|
||||
|
||||
/// Build the currently built project as WASM binary.
|
||||
/// Build the currently built project as wasm binary.
|
||||
///
|
||||
/// The current project is determined by using the `CARGO_MANIFEST_DIR` environment variable.
|
||||
///
|
||||
|
||||
@@ -320,12 +320,16 @@ fn build_project(project: &Path, default_rustflags: &str) {
|
||||
env::var(crate::WASM_BUILD_RUSTFLAGS_ENV).unwrap_or_default(),
|
||||
);
|
||||
|
||||
build_cmd.args(&["build", "--target=wasm32-unknown-unknown"])
|
||||
build_cmd.args(&["rustc", "--target=wasm32-unknown-unknown"])
|
||||
.arg(format!("--manifest-path={}", manifest_path.display()))
|
||||
.env("RUSTFLAGS", rustflags)
|
||||
// We don't want to call ourselves recursively
|
||||
.env(crate::SKIP_BUILD_ENV, "");
|
||||
|
||||
if env::var(crate::WASM_BUILD_NO_COLOR).is_err() {
|
||||
build_cmd.arg("--color=always");
|
||||
}
|
||||
|
||||
if is_release_build() {
|
||||
build_cmd.arg("--release");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user