diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 5303e9a91b6f..215586b32f09 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -194,6 +194,8 @@ pub struct Build { cxx: HashMap, ar: HashMap, ranlib: HashMap, + wasi_sdk_path: Option, + // Miscellaneous // allow bidirectional lookups: both name -> path and path -> name crates: HashMap, @@ -468,6 +470,7 @@ impl Build { cxx: HashMap::new(), ar: HashMap::new(), ranlib: HashMap::new(), + wasi_sdk_path: env::var_os("WASI_SDK_PATH").map(PathBuf::from), crates: HashMap::new(), crate_paths: HashMap::new(), is_sudo, diff --git a/src/bootstrap/src/utils/cc_detect.rs b/src/bootstrap/src/utils/cc_detect.rs index 2af30c16f8fd..dcafeb80f90c 100644 --- a/src/bootstrap/src/utils/cc_detect.rs +++ b/src/bootstrap/src/utils/cc_detect.rs @@ -221,7 +221,10 @@ fn default_compiler( } t if t.contains("-wasi") => { - let root = PathBuf::from(std::env::var_os("WASI_SDK_PATH")?); + let root = build + .wasi_sdk_path + .as_ref() + .expect("WASI_SDK_PATH mut be configured for a -wasi target"); let compiler = match compiler { Language::C => format!("{t}-clang"), Language::CPlusPlus => format!("{t}-clang++"), diff --git a/src/bootstrap/src/utils/cc_detect/tests.rs b/src/bootstrap/src/utils/cc_detect/tests.rs index 9ddf91fcc858..bed03c18aaad 100644 --- a/src/bootstrap/src/utils/cc_detect/tests.rs +++ b/src/bootstrap/src/utils/cc_detect/tests.rs @@ -77,11 +77,11 @@ fn test_new_cc_build() { #[test] fn test_default_compiler_wasi() { - let build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) }); + let mut build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) }); let target = TargetSelection::from_user("wasm32-wasi"); let wasi_sdk = PathBuf::from("/wasi-sdk"); - // SAFETY: bootstrap tests run on a single thread - unsafe { env::set_var("WASI_SDK_PATH", &wasi_sdk) }; + build.wasi_sdk_path = Some(wasi_sdk.clone()); + let mut cfg = cc::Build::new(); if let Some(result) = default_compiler(&mut cfg, Language::C, target.clone(), &build) { let expected = { @@ -94,10 +94,6 @@ fn test_default_compiler_wasi() { "default_compiler should return a compiler path for wasi target when WASI_SDK_PATH is set" ); } - // SAFETY: bootstrap tests run on a single thread - unsafe { - env::remove_var("WASI_SDK_PATH"); - } } #[test]