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()) }