Skip to content

Build script's on-disk wrapper.h forces cargo rebuild #89

@jaredhoberock

Description

@jaredhoberock

Since #85 (auto-generating wrapper.h from installed MLIR headers), every cargo build / cargo test recompiles mlir-sys and everything downstream of it, even with no source changes.

Cause: build.rs writes $OUT_DIR/wrapper.h via fs::write and passes its path to bindgen via .header(...). Bindgen's CargoCallbacks then registers the wrapper file as a rerun-if-changed input. The wrapper is rewritten on every script invocation, and its mtime is set later than the build script's output file (because cargo finalizes output from captured stdout before the script reaches the fs::write call).

Cargo's fingerprinter compares each rerun-if-changed input's mtime against the build script's output file from the previous run; if the input is newer, the script is considered stale and rerun. Because wrapper.h is rewritten after the script's stdout has already been captured into output, it's always newer, and cargo always reruns the script — which regenerates wrapper.h with a yet-newer mtime, so the loop persists indefinitely.

Fix coming in a PR.

Assisted by Claude (Anthropic).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions