@@ -1994,11 +1994,15 @@ impl Build {
1994
1994
cmd. push_cc_arg ( "-fdata-sections" . into ( ) ) ;
1995
1995
}
1996
1996
// 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>
1997
2000
if self . pic . unwrap_or (
1998
2001
target. os != "windows"
1999
2002
&& target. os != "none"
2000
2003
&& target. os != "uefi"
2001
- && target. os != "wasi" ,
2004
+ && target. arch != "wasm32"
2005
+ && target. arch != "wasm64" ,
2002
2006
) {
2003
2007
cmd. push_cc_arg ( "-fPIC" . into ( ) ) ;
2004
2008
// PLT only applies if code is compiled with PIC support,
@@ -2009,10 +2013,17 @@ impl Build {
2009
2013
cmd. push_cc_arg ( "-fno-plt" . into ( ) ) ;
2010
2014
}
2011
2015
}
2012
- if target. os == "wasi " {
2016
+ if target. arch == "wasm32" || target . arch == "wasm64 " {
2013
2017
// WASI does not support exceptions yet.
2014
2018
// 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>
2015
2023
cmd. push_cc_arg ( "-fno-exceptions" . into ( ) ) ;
2024
+ }
2025
+
2026
+ if target. os == "wasi" {
2016
2027
// Link clang sysroot
2017
2028
if let Ok ( wasi_sysroot) = self . wasi_sysroot ( ) {
2018
2029
cmd. push_cc_arg (
@@ -2704,12 +2715,10 @@ impl Build {
2704
2715
"{}-{}-{}-{}" ,
2705
2716
target. full_arch, target. vendor, target. os, traditional
2706
2717
)
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 ( )
2713
2722
} else if target. os == "vxworks" {
2714
2723
if self . cpp {
2715
2724
"wr-c++" . to_string ( )
@@ -3094,7 +3103,7 @@ impl Build {
3094
3103
name = format ! ( "em{}" , tool) . into ( ) ;
3095
3104
Some ( self . cmd ( & name) )
3096
3105
}
3097
- } else if target. arch == "wasm32" {
3106
+ } else if target. arch == "wasm32" || target . arch == "wasm64" {
3098
3107
// Formally speaking one should be able to use this approach,
3099
3108
// parsing -print-search-dirs output, to cover all clang targets,
3100
3109
// including Android SDKs and other cross-compilation scenarios...
0 commit comments