Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebuild and rerun build scripts when RUSTC_WRAPPER has changed #10973

Closed
wants to merge 3 commits into from

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Aug 11, 2022

What does this PR try to resolve?

The current behavior of Cargo, which I think is a bug, is that if you run cargo build followed by RUSTC_WRAPPER=… cargo build, Cargo will rebuild your crate using the given rustc wrapper, but will not rebuild or rerun any build scripts. The same is true of those commands in the opposite order: Cargo will rebuild your crate with no wrapper, but not build scripts.

This PR fixes this to rebuild build scripts too (and rerun them) when RUSTC_WRAPPER has changed.

In general, whatever rationale justifies rebuilding an already successfully built crate on a RUSTC_WRAPPER change (maybe the wrapper is in charge of munging rustc flags somehow?) should apply just as much to justify rebuilding build scripts.

The immediate motivation for the PR is that we had a problematic experience in the anyhow crate where compiling via rust-analyzer using rust-analyzer's RUSTC_WRAPPER would break all subsequent command-line cargo invocations, due to the RUSTC_WRAPPER-using build of the build script being cached and not rerun.

How should we test and review this PR?

I tested by cargo test --test testsuite -- rerun_build_script_if_add_rustc_wrapper.

Currently fails on the "Reruns build script because RUSTC_WRAPPER
changes the fingerprint" step.

    ---- freshness::rerun_build_script_if_add_rustc_wrapper stdout ----
    running `/git/cargo/target/debug/cargo check`
    running `/git/cargo/target/debug/cargo check`
    running `/git/cargo/target/debug/cargo build`
    running `/git/cargo/target/debug/cargo check`
    thread 'freshness::rerun_build_script_if_add_rustc_wrapper' panicked at 'assertion failed: file_created_by_build_script.exists()', tests/testsuite/freshness.rs:888:5
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@rust-highfive
Copy link

r? @ehuss

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 11, 2022
@dtolnay
Copy link
Member Author

dtolnay commented Aug 16, 2022

This is probably misguided unless we also add some detection for whether the output of the build script is any different from the previous run, and avoid rebuilding everything downstream in that situation. :( dtolnay/anyhow#261

@dtolnay dtolnay marked this pull request as draft August 16, 2022 21:31
@dtolnay dtolnay closed this Aug 24, 2022
@dtolnay dtolnay deleted the rerun branch November 20, 2023 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants