diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 87afd5dfb1..1101568b0f 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -4832,7 +4832,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" -version = "1.0.3" +version = "1.0.4" dependencies = [ "build-helper 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "cargo_metadata 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/substrate/core/utils/wasm-builder/Cargo.toml b/substrate/core/utils/wasm-builder/Cargo.toml index eb010c2d54..44288dbcd2 100644 --- a/substrate/core/utils/wasm-builder/Cargo.toml +++ b/substrate/core/utils/wasm-builder/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "substrate-wasm-builder" -version = "1.0.3" +version = "1.0.4" authors = ["Parity Technologies "] description = "Utility for building WASM binaries" edition = "2018" diff --git a/substrate/core/utils/wasm-builder/src/wasm_project.rs b/substrate/core/utils/wasm-builder/src/wasm_project.rs index b460501e2e..2b05774054 100644 --- a/substrate/core/utils/wasm-builder/src/wasm_project.rs +++ b/substrate/core/utils/wasm-builder/src/wasm_project.rs @@ -97,14 +97,26 @@ pub fn create_and_compile(cargo_manifest: &Path) -> (WasmBinary, WasmBinaryBloat /// /// If the `Cargo.lock` cannot be found, we emit a warning and return `None`. fn find_cargo_lock(cargo_manifest: &Path) -> Option { - let mut path = build_helper::out_dir(); + fn find_impl(mut path: PathBuf) -> Option { + loop { + if path.join("Cargo.lock").exists() { + return Some(path.join("Cargo.lock")) + } - while path.pop() { - if path.join("Cargo.lock").exists() { - return Some(path.join("Cargo.lock")) + if !path.pop() { + return None; + } } } + if let Some(path) = find_impl(build_helper::out_dir()) { + return Some(path); + } + + if let Some(path) = find_impl(cargo_manifest.to_path_buf()) { + return Some(path); + } + build_helper::warning!( "Could not find `Cargo.lock` for `{}`, while searching from `{}`.", cargo_manifest.display(), @@ -136,12 +148,13 @@ fn get_wasm_binary_name(cargo_manifest: &Path) -> String { fn get_wasm_workspace_root() -> PathBuf { let mut out_dir = build_helper::out_dir(); - while out_dir.parent().is_some() { - if out_dir.parent().map(|p| p.ends_with("target")).unwrap_or(false) { - return out_dir; + loop { + match out_dir.parent() { + Some(parent) if out_dir.ends_with("build") => return parent.to_path_buf(), + _ => if !out_dir.pop() { + break; + } } - - out_dir.pop(); } panic!("Could not find target dir in: {}", build_helper::out_dir().display())