Skip to content

Auto-track all bridge files#1462

Merged
dtolnay merged 1 commit intodtolnay:masterfrom
nyurik:track
Aug 5, 2025
Merged

Auto-track all bridge files#1462
dtolnay merged 1 commit intodtolnay:masterfrom
nyurik:track

Conversation

@nyurik
Copy link
Copy Markdown
Contributor

@nyurik nyurik commented Mar 6, 2025

Adds cargo:rerun-if-changed=<path> for all files used by the bridge.

Note that when I went through all the rerun-if-changed cases, some of them did not include the .rs file - which may mean that even this repo is missing the needed tracking and this would fix those.

Fixes #1461

Adds `cargo:rerun-if-changed=<path>` for all files used by the bridge.
Copy link
Copy Markdown
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous consideration of this in #26. I think it's better not to do this.

@dtolnay dtolnay closed this Mar 6, 2025
@nyurik
Copy link
Copy Markdown
Contributor Author

nyurik commented Mar 6, 2025

@dtolnay thx, i didn't see that PR. Do you think cxx could adapt the approach to other similar crates like static_files change_detection? It has a builder that allows to enable change detction print statements, and afterwards it finalizes it.

The issue with cxx is that it produces a cc::Build directly - making it somewhat inconvinient when additional configurations are needed. Perhaps we can introduce a new Bridge or CxxBuild struct?

    cxx_build::new()  // empty CxxBuild
        .add_bridge("src/map_renderer.rs") // add a single bridge file
        .change_detection() // enable "rerun-if-changed" printing
        .to_bridge()  // consume CxxBuild and create cc::Build -- prints rerun-if-changed here
        .includes(&include_dirs)  // Just as before - operations on the cc::Build
        .file("src/renderer/bridge.cpp")
        .flag_if_supported("-std=c++20")
        .compile("maplibre_rust_map_renderer_bindings");

@dtolnay
Copy link
Copy Markdown
Owner

dtolnay commented Mar 6, 2025

I don't think a separate builder type is justified. But it could be done using CFG.

@nyurik
Copy link
Copy Markdown
Contributor Author

nyurik commented Mar 6, 2025

Thx, I created #1463 to do that

@dtolnay dtolnay reopened this Aug 5, 2025
@dtolnay
Copy link
Copy Markdown
Owner

dtolnay commented Aug 5, 2025

Beginning in cc version 1.0.74 the cc crate has started printing some rerun-if-env-changed lines by default, so the downsides in #26 are already being paid. (From the description of the relevant cc PR it sounds like the downside was not understood when making that behavior change.) In that case this PR is fine after all and will not make things worse.

@dtolnay dtolnay merged commit b3e5745 into dtolnay:master Aug 5, 2025
45 checks passed
@nyurik nyurik deleted the track branch August 6, 2025 07:52
@phil-opp
Copy link
Copy Markdown
Contributor

Can we add a way to opt-out of this? One of the files I give to bridges is autogenerated by my build script immediately before. So this file always has a timestamp that is newer than the "last build" timestamp kept by cargo. As a consequence, cargo will always consider that file changed and rerun the build script on every build.

The only hacky workaround that I'm aware of is using File::set_modified to fake a modification time older than the build script's start timestamp.

@dtolnay
Copy link
Copy Markdown
Owner

dtolnay commented Nov 11, 2025

I prefer not to make an opt-out but I am open to other suggestions. For example do not do this for files located in OUT_DIR or elsewhere in the target dir, only in the current crate's manifest dir.

@phil-opp
Copy link
Copy Markdown
Contributor

phil-opp commented Nov 11, 2025

For example do not do this for files located in OUT_DIR

Even better, thanks for the quick reply! I opened a PR at #1668.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically generate cargo:rerun-if-changed

3 participants