Skip to content

Commit

Permalink
Fix compilation for wasm: env WASI_SYSROOT should be optional (#1114)
Browse files Browse the repository at this point in the history
* Fix compilation for wasm: env WASI_SYSROOT should be optional

On ubuntu-latest github action runner, it used to work without the environment variable.

Fixed #1109 #1113

* Add wasm32-unknown targets (#1115)

---------

Co-authored-by: Kuuuube <[email protected]>
  • Loading branch information
NobodyXu and Kuuuube authored Jun 30, 2024
1 parent bffb5c0 commit fe9ccd1
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,12 +1339,13 @@ impl Build {
}
// Link c++ lib from WASI sysroot
if Build::is_wasi_target(target.as_ref()) {
let wasi_sysroot = self.wasi_sysroot()?;
self.cargo_output.print_metadata(&format_args!(
"cargo:rustc-flags=-L {}/lib/{} -lstatic=c++ -lstatic=c++abi",
Path::new(&wasi_sysroot).display(),
target
));
if let Ok(wasi_sysroot) = self.wasi_sysroot() {
self.cargo_output.print_metadata(&format_args!(
"cargo:rustc-flags=-L {}/lib/{} -lstatic=c++ -lstatic=c++abi",
Path::new(&wasi_sysroot).display(),
target
));
}
}
}

Expand Down Expand Up @@ -1950,10 +1951,11 @@ impl Build {
// https://github.com/WebAssembly/exception-handling
cmd.push_cc_arg("-fno-exceptions".into());
// Link clang sysroot
let wasi_sysroot = self.wasi_sysroot()?;
cmd.push_cc_arg(
format!("--sysroot={}", Path::new(&wasi_sysroot).display()).into(),
);
if let Ok(wasi_sysroot) = self.wasi_sysroot() {
cmd.push_cc_arg(
format!("--sysroot={}", Path::new(&wasi_sysroot).display()).into(),
);
}
}
}
}
Expand Down Expand Up @@ -3940,12 +3942,14 @@ impl Build {
}
}
fn is_wasi_target(target: &str) -> bool {
const TARGETS: [&'static str; 5] = [
const TARGETS: [&'static str; 7] = [
"wasm32-wasi",
"wasm32-wasip1",
"wasm32-wasip1-threads",
"wasm32-wasip2",
"wasm32-wasi-threads",
"wasm32-unknown-wasi",
"wasm32-unknown-unknown",
];
return TARGETS.contains(&target);
}
Expand Down

0 comments on commit fe9ccd1

Please sign in to comment.