From 18ab8669b50a2963ab4487b2e0c64e5c1d9f6d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Thu, 8 Oct 2020 22:57:14 +0200 Subject: [PATCH 1/4] Release new version of wasm-builder-runner Besides the new version this merges `SKIP_WASM_BUILD` and `BUILD_DUMMY_WASM_BINARY`, this means a file is generated with `SKIP_WASM_BUILD` if no file existed before. --- Cargo.lock | 2 +- utils/wasm-builder-runner/Cargo.toml | 2 +- utils/wasm-builder-runner/src/lib.rs | 45 ++++++++++++++++++---------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c3ee635c37897..f0f9ac826659c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8882,7 +8882,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder-runner" -version = "1.0.6" +version = "1.0.7" [[package]] name = "subtle" diff --git a/utils/wasm-builder-runner/Cargo.toml b/utils/wasm-builder-runner/Cargo.toml index 346807d2e97f4..1fa24c9d1cd21 100644 --- a/utils/wasm-builder-runner/Cargo.toml +++ b/utils/wasm-builder-runner/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "substrate-wasm-builder-runner" -version = "1.0.6" +version = "1.0.7" authors = ["Parity Technologies "] description = "Runner for substrate-wasm-builder" edition = "2018" diff --git a/utils/wasm-builder-runner/src/lib.rs b/utils/wasm-builder-runner/src/lib.rs index 410af87546a4c..d63d77a66ea7a 100644 --- a/utils/wasm-builder-runner/src/lib.rs +++ b/utils/wasm-builder-runner/src/lib.rs @@ -230,16 +230,19 @@ impl WasmBuilder { /// Build the WASM binary. pub fn build(self) { + let out_dir = PathBuf::from(env::var("OUT_DIR").expect("`OUT_DIR` is set by cargo!")); + let file_path = out_dir.join(self.file_name.unwrap_or_else(|| "wasm_binary.rs".into())); + if check_skip_build() { // If we skip the build, we still want to make sure to be called when an env variable // changes generate_rerun_if_changed_instructions(); + + provide_dummy_wasm_binary(&file_path, true); + return; } - let out_dir = PathBuf::from(env::var("OUT_DIR").expect("`OUT_DIR` is set by cargo!")); - let file_path = out_dir.join(self.file_name.unwrap_or_else(|| "wasm_binary.rs".into())); - // Hash the path to the project cargo toml. let mut hasher = DefaultHasher::new(); self.project_cargo_toml.hash(&mut hasher); @@ -252,7 +255,7 @@ impl WasmBuilder { .join(format!("{}{}", project_name, hasher.finish())); if check_provide_dummy_wasm_binary() { - provide_dummy_wasm_binary(&file_path); + provide_dummy_wasm_binary(&file_path, false); } else { create_project( &project_folder, @@ -381,7 +384,7 @@ fn create_project( fs::create_dir_all(project_folder.join("src")) .expect("WASM build runner dir create can not fail; qed"); - fs::write( + write_file_if_changed( project_folder.join("Cargo.toml"), format!( r#" @@ -396,10 +399,10 @@ fn create_project( [workspace] "#, wasm_builder_source = wasm_builder_source.to_cargo_source(&get_manifest_dir()), - ) - ).expect("WASM build runner `Cargo.toml` writing can not fail; qed"); + ), + ); - fs::write( + write_file_if_changed( project_folder.join("src/main.rs"), format!( r#" @@ -418,8 +421,8 @@ fn create_project( file_path = replace_back_slashes(file_path.display()), cargo_toml_path = replace_back_slashes(cargo_toml_path.display()), default_rustflags = default_rustflags, - ) - ).expect("WASM build runner `main.rs` writing can not fail; qed"); + ), + ); } fn run_project(project_folder: &Path) { @@ -465,11 +468,16 @@ fn check_provide_dummy_wasm_binary() -> bool { } /// Provide the dummy WASM binary -fn provide_dummy_wasm_binary(file_path: &Path) { - fs::write( - file_path, - "pub const WASM_BINARY: Option<&[u8]> = None; pub const WASM_BINARY_BLOATY: Option<&[u8]> = None;", - ).expect("Writing dummy WASM binary should not fail"); +/// +/// If `skip_build` is `true`, it will only generate the wasm binary if it doesn't exists. +fn provide_dummy_wasm_binary(file_path: &Path, skip_build: bool) { + if !skip_build || !file_path.exists() { + write_file_if_changed( + file_path.into(), + "pub const WASM_BINARY: Option<&[u8]> = None;\ + pub const WASM_BINARY_BLOATY: Option<&[u8]> = None;".into(), + ); + } } /// Generate the `rerun-if-changed` instructions for cargo to make sure that the WASM binary is @@ -481,3 +489,10 @@ fn generate_rerun_if_changed_instructions() { println!("cargo:rerun-if-env-changed={}", FORCE_WASM_BUILD_ENV); println!("cargo:rerun-if-env-changed={}", generate_crate_skip_build_env_name()); } + +/// Write to the given `file` if the `content` is different. +fn write_file_if_changed(file: PathBuf, content: String) { + if fs::read_to_string(&file).ok().as_ref() != Some(&content) { + fs::write(&file, content).unwrap_or_else(|_| panic!("Writing `{}` can not fail!", file.display())); + } +} From 220ecc8c5bc4f1dd59d003322afab135ec24008f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Thu, 8 Oct 2020 23:49:33 +0200 Subject: [PATCH 2/4] Update utils/wasm-builder-runner/Cargo.toml --- utils/wasm-builder-runner/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/wasm-builder-runner/Cargo.toml b/utils/wasm-builder-runner/Cargo.toml index 1fa24c9d1cd21..2c54a5ec3a4d6 100644 --- a/utils/wasm-builder-runner/Cargo.toml +++ b/utils/wasm-builder-runner/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "substrate-wasm-builder-runner" -version = "1.0.7" +version = "2.0.0" authors = ["Parity Technologies "] description = "Runner for substrate-wasm-builder" edition = "2018" From c351f514d9759bc9b3ee09c6f1c29292f65454e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 9 Oct 2020 09:41:36 +0200 Subject: [PATCH 3/4] Update utils/wasm-builder-runner/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> --- utils/wasm-builder-runner/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/wasm-builder-runner/src/lib.rs b/utils/wasm-builder-runner/src/lib.rs index d63d77a66ea7a..04e06495c69b4 100644 --- a/utils/wasm-builder-runner/src/lib.rs +++ b/utils/wasm-builder-runner/src/lib.rs @@ -469,7 +469,7 @@ fn check_provide_dummy_wasm_binary() -> bool { /// Provide the dummy WASM binary /// -/// If `skip_build` is `true`, it will only generate the wasm binary if it doesn't exists. +/// If `skip_build` is `true`, it will only generate the wasm binary if it doesn't exist. fn provide_dummy_wasm_binary(file_path: &Path, skip_build: bool) { if !skip_build || !file_path.exists() { write_file_if_changed( From 6488abbf48d7cb9177f012c4f805069b67f12fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 9 Oct 2020 09:51:00 +0200 Subject: [PATCH 4/4] Update versions --- Cargo.lock | 2 +- bin/node-template/runtime/Cargo.toml | 2 +- bin/node/runtime/Cargo.toml | 2 +- client/executor/runtime-test/Cargo.toml | 2 +- primitives/runtime-interface/test-wasm-deprecated/Cargo.toml | 2 +- primitives/runtime-interface/test-wasm/Cargo.toml | 2 +- test-utils/runtime/Cargo.toml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f0f9ac826659c..f5779727fc056 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8882,7 +8882,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder-runner" -version = "1.0.7" +version = "2.0.0" [[package]] name = "subtle" diff --git a/bin/node-template/runtime/Cargo.toml b/bin/node-template/runtime/Cargo.toml index 393578f8d295d..ed5a114b813f8 100644 --- a/bin/node-template/runtime/Cargo.toml +++ b/bin/node-template/runtime/Cargo.toml @@ -48,7 +48,7 @@ hex-literal = { version = "0.3.1", optional = true } template = { version = "2.0.0", default-features = false, path = "../pallets/template", package = "pallet-template" } [build-dependencies] -wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-runner", path = "../../../utils/wasm-builder-runner" } +wasm-builder-runner = { version = "2.0.0", package = "substrate-wasm-builder-runner", path = "../../../utils/wasm-builder-runner" } [features] default = ["std"] diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index 47a26c92493d1..6142998ac063c 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -81,7 +81,7 @@ pallet-transaction-payment-rpc-runtime-api = { version = "2.0.0", default-featur pallet-vesting = { version = "2.0.0", default-features = false, path = "../../../frame/vesting" } [build-dependencies] -wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-runner", path = "../../../utils/wasm-builder-runner" } +wasm-builder-runner = { version = "2.0.0", package = "substrate-wasm-builder-runner", path = "../../../utils/wasm-builder-runner" } [dev-dependencies] sp-io = { version = "2.0.0", path = "../../../primitives/io" } diff --git a/client/executor/runtime-test/Cargo.toml b/client/executor/runtime-test/Cargo.toml index 4bd90176f5ecd..444b69f84496c 100644 --- a/client/executor/runtime-test/Cargo.toml +++ b/client/executor/runtime-test/Cargo.toml @@ -21,7 +21,7 @@ sp-runtime = { version = "2.0.0", default-features = false, path = "../../../pri sp-allocator = { version = "2.0.0", default-features = false, path = "../../../primitives/allocator" } [build-dependencies] -wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-runner", path = "../../../utils/wasm-builder-runner" } +wasm-builder-runner = { version = "2.0.0", package = "substrate-wasm-builder-runner", path = "../../../utils/wasm-builder-runner" } [features] default = [ "std" ] diff --git a/primitives/runtime-interface/test-wasm-deprecated/Cargo.toml b/primitives/runtime-interface/test-wasm-deprecated/Cargo.toml index 7e31fb8ad2b80..59790eb172eb3 100644 --- a/primitives/runtime-interface/test-wasm-deprecated/Cargo.toml +++ b/primitives/runtime-interface/test-wasm-deprecated/Cargo.toml @@ -19,7 +19,7 @@ sp-io = { version = "2.0.0", default-features = false, path = "../../io" } sp-core = { version = "2.0.0", default-features = false, path = "../../core" } [build-dependencies] -wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-runner", path = "../../../utils/wasm-builder-runner" } +wasm-builder-runner = { version = "2.0.0", package = "substrate-wasm-builder-runner", path = "../../../utils/wasm-builder-runner" } [features] default = [ "std" ] diff --git a/primitives/runtime-interface/test-wasm/Cargo.toml b/primitives/runtime-interface/test-wasm/Cargo.toml index 99cea1849e1b9..39c8df976a5ba 100644 --- a/primitives/runtime-interface/test-wasm/Cargo.toml +++ b/primitives/runtime-interface/test-wasm/Cargo.toml @@ -19,7 +19,7 @@ sp-io = { version = "2.0.0", default-features = false, path = "../../io" } sp-core = { version = "2.0.0", default-features = false, path = "../../core" } [build-dependencies] -wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-runner", path = "../../../utils/wasm-builder-runner" } +wasm-builder-runner = { version = "2.0.0", package = "substrate-wasm-builder-runner", path = "../../../utils/wasm-builder-runner" } [features] default = [ "std" ] diff --git a/test-utils/runtime/Cargo.toml b/test-utils/runtime/Cargo.toml index 4e388861f1bab..cb6147adf25c6 100644 --- a/test-utils/runtime/Cargo.toml +++ b/test-utils/runtime/Cargo.toml @@ -56,7 +56,7 @@ sc-executor = { version = "0.8.0", path = "../../client/executor" } substrate-test-runtime-client = { version = "2.0.0", path = "./client" } [build-dependencies] -wasm-builder-runner = { version = "1.0.5", package = "substrate-wasm-builder-runner", path = "../../utils/wasm-builder-runner" } +wasm-builder-runner = { version = "2.0.0", package = "substrate-wasm-builder-runner", path = "../../utils/wasm-builder-runner" } [features] default = [