Skip to content

Commit aa4a6cf

Browse files
authored
Fix WASM vs. WASI options (#1284)
1 parent 5835783 commit aa4a6cf

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/lib.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,11 +1994,15 @@ impl Build {
19941994
cmd.push_cc_arg("-fdata-sections".into());
19951995
}
19961996
// Disable generation of PIC on bare-metal for now: rust-lld doesn't support this yet
1997+
//
1998+
// `rustc` also defaults to disable PIC on WASM:
1999+
// <https://github.com/rust-lang/rust/blob/1.82.0/compiler/rustc_target/src/spec/base/wasm.rs#L101-L108>
19972000
if self.pic.unwrap_or(
19982001
target.os != "windows"
19992002
&& target.os != "none"
20002003
&& target.os != "uefi"
2001-
&& target.os != "wasi",
2004+
&& target.arch != "wasm32"
2005+
&& target.arch != "wasm64",
20022006
) {
20032007
cmd.push_cc_arg("-fPIC".into());
20042008
// PLT only applies if code is compiled with PIC support,
@@ -2009,10 +2013,17 @@ impl Build {
20092013
cmd.push_cc_arg("-fno-plt".into());
20102014
}
20112015
}
2012-
if target.os == "wasi" {
2016+
if target.arch == "wasm32" || target.arch == "wasm64" {
20132017
// WASI does not support exceptions yet.
20142018
// https://github.com/WebAssembly/exception-handling
2019+
//
2020+
// `rustc` also defaults to (currently) disable exceptions
2021+
// on all WASM targets:
2022+
// <https://github.com/rust-lang/rust/blob/1.82.0/compiler/rustc_target/src/spec/base/wasm.rs#L72-L77>
20152023
cmd.push_cc_arg("-fno-exceptions".into());
2024+
}
2025+
2026+
if target.os == "wasi" {
20162027
// Link clang sysroot
20172028
if let Ok(wasi_sysroot) = self.wasi_sysroot() {
20182029
cmd.push_cc_arg(
@@ -2704,12 +2715,10 @@ impl Build {
27042715
"{}-{}-{}-{}",
27052716
target.full_arch, target.vendor, target.os, traditional
27062717
)
2707-
} else if target.os == "wasi" {
2708-
if self.cpp {
2709-
"clang++".to_string()
2710-
} else {
2711-
"clang".to_string()
2712-
}
2718+
} else if target.arch == "wasm32" || target.arch == "wasm64" {
2719+
// Compiling WASM is not currently supported by GCC, so
2720+
// let's default to Clang.
2721+
clang.to_string()
27132722
} else if target.os == "vxworks" {
27142723
if self.cpp {
27152724
"wr-c++".to_string()
@@ -3094,7 +3103,7 @@ impl Build {
30943103
name = format!("em{}", tool).into();
30953104
Some(self.cmd(&name))
30963105
}
3097-
} else if target.arch == "wasm32" {
3106+
} else if target.arch == "wasm32" || target.arch == "wasm64" {
30983107
// Formally speaking one should be able to use this approach,
30993108
// parsing -print-search-dirs output, to cover all clang targets,
31003109
// including Android SDKs and other cross-compilation scenarios...

0 commit comments

Comments
 (0)