Skip to content

Conversation

fmease
Copy link
Member

@fmease fmease commented Sep 5, 2025

Successful merges:

Failed merges:

r? @ghost
@rustbot modify labels: rollup

Create a similar rollup

joshtriplett and others added 23 commits August 21, 2025 18:34
this uses some # directives to make sure the code works on x86_64, and does not produce errors on other platforms
`(float_ty::MAX / 2) - (float_ty::MIN_POSITIVE * 2)` equals
`(float_ty::MAX / 2) + (float_ty::MIN_POSITIVE * 2)` equals
`(float_ty::MAX / 2)`. So these branches are pointless
Allows users to link to Objective-C code using `@available(...)`.
…tgross35

Add `__isPlatformVersionAtLeast` and `__isOSVersionAtLeast` symbols

## Motivation

When Objective-C code uses ```@available(...)`,`` Clang inserts a call to [`__isPlatformVersionAtLeast`](https://github.com/llvm/llvm-project/blob/llvmorg-20.1.0/compiler-rt/lib/builtins/os_version_check.c#L276) (`__isOSVersionAtLeast` in older Clang versions). These symbols not being available sometimes ends up causing linker errors. See the new test `tests/run-make/apple-c-available-links` for a minimal reproducer.

The workaround is to link `libclang_rt.osx.a`, see e.g. alexcrichton/curl-rust#279. But that's very difficult for users to figure out (and the backreferences to that issue indicates that people are still running into this in their own projects every so often).

For another recent example, this is preventing `rustc` from using LLVM assertions on macOS, see rust-lang#62592 (comment) and rust-lang#134275 (comment).

It is also a blocker for [setting the correct minimum OS version in `cc-rs`](rust-lang#136113), since fixing this in `cc-rs` might end up introducing linker errors in places where we weren't before (by default, if using e.g. ```@available(macos`` 10.15, *)`, the symbol usually happens to be left out, since `clang` defaults to compiling for the host macOS version, and thus things _seem_ to work - but the availability check actually compiles down to nothing, which is a huge correctness footgun for running on older OSes).

(My super secret evil agenda is also to expose some variant of ```@available``` in Rust's `std` after rust-lang/rfcs#3750 progresses further, will probably file an ACP for this later. But I believe this PR has value regardless of those future plans, since we'd be making C/Objective-C/Swift interop easier).

## Solution

Implement `__isPlatformVersionAtLeast` and `__isOSVersionAtLeast` as part of the "public ABI" that `std` exposes.

**This is insta-stable**, in the same sense that additions to `compiler-builtins` are insta-stable, though the availability of these symbols can probably be considered a "quality of implementation" detail rather than a stable promise.

I originally proposed to implement this in `compiler-builtins`, see rust-lang/compiler-builtins#794, but we discussed moving it to `std` instead ([Zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Provide.20.60__isPlatformVersionAtLeast.60.20in.20.60std.60.3F/with/507880717)), which makes the implementation substantially simpler, and we avoid gnarly issues with requiring the user to link `libSystem.dylib` (since `std` unconditionally does that).

Note that this does not solve the linker errors for (pure) `#![no_std]` users, but that's _probably_ fine, if you are using ```@available``` to test the OS version on Apple platforms, you're likely also using `std` (and it is still possible to work around by linking `libclang_rt.*.a`).

A thing to note about the implementation, I've choosen to stray a bit from LLVM's upstream implementation, and not use `_availability_version_check` since [it has problems when compiling with an older SDK](llvm/llvm-project#64227). Instead, we use `sysctl kern.osproductversion` when available to still avoid the costly PList lookup in most cases, but still with a fall back to the PList lookup when that is not available (with the PList fallback being is similar to LLVM's implementation).

## Testing

Apple has a lot of different "modes" that they can run binaries in, which can be a bit difficult to find your bearings in, but I've tried to be as thorough as I could in testing them all.

Tested using roughly the equivalent of `./x test library/std -- platform_version` on the following configurations:
- macOS 14.7.3 on a Macbook Pro M2
    - `aarch64-apple-darwin`
    - `x86_64-apple-darwin` (under Rosetta)
    - `aarch64-apple-ios-macabi`
    - `x86_64-apple-ios-macabi` (under Rosetta)
    - `aarch64-apple-ios` (using Xcode's "Designed for iPad" setting)
    - `aarch64-apple-ios-sim` (in iOS Simulator, as iPhone with iOS 17.5)
    - `aarch64-apple-ios-sim` (in iOS Simulator, as iPad with iOS 18.2)
    - `aarch64-apple-tvos-sim` (in tvOS Simulator)
    - `aarch64-apple-watchos-sim` (in watchOS Simulator)
    - `aarch64-apple-ios-sim` (in visionOS simulator, using Xcode's "Designed for iPad" setting)
    - `aarch64-apple-visionos-sim` (in visionOS Simulator)
- macOS 15.3.1 VM
    - `aarch64-apple-darwin`
    - `aarch64-apple-ios-macabi`
- macOS 10.12.6 on an Intel Macbook from 2013
    - `x86_64-apple-darwin`
    - `i686-apple-darwin`
    - `x86_64-apple-ios` (in iOS Simulator)
- iOS 9.3.6 on a 1st generation iPad Mini
    - `armv7-apple-ios` with an older compiler

Along with manually inspecting the output of `version_from_sysctl()` and `version_from_plist()`, and verifying that they actually match what's expected.

I believe the only real omissions here would be:
- `aarch64-apple-ios` on a newer iPhone that has `sysctl` available (iOS 11.4 or above).
- `aarch64-apple-ios` on a Vision Pro using Xcode's "Designed for iPad" setting.

But I don't have the hardware available to test those.

``@rustbot`` label O-apple A-linkage -T-compiler -A-meta -A-run-make

try-job: aarch64-apple
…-check-block, r=rcvalle

unstable book: in a sanitizer example, check the code

Use some `#` directives to make sure the code checks on x86_64, and does not produce errors on other platforms. This example still used an older version of `#[naked]`, and because the snippet was ignored that was missed before.

I'm not sure when this gets built on CI exactly, so it might be worthwhile to try and build it for a non-x86_64 architecture to make sure that works. I'm not sure how to verify locally that e.g. on aarch64 this code works without errors/warnings.

try-job: aarch64-apple
try-job: x86_64-msvc-2
…whitespace, r=joshtriplett

style-guide: Document absence of trailing whitespace

We didn't previously have a blanket prohibition on trailing whitespace. Adding
one, inspired by discussion in rust-lang#145617 .
…=Kobzol

tidy: --bless now makes escheck run with --fix

this mirrors how other extra-check tools work.

unsure if this also needs to be done for tsc and es-check.
…ochenkov

compiler: Apply target features to the entry function

Fixes rust-lang#146143
…point, r=tgross35

Simplify `{f16, f32, f64, f128}::midpoint()`

`(float_ty::MAX / 2) - (float_ty::MIN_POSITIVE * 2)` equals `(float_ty::MAX / 2) + (float_ty::MIN_POSITIVE * 2)` equals `(float_ty::MAX / 2)`. So these branches are pointless.

CC `@Urgau` who wrote the original implementation in rust-lang#92048; does this seem right?

`@rustbot` label A-floating-point
…oss35

change file-is-generated doc comment to inner

Alternatively this could perhaps be better as a normal comment...
rustc_infer: change top-level doc comment to inner
… r=lolbinarycat

Ensure that `--html-after-content` option is used to check `scrape_examples_ice` rustdoc GUI test

Follow-up of rust-lang#146091.

This test ensures that the spans are correctly handled when a "local source file" is not the first in the file list. To ensure it's actually what's tested, this test checks that the option is actually used by adding an element.

r? `@lolbinarycat`
…-Simulacrum

Bump stage0 rustfmt

Unblocks rust-lang#146071, cc `@npmccallum.`

Steps to reproduce:

1. Temporarily upgrade `src/tools/bump-stage0`'s `toml` dependency from 0.7 to 0.9 to fix build error (see Zulip topic)
2. Execute `./x run src/tools/bump-stage0`
3. Manually revert changes unrelated to nightly `rustfmt`+`rustc` (the latter needs to be bumped, too, for the driver ([via](rust-lang#146250 (comment))))

r? `@Mark-Simulacrum` as discussed in [#t-release > Bump stage0 rustfmt separately ("one-off")](https://rust-lang.zulipchat.com/#narrow/channel/241545-t-release/topic/Bump.20stage0.20rustfmt.20separately.20.28.22one-off.22.29/with/537916615)
@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-run-make Area: port run-make Makefiles to rmake.rs A-tidy Area: The tidy tool PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Sep 5, 2025
@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-release Relevant to the release subteam, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. T-style Relevant to the style team, which will review and decide on the PR/issue. rollup A PR which is a rollup labels Sep 5, 2025
@fmease
Copy link
Member Author

fmease commented Sep 5, 2025

@bors r+ rollup=never p=5

@bors
Copy link
Collaborator

bors commented Sep 5, 2025

📌 Commit 55a62d5 has been approved by fmease

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 5, 2025
@bors
Copy link
Collaborator

bors commented Sep 5, 2025

⌛ Testing commit 55a62d5 with merge 6c699a3...

@bors
Copy link
Collaborator

bors commented Sep 5, 2025

☀️ Test successful - checks-actions
Approved by: fmease
Pushing 6c699a3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 5, 2025
@bors bors merged commit 6c699a3 into rust-lang:master Sep 5, 2025
11 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Sep 5, 2025
Copy link
Contributor

github-actions bot commented Sep 6, 2025

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 99317ef (parent) -> 6c699a3 (this PR)

Test differences

Show 436 test diffs

Stage 1

  • [run-make] tests/run-make/apple-c-available-links: [missing] -> ignore (only executed when the target vendor is Apple (__builtin_available is (mostly) specific to Apple platforms.)) (J1)

Stage 2

  • [run-make] tests/run-make/apple-c-available-links: [missing] -> pass (J0)
  • sys::platform_version::darwin::tests::compare_against_sw_vers: [missing] -> pass (J0)
  • sys::platform_version::darwin::tests::empty_plist: [missing] -> pass (J0)
  • sys::platform_version::darwin::tests::invalid_plist: [missing] -> pass (J0)
  • sys::platform_version::darwin::tests::lookup_idempotent: [missing] -> pass (J0)
  • sys::platform_version::darwin::tests::parse_plist: [missing] -> pass (J0)
  • sys::platform_version::darwin::tests::parse_version: [missing] -> pass (J0)
  • sys::platform_version::darwin::tests::sysctl_same_as_in_plist: [missing] -> pass (J0)
  • sys::platform_version::darwin::tests::test_general_available: [missing] -> pass (J0)
  • sys::platform_version::darwin::tests::test_saturating: [missing] -> pass (J0)
  • [run-make] tests/run-make/apple-c-available-links: [missing] -> ignore (only executed when the target vendor is Apple (__builtin_available is (mostly) specific to Apple platforms.)) (J2)

Additionally, 424 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 6c699a37235700ab749e3f14147fe41d49c056e8 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-apple-various: 4461.9s -> 3413.4s (-23.5%)
  2. dist-x86_64-apple: 8690.3s -> 6649.0s (-23.5%)
  3. dist-aarch64-apple: 7008.8s -> 6059.5s (-13.5%)
  4. pr-check-1: 1360.6s -> 1531.5s (12.6%)
  5. dist-various-1: 4222.4s -> 3694.3s (-12.5%)
  6. dist-armhf-linux: 4940.0s -> 5529.0s (11.9%)
  7. aarch64-msvc-1: 7081.3s -> 6523.2s (-7.9%)
  8. x86_64-gnu-llvm-19-1: 3332.6s -> 3595.2s (7.9%)
  9. x86_64-gnu-llvm-19-3: 6969.0s -> 6467.5s (-7.2%)
  10. tidy: 184.4s -> 197.5s (7.1%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

📌 Perf builds for each rolled up PR:

PR# Message Perf Build Sha
#138944 Add __isPlatformVersionAtLeast and __isOSVersionAtLeast 597abfc3a3928025dcacfa498e7197103033f868 (link)
#139113 unstable book: in a sanitizer example, check the code 7211dc6570dfa942721695d43b4c74c3ac630a55 (link)
#145735 style-guide: Document absence of trailing whitespace e583e7290695ba9cef3a127178864bf59ad5fa6d (link)
#146041 tidy: --bless now makes escheck run with --fix bb18fb1baa2d909928abc9e0454cd582f5ddb8e6 (link)
#146144 compiler: Apply target features to the entry function 2732afb095e5e898545b8f8e26eac5ec5401209f (link)
#146225 Simplify {f16, f32, f64, f128}::midpoint() 219f155fdb5d08beeaa45b39db6fe0b3051b9221 (link)
#146234 change file-is-generated doc comment to inner 0f5f4c795f6cf2629105d998b373f730263ebcca (link)
#146241 rustc_infer: change top-level doc comment to inner 26a68c75688d2024f27a2402a64bea4a95f9f53f (link)
#146242 Ensure that --html-after-content option is used to check … 5545848e274b5d2d125168ded36d0c1c318ea362 (link)
#146243 remove couple of redundant clones 4026c339a378d99c49ffa7c627545698e8dfde3e (link)
#146250 Bump stage0 rustfmt b9876e513eaacefc48472232bcc9f77e498c235f (link)

previous master: 99317ef14d

In the case of a perf regression, run the following command for each PR you suspect might be the cause: @rust-timer build $SHA

@fmease fmease deleted the rollup-1v0kp8i branch September 6, 2025 00:06
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6c699a3): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary -0.8%, secondary -0.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.1% [2.1%, 2.1%] 1
Regressions ❌
(secondary)
2.4% [2.4%, 2.5%] 2
Improvements ✅
(primary)
-3.6% [-3.6%, -3.6%] 1
Improvements ✅
(secondary)
-3.2% [-4.2%, -2.2%] 2
All ❌✅ (primary) -0.8% [-3.6%, 2.1%] 2

Cycles

Results (secondary -1.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.2% [-1.2%, -1.2%] 1
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 468.222s -> 467.925s (-0.06%)
Artifact size: 390.57 MiB -> 390.56 MiB (-0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-run-make Area: port run-make Makefiles to rmake.rs A-tidy Area: The tidy tool merged-by-bors This PR was explicitly merged by bors. PG-exploit-mitigations Project group: Exploit mitigations rollup A PR which is a rollup S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-release Relevant to the release subteam, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. T-style Relevant to the style team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.