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>
This commit is contained in:
Bastian Köcher
2019-09-18 13:52:18 +02:00
committed by GitHub
parent b46340cf8e
commit 49ad0dbdff
2 changed files with 23 additions and 11 deletions
+5
View File
@@ -193,6 +193,11 @@ You will also need to install the following packages:
[source, shell] [source, shell]
sudo apt install cmake pkg-config libssl-dev git clang libclang-dev 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: - Mac:
[source, shell] [source, shell]
brew install cmake pkg-config openssl git llvm brew install cmake pkg-config openssl git llvm
@@ -36,11 +36,7 @@ pub fn check() -> Option<&'static str> {
return Some("`wasm-gc` not installed, please install it!") return Some("`wasm-gc` not installed, please install it!")
} }
if !check_wasm_toolchain_installed() { check_wasm_toolchain_installed()
return Some("Rust WASM toolchain not installed, please install it!")
}
None
} }
fn check_nightly_installed() -> bool { fn check_nightly_installed() -> bool {
@@ -48,7 +44,7 @@ fn check_nightly_installed() -> bool {
command.is_nightly() 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"); 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"); 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() {}") fs::write(&test_file, "pub fn test() {}")
.expect("Writing to the test file does not fail; qed"); .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(); let manifest_path = manifest_path.display().to_string();
crate::get_nightly_cargo() crate::get_nightly_cargo()
.command() .command()
.args(&["build", "--target=wasm32-unknown-unknown", "--manifest-path", &manifest_path]) .args(&["build", "--target=wasm32-unknown-unknown", "--manifest-path", &manifest_path])
.stdout(Stdio::null()) .output()
.stderr(Stdio::null()) .map_err(|_| err_msg)
.status() .and_then(|s|
.map(|s| s.success()) if s.status.success() {
.unwrap_or(false) 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()
} }