Allow Apple SDK to be missing on non-host macOS by madsmtm · Pull Request #139053 · rust-lang/rust (original) (raw)
Allow the SDK to be missing when cross-compiling to Apple platforms from non-host macOS, and instead emit a warning, since it is often available in the cross-compilation tooling the user has installed.
Note that in the common cross-compilation case (to macOS while linking with cc
-like compiler), users won't actually hit this, since xcrun
isn't invoked in that case. But I intend to change that in #131477, and then the error message here will start to matter a lot more.
The message now looks something like:
$ rustc +stage1 example.rs --target aarch64-apple-ios
warning: invoking "xcrun" "--sdk" "iphoneos" "--show-sdk-path"
to find iPhoneOS.sdk failed: No such file or directory (os error 2)
|
= note: the SDK is needed by the linker to know where to find symbols in system libraries and for embedding the SDK version in the final object file
= help: pass the path to the SDK using the SDKROOT environment variable
= help: the SDK can be downloaded and extracted from https://developer.apple.com/download/all/?q=xcode (requires an Apple ID).
The full Xcode bundle should contain the SDK in Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk.
= warning: you will also need to use a linker capable of linking Mach-O files, consider using the bundled lld
with -Clinker=rust-lld
= warning: cross-compiling on iOS, tvOS, visionOS or watchOS (in particular the linking step) is ill supported on non-macOS hosts
Suggestions on how to improve it welcome!
Might also make sense to emit some of these help messages if the linker invocation itself fails? Unsure, but I'll work on that in a different PR.
(I originally considered not even attempting to invoke xcrun
, but decided to continue doing that, since an xcrun
-compatible interface can be present on other platforms, it's just unusual (e.g. Facebook developed xcbuild for a while, similar probably exist)).
Follow-up to #139010.
Part of #129432.
Related to rust-lang/rustup#1483 in that we now document the steps required for cross-compilation in the error message.
@rustbot label O-apple
r? wesleywiser since you just reviewed #139010
CC @BlackHoleFox @thomcc