From 401e0926d70fcd753180102f8fdb43ae9649dfe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 6 Nov 2026 19:00:23 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Tests=20find=20hw-child=20when?= =?UTF-8?q?=20cargo's=20build-dir=20puts=20test=20binaries=20outside=20tar?= =?UTF-8?q?get/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cargo/config.toml | 5 +++++ crates/engine/src/hwproc.rs | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..e15481b --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,5 @@ +# The workspace's own target directory, for the processes cargo and nextest start (tests, +# `cargo run`). With a `build-dir` set elsewhere, a test binary does not run from under +# `target/`, so the hardware seat looks for `hw-child` in the target directory named here. +[env] +EDITH_TARGET_DIR = { value = "target", relative = true } diff --git a/crates/engine/src/hwproc.rs b/crates/engine/src/hwproc.rs index 46774cd..f35823d 100644 --- a/crates/engine/src/hwproc.rs +++ b/crates/engine/src/hwproc.rs @@ -394,7 +394,11 @@ pub fn recv_reply(sock: &mut UnixStream, body: &mut Vec) -> std::io::Result< /// Where the helper lives: told outright, or beside the running executable -- /// which is `target//` for the editor and one directory up from -/// `deps/` for a test binary. +/// `deps/` for a test binary -- or, when cargo started the process, in the +/// workspace's target directory under this build's profile. That last place is +/// what a test finds the child in when cargo's `build-dir` puts the test +/// binaries outside `target/` (the workspace's `.cargo/config.toml` names it as +/// `EDITH_TARGET_DIR`). fn locate_child() -> Option { if let Some(pinned) = crate::envcfg::var_os("VE_HW_CHILD_BIN") { let pinned = PathBuf::from(pinned); @@ -402,8 +406,11 @@ fn locate_child() -> Option { } let exe = std::env::current_exe().ok()?; let dir = exe.parent()?.to_path_buf(); - [dir.join(BIN), dir.parent()?.join(BIN)] + let profile = if cfg!(debug_assertions) { "debug" } else { "release" }; + let target = crate::envcfg::var_os("EDITH_TARGET_DIR").map(|t| PathBuf::from(t).join(profile).join(BIN)); + [Some(dir.join(BIN)), dir.parent().map(|up| up.join(BIN)), target] .into_iter() + .flatten() .find(|candidate| candidate.is_file()) }