Skip to content

Commit 684e471

Browse files
committed
Added support for wasm32-wali-linux-musl target
1 parent dcd8ed3 commit 684e471

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/lib.rs

+39-1
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,12 @@ impl Build {
13631363
target
13641364
));
13651365
}
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+
));
13661372
}
13671373
}
13681374

@@ -2178,6 +2184,25 @@ impl Build {
21782184
}
21792185

21802186
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+
);
21812206
} else {
21822207
cmd.push_cc_arg(format!("--target={}", target).into());
21832208
}
@@ -2915,7 +2940,9 @@ impl Build {
29152940
autodetect_android_compiler(target, &host, gnu, clang)
29162941
} else if target.contains("cloudabi") {
29172942
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+
{
29192946
if self.cpp {
29202947
"clang++".to_string()
29212948
} else {
@@ -3949,6 +3976,17 @@ impl Build {
39493976
version
39503977
}
39513978

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+
39523990
fn wasi_sysroot(&self) -> Result<Arc<OsStr>, Error> {
39533991
if let Some(wasi_sysroot_path) = self.getenv("WASI_SYSROOT") {
39543992
Ok(wasi_sysroot_path)

0 commit comments

Comments
 (0)