fix(build): resolve the artifacts dir at build-script runtime

This commit is contained in:
moudyellaz
2026-08-12 15:25:01 +02:00
parent f846e7ac73
commit e7d3ec568b
+10 -2
View File
@@ -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());