Skip to content

Commit

Permalink
Collator overseer builder unification (paritytech#3335)
Browse files Browse the repository at this point in the history
resolve paritytech#3116

a follow-up on
paritytech#3061 (review):

- [x] reuse collator overseer builder for polkadot-node and collator
- [x] run zombienet test (0001-parachains-smoke-test.toml)
- [x] make wasm build errors more user-friendly for an easier problem
detection when using different toolchains in Rust

---------

Co-authored-by: ordian <write@reusable.software>
Co-authored-by: s0me0ne-unkn0wn <48632512+s0me0ne-unkn0wn@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 28, 2024
1 parent 9c96053 commit 4fbe140
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions substrate/utils/wasm-builder/src/prerequisites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ impl<'a> DummyCrate<'a> {
sysroot_cmd.output().ok().and_then(|o| String::from_utf8(o.stdout).ok())
}

fn get_toolchain(&self) -> Option<String> {
let sysroot = self.get_sysroot()?;
Path::new(sysroot.trim())
.file_name()
.and_then(|s| s.to_str())
.map(|s| s.to_string())
}

fn try_build(&self) -> Result<(), Option<String>> {
let Ok(result) = self.prepare_command("build").output() else { return Err(None) };
if !result.status.success() {
Expand All @@ -164,14 +172,15 @@ fn check_wasm_toolchain_installed(
let dummy_crate = DummyCrate::new(&cargo_command, RuntimeTarget::Wasm);

if let Err(error) = dummy_crate.try_build() {
let toolchain = dummy_crate.get_toolchain().unwrap_or("<unknown>".to_string());
let basic_error_message = colorize_error_message(
"Rust WASM toolchain is not properly installed; please install it!",
&format!("Rust WASM target for toolchain {toolchain} is not properly installed; please install it!")
);
return match error {
None => Err(basic_error_message),
Some(error) if error.contains("the `wasm32-unknown-unknown` target may not be installed") => {
Err(colorize_error_message("Cannot compile the WASM runtime: the `wasm32-unknown-unknown` target is not installed!\n\
You can install it with `rustup target add wasm32-unknown-unknown` if you're using `rustup`."))
Err(colorize_error_message(&format!("Cannot compile the WASM runtime: the `wasm32-unknown-unknown` target is not installed!\n\
You can install it with `rustup target add wasm32-unknown-unknown --toolchain {toolchain}` if you're using `rustup`.")))
},
// Apparently this can happen when we're running on a non Tier 1 platform.
Some(ref error) if error.contains("linker `rust-lld` not found") =>
Expand All @@ -193,9 +202,10 @@ fn check_wasm_toolchain_installed(
let src_path =
Path::new(sysroot.trim()).join("lib").join("rustlib").join("src").join("rust");
if !src_path.exists() {
let toolchain = dummy_crate.get_toolchain().unwrap_or("<toolchain>".to_string());
return Err(colorize_error_message(
"Cannot compile the WASM runtime: no standard library sources found!\n\
You can install them with `rustup component add rust-src` if you're using `rustup`.",
&format!("Cannot compile the WASM runtime: no standard library sources found at {}!\n\
You can install them with `rustup component add rust-src --toolchain {toolchain}` if you're using `rustup`.", src_path.display()),
))
}
}
Expand Down

0 comments on commit 4fbe140

Please sign in to comment.