cmake-rs icon indicating copy to clipboard operation
cmake-rs copied to clipboard

Build rerunning because of file regenerated at build time

Open Enduriel opened this issue 4 months ago • 0 comments

This was originally reported as a cargo issue where I was directed that this is likely a cmake issue, so making a new issue here. The original problem description is below

Problem

I'm building a dependency using a build.rs file, specifically libheif (and libde265 which it depends on). I want to configure cargo so it only reruns when necessary, this is my build.rs. Currently it reruns on every single build/check. This seems to be because bindgen using libheif generates a file (heif_version.h) at compile time, and it's generated after the reference cargo uses to compare when files should be updated.

Repo showcasing this issue here

Steps

  1. git clone https://github.com/Enduriel/cargo-rerun-libheif-example
  2. cargo check Notice it builds from scratch
  3. cargo check again, notice it reruns the build for the crate

Possible Solution(s)

There seems to be a timing mismatch here to me, I'm not sure whether it's the fault of bindgen or cargo. The reference cargo is using for when to mark something as stale seems to be wrong. I don't know enough about the internals of cargo to know the best solution, but maybe set the modified time of the file being updated to the most recently modified time of any file in the output contents after all the builds have run.

Notes

My output from running CARGO_LOG=cargo::core::compiler::fingerprint=trace cargo build which helped me diagnose the issue

Version

cargo 1.88.0 (873a06493 2025-05-10)
release: 1.88.0
commit-hash: 873a0649350c486caf67be772828a4f36bb4734c
commit-date: 2025-05-10
host: aarch64-apple-darwin
libgit2: 1.9.0 (sys:0.20.0 vendored)
libcurl: 8.7.1 (sys:0.4.80+curl-8.12.1 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 3.4.1 11 Feb 2025
os: Mac OS 15.5.0 [64-bit]

Enduriel avatar Aug 07 '25 08:08 Enduriel