Skip to content

cargo doesn't rerun build scripts when RUSTC is changed #10367

Closed as duplicate

Description

@jyn514

Problem

The RUSTC env variable is provided to build scripts by cargo. According to the docs: https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-env-changed

It is not necessary to use this for environment variables like TARGET that Cargo sets.

Cargo should rerun build scripts when rustc changes. I suspect this code needs to account for the path of the compiler, not just the version:

hash_rustc_version(bcx, &mut hasher);

See rust-lang/rust#93723 for a reproduction, but it's not anywhere close to minimal.

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.59.0-beta.5 (5ad495c68 2022-01-25)

Activity

  1. ehuss commented on Feb 27, 2022

    @ehuss
    Contributor

    This is currently intentional behavior. There are situations where RUSTC changes, but we don't want that to trigger a full recompile. If one rustc emits the same version output as another, then cargo assumes they essentially behave the same, even if they are from different paths. I'm not sure this is something that can be changed without causing unwanted recompiles in some situations.

  2. jyn514 commented on Mar 1, 2022

    @jyn514
    MemberAuthor

    Ok. Is it possible to document this somewhere? Maybe around https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-env-changed ?

  3. jyn514 commented on Mar 1, 2022

    @jyn514
    MemberAuthor

    If one rustc emits the same version output as another, then cargo assumes they essentially behave the same, even if they are from different paths.

    To be clear, the original bug in x.py was that it cached the path from the build script and would try to run that compiler on all subsequent builds, which broke because the target directory was deleted.

  4. added
    S-triageStatus: This issue is waiting on initial triage.
    on Nov 20, 2024
  5. epage commented on Nov 7, 2025

    @epage
    Contributor

    I wonder how related #9983 is

  6. added
    S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
    and removed
    S-triageStatus: This issue is waiting on initial triage.
    on Nov 7, 2025
  7. Alexhuszagh commented on Nov 10, 2025

    @Alexhuszagh

    They look like duplicates. I'm not sure if current behavior with x.py still would affect this. I wonder if we could set an environment variable, either to opt-in to full recompiles or opt-out of them depending on the desired default behavior when RUSTC changes, since it sounds like both are valid use-cases.

  8. epage commented on Nov 10, 2025

    @epage
    Contributor

    Going to go ahead and close. If there is a reason for us to re-evaluate, let us know!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-rebuild-detectionArea: rebuild detection and fingerprintingC-bugCategory: bugS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions