diff --git a/extensions/README.md b/extensions/README.md index 4e03bdd..b5af262 100644 --- a/extensions/README.md +++ b/extensions/README.md @@ -79,4 +79,4 @@ It tests A, broken B, changed C, an old call across reload, a retained service h It also tests the revert command, file operations, and exec environment options. The world git and helper components use the executor's shared `CARGO_TARGET_DIR`. The API and hook fixtures use that directory too. -The Nix shell overrides `CARGO_HOME`. Unset that variable before Cargo commands to preserve the configured kache wrapper. +The Nix shell preserves the user's Cargo configuration and its kache wrapper. diff --git a/host/tests/extensions.rs b/host/tests/extensions.rs index 066a550..d6ae8eb 100644 --- a/host/tests/extensions.rs +++ b/host/tests/extensions.rs @@ -28,9 +28,7 @@ impl Exec for Author { #[tokio::test(flavor = "current_thread")] async fn commits_and_restart() -> anyhow::Result<()> { let userland = Path::new(env!("CARGO_MANIFEST_DIR")).join("../userland"); - let target = std::env::var_os("CARGO_TARGET_DIR") - .map(std::path::PathBuf::from) - .expect("CARGO_TARGET_DIR must name the executor's shared target directory"); + let target = Path::new(env!("CARGO_TARGET_TMPDIR")).parent().unwrap(); if !userland.join("cwd-init/init.o").is_file() { assert!( std::process::Command::new("nu") @@ -53,7 +51,7 @@ async fn commits_and_restart() -> anyhow::Result<()> { ]) .arg(userland.join("Cargo.toml")) .args(["--target", "wasm32-wasip2", "--target-dir"]) - .arg(&target) + .arg(target) .args(["-j", "2", "--locked"]) .current_dir(&userland) .status()? diff --git a/host/tests/hook_git.rs b/host/tests/hook_git.rs index 1a1365c..f987076 100644 --- a/host/tests/hook_git.rs +++ b/host/tests/hook_git.rs @@ -24,10 +24,7 @@ fn git(cwd: &Path, args: &[&str]) { async fn several_mb_git_push() { static BUILT: OnceLock = OnceLock::new(); let component = BUILT.get_or_init(|| { - let target = std::path::PathBuf::from( - std::env::var_os("CARGO_TARGET_DIR") - .expect("CARGO_TARGET_DIR must name the executor's shared target directory"), - ); + let target = Path::new(env!("CARGO_TARGET_TMPDIR")).parent().unwrap(); let userland = Path::new(env!("CARGO_MANIFEST_DIR")).join("../userland"); if !userland.join("cwd-init/init.o").is_file() { assert!( @@ -46,7 +43,7 @@ async fn several_mb_git_push() { .arg(manifest) .current_dir(&userland) .args(["--target", "wasm32-wasip2", "--target-dir"]) - .arg(&target) + .arg(target) .args(["-j", "2", "--locked"]) .status() .unwrap() diff --git a/host/tests/hook_guest.rs b/host/tests/hook_guest.rs index c56615f..3644367 100644 --- a/host/tests/hook_guest.rs +++ b/host/tests/hook_guest.rs @@ -12,7 +12,7 @@ fn write(path: PathBuf, text: &str) -> std::io::Result<()> { pub fn component() -> &'static Path { static PATH: OnceLock = OnceLock::new(); PATH.get_or_init(|| { - let target = PathBuf::from(std::env::var_os("CARGO_TARGET_DIR").expect("CARGO_TARGET_DIR must name the executor's shared target directory")); + let target = Path::new(env!("CARGO_TARGET_TMPDIR")).parent().unwrap(); let directory = Path::new(env!("CARGO_TARGET_TMPDIR")).join("hook-guest"); std::fs::create_dir_all(directory.join("src")).unwrap(); std::fs::create_dir_all(directory.join("wit/deps")).unwrap(); @@ -68,7 +68,7 @@ async fn main() -> anyhow::Result<()> { Ok(()) } "#).unwrap(); - assert!(std::process::Command::new("cargo").args(["build", "--manifest-path"]).arg(directory.join("Cargo.toml")).args(["--target", "wasm32-wasip2", "--release", "-j", "2"]).env("CARGO_TARGET_DIR", &target).status().unwrap().success(), "test guest build failed"); + assert!(std::process::Command::new("cargo").args(["build", "--manifest-path"]).arg(directory.join("Cargo.toml")).args(["--target", "wasm32-wasip2", "--release", "-j", "2"]).env("CARGO_TARGET_DIR", target).status().unwrap().success(), "test guest build failed"); target.join("wasm32-wasip2/release/hook-guest.wasm") }) }