Skip to content

Commit

Permalink
Fix invalid wasi targets compatibility (#1105)
Browse files Browse the repository at this point in the history
* Fix invalid wasi targets compatibility

* Fix fmt issues
  • Loading branch information
antaalt authored Jun 29, 2024
1 parent 853fa8b commit 9d44677
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,8 @@ impl Build {
self.compile_objects(&objects)?;
self.assemble(lib_name, &dst.join(gnu_lib_name), &objects)?;

if self.get_target()?.contains("msvc") {
let target = self.get_target()?;
if target.contains("msvc") {
let compiler = self.get_base_compiler()?;
let atlmfc_lib = compiler
.env()
Expand Down Expand Up @@ -1337,11 +1338,12 @@ impl Build {
.print_metadata(&format_args!("cargo:rustc-link-lib={}", stdlib.display()));
}
// Link c++ lib from WASI sysroot
if self.get_target()?.contains("wasi") {
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/wasm32-wasi -lstatic=c++ -lstatic=c++abi",
Path::new(&wasi_sysroot).display()
"cargo:rustc-flags=-L {}/lib/{} -lstatic=c++ -lstatic=c++abi",
Path::new(&wasi_sysroot).display(),
target
));
}
}
Expand Down Expand Up @@ -1943,7 +1945,7 @@ impl Build {
cmd.push_cc_arg("-fno-plt".into());
}
}
if target == "wasm32-wasip1" {
if Build::is_wasi_target(target) {
// WASI does not support exceptions yet.
// https://github.com/WebAssembly/exception-handling
cmd.push_cc_arg("-fno-exceptions".into());
Expand Down Expand Up @@ -2893,10 +2895,7 @@ impl Build {
autodetect_android_compiler(target, &host, gnu, clang)
} else if target.contains("cloudabi") {
format!("{}-{}", target, traditional)
} else if target == "wasm32-wasi"
|| target == "wasm32-unknown-wasi"
|| target == "wasm32-unknown-unknown"
{
} else if Build::is_wasi_target(target) {
if self.cpp {
"clang++".to_string()
} else {
Expand Down Expand Up @@ -3940,6 +3939,16 @@ impl Build {
))
}
}
fn is_wasi_target(target: &str) -> bool {
const TARGETS: [&'static str; 5] = [
"wasm32-wasi",
"wasm32-wasip1",
"wasm32-wasip1-threads",
"wasm32-wasip2",
"wasm32-wasi-threads",
];
return TARGETS.contains(&target);
}

fn cuda_file_count(&self) -> usize {
self.files
Expand Down

0 comments on commit 9d44677

Please sign in to comment.