Skip to content

Rebuild if deployment target changes #118204

@madsmtm

Description

@madsmtm
Contributor

rustc reads the MACOSX_DEPLOYMENT_TARGET environment variable (and similar other *_DEPLOYMENT_TARGET variables), and uses that value to determine (probably amongst other things) certain options for LLVM and the linker.

However, it seems like this environment variable is not tracked as an external dependency, meaning that changing it does not cause rustc/cargo to rebuild the target, as is otherwise expected when changing environment variables that modify compilation.

E.g. running the following code:

cargo clean
MACOSX_DEPLOYMENT_TARGET=12.0 cargo build
MACOSX_DEPLOYMENT_TARGET=13.0 cargo build

I expected to see this happen: The project was built twice.

Instead, this happened: The project was built once, and then the cache was used the second time.

Meta

rustc --version --verbose:

rustc 1.76.0-nightly (2f8d81f9d 2023-11-21)
binary: rustc
commit-hash: 2f8d81f9dbac6b8df982199f69da04a4c8357227
commit-date: 2023-11-21
host: aarch64-apple-darwin
release: 1.76.0-nightly
LLVM version: 17.0.5

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Nov 23, 2023
madsmtm

madsmtm commented on Nov 23, 2023

@madsmtm
ContributorAuthor

I know that a crate can emit cargo:rerun-if-env-changed=MACOSX_DEPLOYMENT_TARGET in their build.rs to opt in to this behaviour, but I'm not sure that's enough if there are other cached crates in the dependency graph that may have been built with a different deployment target?

added
O-macosOperating system: macOS
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Dec 4, 2023
Noratrieb

Noratrieb commented on Dec 4, 2023

@Noratrieb
Member

This also affects other apple targets with their *_DEPLOYMENT_TARGETs. Looks like the relevant code should somehow add the env var to sess.parse_sess.env_depinfo. I'm not sure what the nicest way to ensure that would be.
cc @BlackHoleFox

added
O-iosOperating system: iOS
O-tvosOperating system: tvOS (including simulator)
on Dec 4, 2023
madsmtm

madsmtm commented on May 3, 2024

@madsmtm
ContributorAuthor

I'll add that this also affects the environment variable SDKROOT

16 remaining items

Loading
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

    C-bugCategory: This is a bug.O-iosOperating system: iOSO-macosOperating system: macOSO-tvosOperating system: tvOS (including simulator)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @madsmtm@rustbot@Noratrieb

      Issue actions

        Rebuild if deployment target changes · Issue #118204 · rust-lang/rust