Pass wrapper.h to bindgen in-memory to avoid rebuild loop#90
Open
jaredhoberock wants to merge 1 commit intomlir-rs:mainfrom
Open
Pass wrapper.h to bindgen in-memory to avoid rebuild loop#90jaredhoberock wants to merge 1 commit intomlir-rs:mainfrom
jaredhoberock wants to merge 1 commit intomlir-rs:mainfrom
Conversation
Previously the build script wrote `wrapper.h` to `$OUT_DIR` and passed
the path to bindgen via `.header(...)`. Bindgen's `CargoCallbacks` then
emitted `cargo:rerun-if-changed=<wrapper.h path>`, telling cargo to
track the file. Since the build script unconditionally rewrote
`wrapper.h` on every invocation (newer mtime than the script's
`output` file, which is finalized when cargo captures the script's
stdout), cargo always saw the file as newer than its recorded
fingerprint and marked the build script as stale. This forced a
rerun on every `cargo build` / `cargo test`, which in turn
invalidated `mlir-sys`'s lib target and every downstream crate.
Switch to `bindgen::Builder::header_contents("wrapper.h", &content)`
so the wrapper exists only in memory. Bindgen still needs a logical
header name for diagnostics; the string `wrapper.h` is passed but
nothing is written to disk, so there is no file for `CargoCallbacks`
to track and the rerun loop is gone.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #89.
Switch the build script from writing
$OUT_DIR/wrapper.hand callingbindgen::Builder::header(path)to callingbindgen::Builder::header_contents("wrapper.h", &content). The wrapper exists only in memory, so there's no file for bindgen'sCargoCallbacksto register viarerun-if-changed, and cargo no longer treats the build script as stale on every invocation.The walk over
{includedir}/mlir-c/is unchanged; the helper is renamed fromgenerate_wrapper -> PathBuftogenerate_wrapper_contents -> String.PathBufimport dropped.Verification
Two consecutive
cargo builds on a downstream crate:Full downstream test suite (289 tests) passes.
Assisted by Claude (Anthropic).