From 49ad0dbdff394dc94e73c84b68809c1fed9776ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 18 Sep 2019 13:52:18 +0200 Subject: [PATCH] Make `wasm-builder` check for `rust-lld` (#3635) * Make `wasm-builder` check for `rust-lld` * Update README.adoc Co-Authored-By: Ricardo Rius <9488369+riusricardo@users.noreply.github.com> --- substrate/README.adoc | 5 ++++ .../utils/wasm-builder/src/prerequisites.rs | 29 ++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/substrate/README.adoc b/substrate/README.adoc index f700a554ce..39b0912b7d 100644 --- a/substrate/README.adoc +++ b/substrate/README.adoc @@ -193,6 +193,11 @@ You will also need to install the following packages: [source, shell] sudo apt install cmake pkg-config libssl-dev git clang libclang-dev +- Linux on ARM: +`rust-lld` is required for linking wasm, but is missing on non Tier 1 platforms. +So, use this https://github.com/Plume-org/Plume/blob/master/script/wasm-deps.sh[script] +to build `lld` and create the symlink `/usr/bin/rust-lld` to the build binary. + - Mac: [source, shell] brew install cmake pkg-config openssl git llvm diff --git a/substrate/core/utils/wasm-builder/src/prerequisites.rs b/substrate/core/utils/wasm-builder/src/prerequisites.rs index 52ff40887c..eeac6df33e 100644 --- a/substrate/core/utils/wasm-builder/src/prerequisites.rs +++ b/substrate/core/utils/wasm-builder/src/prerequisites.rs @@ -36,11 +36,7 @@ pub fn check() -> Option<&'static str> { return Some("`wasm-gc` not installed, please install it!") } - if !check_wasm_toolchain_installed() { - return Some("Rust WASM toolchain not installed, please install it!") - } - - None + check_wasm_toolchain_installed() } fn check_nightly_installed() -> bool { @@ -48,7 +44,7 @@ fn check_nightly_installed() -> bool { command.is_nightly() } -fn check_wasm_toolchain_installed() -> bool { +fn check_wasm_toolchain_installed() -> Option<&'static str> { let temp = tempdir().expect("Creating temp dir does not fail; qed"); fs::create_dir_all(temp.path().join("src")).expect("Creating src dir does not fail; qed"); @@ -72,13 +68,24 @@ fn check_wasm_toolchain_installed() -> bool { fs::write(&test_file, "pub fn test() {}") .expect("Writing to the test file does not fail; qed"); + let err_msg = "Rust WASM toolchain not installed, please install it!"; let manifest_path = manifest_path.display().to_string(); crate::get_nightly_cargo() .command() .args(&["build", "--target=wasm32-unknown-unknown", "--manifest-path", &manifest_path]) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .status() - .map(|s| s.success()) - .unwrap_or(false) + .output() + .map_err(|_| err_msg) + .and_then(|s| + if s.status.success() { + Ok(()) + } else { + match String::from_utf8(s.stderr) { + Ok(ref err) if err.contains("linker `rust-lld` not found") => { + Err("`rust-lld` not found, please install it!") + }, + _ => Err(err_msg) + } + } + ) + .err() }