Skip to content

Commit dbe15e3

Browse files
committed
Remove environment variable modification in test_default_compiler_wasi
1 parent 8540188 commit dbe15e3

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/bootstrap/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ pub struct Build {
194194
cxx: HashMap<TargetSelection, cc::Tool>,
195195
ar: HashMap<TargetSelection, PathBuf>,
196196
ranlib: HashMap<TargetSelection, PathBuf>,
197+
wasi_sdk_path: Option<PathBuf>,
198+
197199
// Miscellaneous
198200
// allow bidirectional lookups: both name -> path and path -> name
199201
crates: HashMap<String, Crate>,
@@ -468,6 +470,7 @@ impl Build {
468470
cxx: HashMap::new(),
469471
ar: HashMap::new(),
470472
ranlib: HashMap::new(),
473+
wasi_sdk_path: env::var_os("WASI_SDK_PATH").map(PathBuf::from),
471474
crates: HashMap::new(),
472475
crate_paths: HashMap::new(),
473476
is_sudo,

src/bootstrap/src/utils/cc_detect.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,10 @@ fn default_compiler(
221221
}
222222

223223
t if t.contains("-wasi") => {
224-
let root = PathBuf::from(std::env::var_os("WASI_SDK_PATH")?);
224+
let root = build
225+
.wasi_sdk_path
226+
.as_ref()
227+
.expect("WASI_SDK_PATH mut be configured for a -wasi target");
225228
let compiler = match compiler {
226229
Language::C => format!("{t}-clang"),
227230
Language::CPlusPlus => format!("{t}-clang++"),

src/bootstrap/src/utils/cc_detect/tests.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ fn test_new_cc_build() {
7777

7878
#[test]
7979
fn test_default_compiler_wasi() {
80-
let build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
80+
let mut build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
8181
let target = TargetSelection::from_user("wasm32-wasi");
8282
let wasi_sdk = PathBuf::from("/wasi-sdk");
83-
// SAFETY: bootstrap tests run on a single thread
84-
unsafe { env::set_var("WASI_SDK_PATH", &wasi_sdk) };
83+
build.wasi_sdk_path = Some(wasi_sdk.clone());
84+
8585
let mut cfg = cc::Build::new();
8686
if let Some(result) = default_compiler(&mut cfg, Language::C, target.clone(), &build) {
8787
let expected = {
@@ -94,10 +94,6 @@ fn test_default_compiler_wasi() {
9494
"default_compiler should return a compiler path for wasi target when WASI_SDK_PATH is set"
9595
);
9696
}
97-
// SAFETY: bootstrap tests run on a single thread
98-
unsafe {
99-
env::remove_var("WASI_SDK_PATH");
100-
}
10197
}
10298

10399
#[test]

0 commit comments

Comments
 (0)