Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WASI compilation for C++ #1083

Merged
merged 8 commits into from
Jun 21, 2024
Merged
Changes from 2 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
20 changes: 19 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,19 @@ impl Build {
cmd.push_cc_arg("-fno-plt".into());
}
}
if target.contains("wasm32-wasi") {
antaalt marked this conversation as resolved.
Show resolved Hide resolved
// WASI does not support exceptions yet.
cmd.push_cc_arg("-fno-exceptions".into());
let wasi_sdk = std::env::var("WASI_SDK").expect("Could not find WASI_SDK. Download it from github & setup environment variable WASI_SDK targetting the folder.");
antaalt marked this conversation as resolved.
Show resolved Hide resolved
let wasi_sysroot = format!("{}/share/wasi-sysroot/", wasi_sdk);
// If compiling for c++, link libc++ & libc++abi
if self.cpp {
self.cargo_output.print_metadata(&format_args!(
"cargo:rustc-flags=-L {}/lib/wasm32-wasi -lstatic=c++ -lstatic=c++abi",
wasi_sysroot
));
}
}
}
}

Expand Down Expand Up @@ -2861,7 +2874,11 @@ impl Build {
|| target == "wasm32-unknown-wasi"
|| target == "wasm32-unknown-unknown"
{
"clang".to_string()
if self.cpp {
"clang++".to_string()
} else {
"clang".to_string()
}
} else if target.contains("vxworks") {
if self.cpp {
"wr-c++".to_string()
Expand Down Expand Up @@ -3099,6 +3116,7 @@ impl Build {
| target.contains("openbsd")
| target.contains("aix")
| target.contains("linux-ohos")
| target.contains("wasm32")
{
Ok(Some("c++".to_string()))
} else if target.contains("android") {
Expand Down