From e7d3ec568bbf0e5a4fc252fa3fc6788f843d8605 Mon Sep 17 00:00:00 2001 From: moudyellaz Date: Wed, 12 Aug 2026 15:25:01 +0200 Subject: [PATCH] fix(build): resolve the artifacts dir at build-script runtime --- build_utils/src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/build_utils/src/lib.rs b/build_utils/src/lib.rs index 1323d830e..6753e845d 100644 --- a/build_utils/src/lib.rs +++ b/build_utils/src/lib.rs @@ -17,11 +17,19 @@ use anyhow::{Context as _, Result, bail}; /// } /// ``` pub fn include_artifacts(artifacts_sub_dir: &str) -> Result<()> { - let manifest_dir = PathBuf::from(std::env!("CARGO_MANIFEST_DIR")); + // Resolved at build-script runtime from the invoking crate, not at compile + // time: `env!` would bake in the path of whichever checkout compiled this + // rlib first, and with a shared cargo target dir every other worktree then + // embeds that checkout's artifacts instead of its own. + let invoking_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?); + let workspace_root = invoking_manifest_dir + .ancestors() + .find(|dir| dir.join("artifacts").is_dir()) + .context("no artifacts/ directory above the invoking crate")?; let out_dir = PathBuf::from(env::var("OUT_DIR")?); let mod_dir = out_dir.join(artifacts_sub_dir); let mod_file = mod_dir.join("mod.rs"); - let artifacts_dir = manifest_dir.join(format!("../artifacts/{artifacts_sub_dir}/")); + let artifacts_dir = workspace_root.join(format!("artifacts/{artifacts_sub_dir}/")); println!("cargo:rerun-if-changed={}", artifacts_dir.display());