From 31dd962fc4ccd9f07397ed4f21bc954909247f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Walle?= Date: Mon, 18 May 2026 09:22:11 +0200 Subject: [PATCH] halide-cache: hash the builder invocation Some flags can change the builder output even though the builder inputs and dependencies haven't changed. Make the builder invocation part of the hash generation but make paths relative to the base dir if possible. Several of the strings in the builder invocations aren't paths at all, but they are tolerated since stripping the base_dir from them won't succeed like for relative paths. --- halide-cache/src/main.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/halide-cache/src/main.rs b/halide-cache/src/main.rs index ce4211a..085055a 100644 --- a/halide-cache/src/main.rs +++ b/halide-cache/src/main.rs @@ -25,6 +25,7 @@ struct Dependencies<'a> { path: &'a Path, dependencies: &'a [PathBuf], env: &'a [String], + cmdline: &'a [&'a str], } impl<'a> Dependencies<'a> { @@ -48,6 +49,12 @@ impl<'a> Dependencies<'a> { } hasher.update(&[0u8]); + for e in self.cmdline { + hasher.update(e.as_bytes()); + hasher.update(&[0u8]); + } + hasher.update(&[0u8]); + let mut buf = [0u8; _]; hasher.finalize_xof().fill(&mut buf); Ok(buf.into()) @@ -82,16 +89,30 @@ fn main() -> anyhow::Result<()> { .strip_prefix(&base_dir) .unwrap_or(&args.generated_header); + let cmdline = args + .builder + .iter() + .map(|c| { + Path::new(c) + .strip_prefix(&base_dir) + .ok() + .and_then(|p| p.to_str()) + .unwrap_or(c) + }) + .collect::>(); + let object_dependencies = Dependencies { path: generated_object, dependencies: &args.dependencies, env: &zivid_env, + cmdline: &cmdline, }; let header_dependencies = Dependencies { path: generated_header, dependencies: &args.dependencies, env: &zivid_env, + cmdline: &cmdline, }; let header_address = header_dependencies.make_address()?;