Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,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 @@ -1334,11 +1335,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 @@ -1940,7 +1942,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 @@ -2888,10 +2890,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 @@ -3922,6 +3921,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);
Comment on lines +3925 to +3932
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we listing each target? Would target.contains("wasi") not be more forwards-compatible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, it was mostly to ensure if they had a target supporting exceptions or something like that to handle them separately, but maybe its overkill

}

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