Remove environment variable modification in test_default_compiler_wasi

This commit is contained in:
Jakub Beránek 2025-06-12 15:27:48 +02:00
parent 85401882d2
commit dbe15e3e94
No known key found for this signature in database
GPG key ID: 909CD0D26483516B
3 changed files with 10 additions and 8 deletions

View file

@ -194,6 +194,8 @@ pub struct Build {
cxx: HashMap<TargetSelection, cc::Tool>,
ar: HashMap<TargetSelection, PathBuf>,
ranlib: HashMap<TargetSelection, PathBuf>,
wasi_sdk_path: Option<PathBuf>,
// Miscellaneous
// allow bidirectional lookups: both name -> path and path -> name
crates: HashMap<String, Crate>,
@ -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,

View file

@ -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++"),

View file

@ -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]