Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit d020e0f

Browse files
bkchrcmichi
authored andcommitted
Make wasm-builder less spammy (#3020)
* Don't clutter the output that much * Support building from `crates` or from `path` * Upgrade the versions * Update `Cargo.lock`
1 parent 28313a5 commit d020e0f

File tree

15 files changed

+75
-29
lines changed

15 files changed

+75
-29
lines changed

Cargo.lock

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/executor/runtime-test/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sandbox = { package = "sr-sandbox", path = "../../sr-sandbox", default-features
1212
substrate-primitives = { path = "../../primitives", default-features = false }
1313

1414
[build-dependencies]
15-
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.0" }
15+
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.1", path = "../../utils/wasm-builder-runner" }
1616

1717
[features]
1818
default = [ "std" ]

core/executor/runtime-test/build.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,11 @@
1717
use wasm_builder_runner::{build_current_project, WasmBuilderSource};
1818

1919
fn main() {
20-
build_current_project("wasm_binary.rs", WasmBuilderSource::Crates("1.0.1"));
20+
build_current_project(
21+
"wasm_binary.rs",
22+
WasmBuilderSource::CratesOrPath {
23+
path: "../../utils/wasm-builder",
24+
version: "1.0.2",
25+
},
26+
);
2127
}

core/test-runtime/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ substrate-executor = { path = "../executor" }
3131
substrate-test-runtime-client = { path = "./client" }
3232

3333
[build-dependencies]
34-
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.0" }
34+
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.1", path = "../utils/wasm-builder-runner" }
3535

3636
[features]
3737
default = [

core/test-runtime/build.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,11 @@
1717
use wasm_builder_runner::{build_current_project, WasmBuilderSource};
1818

1919
fn main() {
20-
build_current_project("wasm_binary.rs", WasmBuilderSource::Crates("1.0.1"));
20+
build_current_project(
21+
"wasm_binary.rs",
22+
WasmBuilderSource::CratesOrPath {
23+
path: "../utils/wasm-builder",
24+
version: "1.0.2",
25+
},
26+
);
2127
}

core/utils/wasm-builder-runner/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "substrate-wasm-builder-runner"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
authors = ["Parity Technologies <admin@parity.io>"]
55
description = "Runner for substrate-wasm-builder"
66
edition = "2018"

core/utils/wasm-builder-runner/src/lib.rs

+24-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
//!
2626
//! For more information see <https://crates.io/substrate-wasm-builder>
2727
28-
use std::{env, process::Command, fs, path::{PathBuf, Path}};
28+
use std::{env, process::{Command, self}, fs, path::{PathBuf, Path}};
2929

3030
/// Environment variable that tells us to skip building the WASM binary.
3131
const SKIP_BUILD_ENV: &str = "SKIP_WASM_BUILD";
@@ -56,8 +56,13 @@ pub enum WasmBuilderSource {
5656
repo: &'static str,
5757
rev: &'static str,
5858
},
59-
/// Use the given version released on crates.io
59+
/// Use the given version released on crates.io.
6060
Crates(&'static str),
61+
/// Use the given version released on crates.io or from the given path.
62+
CratesOrPath {
63+
version: &'static str,
64+
path: &'static str,
65+
}
6166
}
6267

6368
impl WasmBuilderSource {
@@ -75,6 +80,15 @@ impl WasmBuilderSource {
7580
WasmBuilderSource::Crates(version) => {
7681
format!("version = \"{}\"", version)
7782
}
83+
WasmBuilderSource::CratesOrPath { version, path } => {
84+
replace_back_slashes(
85+
format!(
86+
"path = \"{}\", version = \"{}\"",
87+
manifest_dir.join(path).display(),
88+
version
89+
)
90+
)
91+
}
7892
}
7993
}
8094
}
@@ -87,9 +101,9 @@ impl WasmBuilderSource {
87101
/// constant `WASM_BINARY` which contains the build wasm binary.
88102
/// `wasm_builder_path` - Path to the wasm-builder project, relative to `CARGO_MANIFEST_DIR`.
89103
pub fn build_current_project(file_name: &str, wasm_builder_source: WasmBuilderSource) {
90-
generate_rerun_if_changed_instructions();
91-
92104
if check_skip_build() {
105+
// If we skip the build, we still want to make sure to be called when an env variable changes
106+
generate_rerun_if_changed_instructions();
93107
return;
94108
}
95109

@@ -110,6 +124,10 @@ pub fn build_current_project(file_name: &str, wasm_builder_source: WasmBuilderSo
110124
create_project(&project_folder, &file_path, &manifest_dir, wasm_builder_source, &cargo_toml_path);
111125
run_project(&project_folder);
112126
}
127+
128+
// As last step we need to generate our `rerun-if-changed` stuff. If a build fails, we don't
129+
// want to spam the output!
130+
generate_rerun_if_changed_instructions();
113131
}
114132

115133
fn create_project(
@@ -164,7 +182,8 @@ fn run_project(project_folder: &Path) {
164182
}
165183

166184
if !cmd.status().map(|s| s.success()).unwrap_or(false) {
167-
panic!("Running WASM build runner failed!");
185+
// Don't spam the output with backtraces when a build failed!
186+
process::exit(1);
168187
}
169188
}
170189

core/utils/wasm-builder/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "substrate-wasm-builder"
3-
version = "1.0.1"
3+
version = "1.0.2"
44
authors = ["Parity Technologies <admin@parity.io>"]
55
description = "Utility for building WASM binaries"
66
edition = "2018"

core/utils/wasm-builder/src/lib.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
//! - wasm-gc
7979
//!
8080
81-
use std::{env, fs, path::PathBuf, process::Command};
81+
use std::{env, fs, path::PathBuf, process::{Command, Stdio}};
8282

8383
mod prerequisites;
8484
mod wasm_project;
@@ -156,8 +156,12 @@ fn create_out_file(file_name: &str, content: String) {
156156

157157
/// Get a cargo command that compiles with nightly
158158
fn get_nightly_cargo() -> Command {
159-
if Command::new("rustup").args(&["run", "nightly", "cargo"])
160-
.status().map(|s| s.success()).unwrap_or(false)
159+
if Command::new("rustup")
160+
.args(&["run", "nightly", "cargo"])
161+
.stdout(Stdio::null())
162+
.stderr(Stdio::null())
163+
.status()
164+
.map(|s| s.success()).unwrap_or(false)
161165
{
162166
let mut cmd = Command::new("rustup");
163167
cmd.args(&["run", "nightly", "cargo"]);

core/utils/wasm-builder/src/prerequisites.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ pub fn check() -> Option<&'static str> {
2727
return Some("Rust nightly not installed, please install it!")
2828
}
2929

30-
if Command::new("wasm-gc").stdout(Stdio::null()).status().map(|s| !s.success()).unwrap_or(true) {
30+
if Command::new("wasm-gc")
31+
.stdout(Stdio::null())
32+
.stderr(Stdio::null())
33+
.status()
34+
.map(|s| !s.success()).unwrap_or(true)
35+
{
3136
return Some("wasm-gc not installed, please install it!")
3237
}
3338

@@ -83,6 +88,8 @@ fn check_wasm_toolchain_installed() -> bool {
8388
let manifest_path = manifest_path.display().to_string();
8489
crate::get_nightly_cargo()
8590
.args(&["build", "--target=wasm32-unknown-unknown", "--manifest-path", &manifest_path])
91+
.stdout(Stdio::null())
92+
.stderr(Stdio::null())
8693
.status()
8794
.map(|s| s.success())
8895
.unwrap_or(false)

core/utils/wasm-builder/src/wasm_project.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
1616

17-
use std::{fs, path::{Path, PathBuf}, borrow::ToOwned, process::Command, env};
17+
use std::{fs, path::{Path, PathBuf}, borrow::ToOwned, process::{Command, self}, env};
1818

1919
use toml::value::Table;
2020

@@ -266,7 +266,8 @@ fn build_project(project: &Path) {
266266

267267
match build_cmd.status().map(|s| s.success()) {
268268
Ok(true) => {},
269-
_ => panic!("Failed to compile WASM binary"),
269+
// Use `process.exit(1)` to have a clean error output.
270+
_ => process::exit(1),
270271
}
271272
}
272273

node-template/runtime/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ consensus-aura = { package = "substrate-consensus-aura-primitives", path = "../.
2626
offchain-primitives = { package = "substrate-offchain-primitives", path = "../../core/offchain/primitives", default-features = false }
2727

2828
[build-dependencies]
29-
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.0" }
29+
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.1" }
3030

3131
[features]
3232
default = ["std"]

node-template/runtime/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
use wasm_builder_runner::{build_current_project, WasmBuilderSource};
1818

1919
fn main() {
20-
build_current_project("wasm_binary.rs", WasmBuilderSource::Crates("1.0.1"));
20+
build_current_project("wasm_binary.rs", WasmBuilderSource::Crates("1.0.2"));
2121
}

node/runtime/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ serde = { version = "1.0", optional = true }
3939
substrate-keyring = { path = "../../core/keyring", optional = true }
4040

4141
[build-dependencies]
42-
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.0" }
42+
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.1", path = "../../core/utils/wasm-builder-runner" }
4343

4444
[features]
4545
default = ["std"]

node/runtime/build.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ use wasm_builder_runner::{build_current_project, WasmBuilderSource};
1919
fn main() {
2020
build_current_project(
2121
"wasm_binary.rs",
22-
WasmBuilderSource::Crates("1.0.1"),
22+
WasmBuilderSource::CratesOrPath {
23+
path: "../../core/utils/wasm-builder",
24+
version: "1.0.2",
25+
},
2326
);
2427
}

0 commit comments

Comments
 (0)