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

Improve xcrun error handling #139010

Merged
merged 4 commits into from
Mar 28, 2025
Merged

Improve xcrun error handling #139010

merged 4 commits into from
Mar 28, 2025

Conversation

madsmtm
Copy link
Contributor

@madsmtm madsmtm commented Mar 27, 2025

The compiler invokes xcrun on macOS when linking Apple targets, to find the Xcode SDK which contain all the necessary linker stubs. The error messages that xcrun outputs aren't always that great though, so this PR tries to improve that by providing extra context when an error occurs.

Fixes #56829.
Fixes #84534.
Part of #129432.
See also the alternative #131433.

Tested on:

  • x86_64-apple-darwin, MacBook Pro running Mac OS X 10.12.6
    • With no tooling installed
    • With Xcode 9.2
    • With Xcode 9.2 Commandline Tools
  • aarch64-apple-darwin, MacBook M2 Pro running macOS 14.7.4
    • With Xcode 13.4.1
    • With Xcode 16.2
    • Inside nix-shell -p xcbuild (nixpkgs' xcrun shim)
  • aarch64-apple-darwin, VM running macOS 15.3.1
    • With no tooling installed
    • With Xcode 16.2 Commandline Tools

@rustbot label O-apple
r? compiler
CC @BlackHoleFox @thomcc

madsmtm added 3 commits March 27, 2025 03:34
I've intentionally used slightly vague language ("roughly"), as we don't
want to guarantee the exact invocation of `xcrun`, just hint that it's
close to that.
It can be a fairly expensive operation when the output is not cached, so
it's nice to get some visibility into the runtime cost.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 27, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 27, 2025

Some changes occurred in src/doc/rustc/src/platform-support

cc @Noratrieb

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@rustbot rustbot added the O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) label Mar 27, 2025
@rust-log-analyzer

This comment has been minimized.

@madsmtm madsmtm force-pushed the parse-xcrun-better branch from 37a78c0 to 4f68498 Compare March 27, 2025 03:25
Also allow the SDK path to be non-UTF-8.
@madsmtm madsmtm force-pushed the parse-xcrun-better branch from 4f68498 to 89348e5 Compare March 27, 2025 03:39
Copy link
Member

@wesleywiser wesleywiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks great! I don't have the proper setup to test it but it sounds like you already have.

@wesleywiser
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 27, 2025

📌 Commit 89348e5 has been approved by wesleywiser

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 Mar 27, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request Mar 27, 2025
…eywiser

Improve `xcrun` error handling

The compiler invokes `xcrun` on macOS when linking Apple targets, to find the Xcode SDK which contain all the necessary linker stubs. The error messages that `xcrun` outputs aren't always that great though, so this PR tries to improve that by providing extra context when an error occurs.

Fixes rust-lang#56829.
Fixes rust-lang#84534.
Part of rust-lang#129432.
See also the alternative rust-lang#131433.

Tested on:
- `x86_64-apple-darwin`, MacBook Pro running Mac OS X 10.12.6
    - With no tooling installed
    - With Xcode 9.2
    - With Xcode 9.2 Commandline Tools
- `aarch64-apple-darwin`, MacBook M2 Pro running macOS 14.7.4
    - With Xcode 13.4.1
    - With Xcode 16.2
    - Inside `nix-shell -p xcbuild` (nixpkgs' `xcrun` shim)
- `aarch64-apple-darwin`, VM running macOS 15.3.1
    - With no tooling installed
    - With Xcode 16.2 Commandline Tools

`@rustbot` label O-apple
r? compiler
CC `@BlackHoleFox` `@thomcc`
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 28, 2025
Rollup of 5 pull requests

Successful merges:

 - rust-lang#138104 (Greatly simplify doctest parsing and information extraction)
 - rust-lang#139010 (Improve `xcrun` error handling)
 - rust-lang#139021 (std: get rid of pre-Vista fallback code)
 - rust-lang#139026 (Use `abs_diff` where applicable)
 - rust-lang#139030 (saethlin goes on vacation)

r? `@ghost`
`@rustbot` modify labels: rollup
Copy link
Contributor

@BlackHoleFox BlackHoleFox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 28, 2025
Rollup of 6 pull requests

Successful merges:

 - rust-lang#138720 (Specify a concrete stack size in channel tests)
 - rust-lang#139010 (Improve `xcrun` error handling)
 - rust-lang#139021 (std: get rid of pre-Vista fallback code)
 - rust-lang#139025 (Do not trim paths in MIR validator)
 - rust-lang#139026 (Use `abs_diff` where applicable)
 - rust-lang#139030 (saethlin goes on vacation)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 28, 2025
Rollup of 6 pull requests

Successful merges:

 - rust-lang#138720 (Specify a concrete stack size in channel tests)
 - rust-lang#139010 (Improve `xcrun` error handling)
 - rust-lang#139021 (std: get rid of pre-Vista fallback code)
 - rust-lang#139025 (Do not trim paths in MIR validator)
 - rust-lang#139026 (Use `abs_diff` where applicable)
 - rust-lang#139030 (saethlin goes on vacation)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0b40e6e into rust-lang:master Mar 28, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 28, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 28, 2025
Rollup merge of rust-lang#139010 - madsmtm:parse-xcrun-better, r=wesleywiser

Improve `xcrun` error handling

The compiler invokes `xcrun` on macOS when linking Apple targets, to find the Xcode SDK which contain all the necessary linker stubs. The error messages that `xcrun` outputs aren't always that great though, so this PR tries to improve that by providing extra context when an error occurs.

Fixes rust-lang#56829.
Fixes rust-lang#84534.
Part of rust-lang#129432.
See also the alternative rust-lang#131433.

Tested on:
- `x86_64-apple-darwin`, MacBook Pro running Mac OS X 10.12.6
    - With no tooling installed
    - With Xcode 9.2
    - With Xcode 9.2 Commandline Tools
- `aarch64-apple-darwin`, MacBook M2 Pro running macOS 14.7.4
    - With Xcode 13.4.1
    - With Xcode 16.2
    - Inside `nix-shell -p xcbuild` (nixpkgs' `xcrun` shim)
- `aarch64-apple-darwin`, VM running macOS 15.3.1
    - With no tooling installed
    - With Xcode 16.2 Commandline Tools

``@rustbot`` label O-apple
r? compiler
CC ``@BlackHoleFox`` ``@thomcc``
@madsmtm madsmtm deleted the parse-xcrun-better branch March 28, 2025 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
6 participants