@@ -1363,6 +1363,12 @@ impl Build {
1363
1363
target
1364
1364
) ) ;
1365
1365
}
1366
+ } else if target. contains ( "wasm32" ) && target. contains ( "linux" ) {
1367
+ let musl_sysroot = self . wasm_musl_sysroot ( ) . unwrap ( ) ;
1368
+ self . cargo_output . print_metadata ( & format_args ! (
1369
+ "cargo:rustc-flags=-L {}/lib -lstatic=c++ -lstatic=c++abi" ,
1370
+ Path :: new( & musl_sysroot) . display( ) ,
1371
+ ) ) ;
1366
1372
}
1367
1373
}
1368
1374
@@ -2178,6 +2184,25 @@ impl Build {
2178
2184
}
2179
2185
2180
2186
cmd. push_cc_arg ( format ! ( "--target={}" , target) . into ( ) ) ;
2187
+ } else if target. contains ( "wasm32" ) && target. contains ( "linux" ) {
2188
+ // wasm32-linux currently uses the LLVM-18 wasi threads target
2189
+ cmd. push_cc_arg ( "--target=wasm32-wasi-threads" . into ( ) ) ;
2190
+ for x in & [
2191
+ "atomics" ,
2192
+ "bulk-memory" ,
2193
+ "mutable-globals" ,
2194
+ "sign-ext" ,
2195
+ "exception-handling" ,
2196
+ ] {
2197
+ cmd. push_cc_arg ( format ! ( "-m{}" , x) . into ( ) ) ;
2198
+ }
2199
+ for x in & [ "wasm-exceptions" , "declspec" ] {
2200
+ cmd. push_cc_arg ( format ! ( "-f{}" , x) . into ( ) ) ;
2201
+ }
2202
+ let musl_sysroot = self . wasm_musl_sysroot ( ) . unwrap ( ) ;
2203
+ cmd. push_cc_arg (
2204
+ format ! ( "--sysroot={}" , Path :: new( & musl_sysroot) . display( ) ) . into ( ) ,
2205
+ ) ;
2181
2206
} else {
2182
2207
cmd. push_cc_arg ( format ! ( "--target={}" , target) . into ( ) ) ;
2183
2208
}
@@ -2915,7 +2940,9 @@ impl Build {
2915
2940
autodetect_android_compiler ( target, & host, gnu, clang)
2916
2941
} else if target. contains ( "cloudabi" ) {
2917
2942
format ! ( "{}-{}" , target, traditional)
2918
- } else if Build :: is_wasi_target ( target) {
2943
+ } else if Build :: is_wasi_target ( target)
2944
+ || ( target. contains ( "wasm32" ) && target. contains ( "linux" ) )
2945
+ {
2919
2946
if self . cpp {
2920
2947
"clang++" . to_string ( )
2921
2948
} else {
@@ -3949,6 +3976,17 @@ impl Build {
3949
3976
version
3950
3977
}
3951
3978
3979
+ fn wasm_musl_sysroot ( & self ) -> Result < Arc < OsStr > , Error > {
3980
+ if let Some ( musl_sysroot_path) = self . getenv ( "WASM_MUSL_SYSROOT" ) {
3981
+ Ok ( musl_sysroot_path)
3982
+ } else {
3983
+ Err ( Error :: new (
3984
+ ErrorKind :: EnvVarNotFound ,
3985
+ "Environment variable WASM_MUSL_SYSROOT not defined for wasm32. Download sysroot from GitHub & setup environment variable MUSL_SYSROOT targeting the folder." ,
3986
+ ) )
3987
+ }
3988
+ }
3989
+
3952
3990
fn wasi_sysroot ( & self ) -> Result < Arc < OsStr > , Error > {
3953
3991
if let Some ( wasi_sysroot_path) = self . getenv ( "WASI_SYSROOT" ) {
3954
3992
Ok ( wasi_sysroot_path)
0 commit comments