Skip to content

Commit

Permalink
Rollup merge of #129367 - madsmtm:fix-apple-aarch64-deployment-target…
Browse files Browse the repository at this point in the history
…s, r=jieyouxu

Fix default/minimum deployment target for Aarch64 simulator targets

The minimum that `rustc` encoded did not match [the version in Clang](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.8/llvm/lib/TargetParser/Triple.cpp#L1900-L1932), and that meant that that when linking, Clang ended up bumping the version. See #129432 for more motivation behind this change.

Specifically, this PR sets the correct deployment target of the following targets:
- `aarch64-apple-ios-sim` from 10.0 to 14.0
- `aarch64-apple-tvos-sim` from 10.0 to 14.0
- `aarch64-apple-watchos-sim` from 5.0 to 7.0
- `aarch64-apple-ios-macabi` from 13.1 to 14.0

I have chosen not to document the `-sim` changes in the platform support docs, as it is fundamentally uninteresting; the normal targets (e.g. `aarch64-apple-ios`) still have the same deployment target, and that's what developers should actually target.

r? compiler

CC `@BlackHoleFox`
  • Loading branch information
Zalathar authored Sep 12, 2024
2 parents 8e037cc + 97df8fb commit 65a5cd4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
10 changes: 8 additions & 2 deletions compiler/rustc_target/src/spec/base/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,18 @@ fn deployment_target(os: &str, arch: Arch, abi: TargetAbi) -> (u16, u8, u8) {
};

// On certain targets it makes sense to raise the minimum OS version.
//
// This matches what LLVM does, see:
// <https://github.com/llvm/llvm-project/blob/llvmorg-18.1.8/llvm/lib/TargetParser/Triple.cpp#L1900-L1932>
let min = match (os, arch, abi) {
// Use 11.0 on Aarch64 as that's the earliest version with M1 support.
("macos", Arch::Arm64 | Arch::Arm64e, _) => (11, 0, 0),
("ios", Arch::Arm64e, _) => (14, 0, 0),
("ios", Arch::Arm64 | Arch::Arm64e, TargetAbi::MacCatalyst) => (14, 0, 0),
("ios", Arch::Arm64 | Arch::Arm64e, TargetAbi::Simulator) => (14, 0, 0),
("ios", Arch::Arm64e, TargetAbi::Normal) => (14, 0, 0),
// Mac Catalyst defaults to 13.1 in Clang.
("ios", _, TargetAbi::MacCatalyst) => (13, 1, 0),
("tvos", Arch::Arm64 | Arch::Arm64e, TargetAbi::Simulator) => (14, 0, 0),
("watchos", Arch::Arm64 | Arch::Arm64e, TargetAbi::Simulator) => (7, 0, 0),
_ => os_min,
};

Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/platform-support/apple-ios-macabi.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ environment variable.

### OS version

The minimum supported version is iOS 13.1.
The minimum supported version is iOS 13.1 on x86 and 14.0 on Aarch64.

This can be raised per-binary by changing the deployment target. `rustc`
respects the common environment variables used by Xcode to do so, in this
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/platform-support/arm64e-apple-ios.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**Tier: 3**

ARM64e iOS (12.0+)
ARM64e iOS (14.0+)

## Target maintainers

Expand Down
28 changes: 16 additions & 12 deletions tests/run-make/apple-deployment-target/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ fn main() {
rustc().env(env_var, example_version).run();
minos("foo.o", example_version);

// FIXME(madsmtm): Doesn't work on Mac Catalyst and the simulator.
if !target().contains("macabi") && !target().contains("sim") {
rustc().env_remove(env_var).run();
minos("foo.o", default_version);
}
rustc().env_remove(env_var).run();
minos("foo.o", default_version);
});

// Test that version makes it to the linker when linking dylibs.
Expand Down Expand Up @@ -104,8 +101,18 @@ fn main() {
rustc
};

// FIXME(madsmtm): Doesn't work on watchOS for some reason?
if !target().contains("watchos") {
// FIXME(madsmtm): Xcode's version of Clang seems to require a minimum
// version of 9.0 on aarch64-apple-watchos for some reason? Which is
// odd, because the first Aarch64 watch was Apple Watch Series 4,
// which runs on as low as watchOS 5.0.
//
// You can see Clang's behaviour by running:
// ```
// echo "int main() { return 0; }" > main.c
// xcrun --sdk watchos clang --target=aarch64-apple-watchos main.c
// vtool -show a.out
// ```
if target() != "aarch64-apple-watchos" {
rustc().env(env_var, example_version).run();
minos("foo", example_version);

Expand Down Expand Up @@ -146,10 +153,7 @@ fn main() {
rustc().env(env_var, higher_example_version).run();
minos("foo.o", higher_example_version);

// FIXME(madsmtm): Doesn't work on Mac Catalyst and the simulator.
if !target().contains("macabi") && !target().contains("sim") {
rustc().env_remove(env_var).run();
minos("foo.o", default_version);
}
rustc().env_remove(env_var).run();
minos("foo.o", default_version);
});
}

0 comments on commit 65a5cd4

Please sign in to comment.