Skip to content

Commit fe9ccd1

Browse files
NobodyXuKuuuube
andauthored
Fix compilation for wasm: env WASI_SYSROOT should be optional (#1114)
* Fix compilation for wasm: env WASI_SYSROOT should be optional On ubuntu-latest github action runner, it used to work without the environment variable. Fixed #1109 #1113 * Add wasm32-unknown targets (#1115) --------- Co-authored-by: Kuuuube <61125188+Kuuuube@users.noreply.github.com>
1 parent bffb5c0 commit fe9ccd1

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

Diff for: src/lib.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -1339,12 +1339,13 @@ impl Build {
13391339
}
13401340
// Link c++ lib from WASI sysroot
13411341
if Build::is_wasi_target(target.as_ref()) {
1342-
let wasi_sysroot = self.wasi_sysroot()?;
1343-
self.cargo_output.print_metadata(&format_args!(
1344-
"cargo:rustc-flags=-L {}/lib/{} -lstatic=c++ -lstatic=c++abi",
1345-
Path::new(&wasi_sysroot).display(),
1346-
target
1347-
));
1342+
if let Ok(wasi_sysroot) = self.wasi_sysroot() {
1343+
self.cargo_output.print_metadata(&format_args!(
1344+
"cargo:rustc-flags=-L {}/lib/{} -lstatic=c++ -lstatic=c++abi",
1345+
Path::new(&wasi_sysroot).display(),
1346+
target
1347+
));
1348+
}
13481349
}
13491350
}
13501351

@@ -1950,10 +1951,11 @@ impl Build {
19501951
// https://github.com/WebAssembly/exception-handling
19511952
cmd.push_cc_arg("-fno-exceptions".into());
19521953
// Link clang sysroot
1953-
let wasi_sysroot = self.wasi_sysroot()?;
1954-
cmd.push_cc_arg(
1955-
format!("--sysroot={}", Path::new(&wasi_sysroot).display()).into(),
1956-
);
1954+
if let Ok(wasi_sysroot) = self.wasi_sysroot() {
1955+
cmd.push_cc_arg(
1956+
format!("--sysroot={}", Path::new(&wasi_sysroot).display()).into(),
1957+
);
1958+
}
19571959
}
19581960
}
19591961
}
@@ -3940,12 +3942,14 @@ impl Build {
39403942
}
39413943
}
39423944
fn is_wasi_target(target: &str) -> bool {
3943-
const TARGETS: [&'static str; 5] = [
3945+
const TARGETS: [&'static str; 7] = [
39443946
"wasm32-wasi",
39453947
"wasm32-wasip1",
39463948
"wasm32-wasip1-threads",
39473949
"wasm32-wasip2",
39483950
"wasm32-wasi-threads",
3951+
"wasm32-unknown-wasi",
3952+
"wasm32-unknown-unknown",
39493953
];
39503954
return TARGETS.contains(&target);
39513955
}

0 commit comments

Comments
 (0)