-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Allow Apple SDK to be missing on non-host macOS #139053
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in compiler/rustc_codegen_ssa |
Converted to draft, because I want to think a little bit if we should make it a warning on host macOS too (to allow linking with e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As written, this looks fine to me so please ping me when you move it out of draft state (whichever way you decide) 🙂
We might want to be a bit careful around recommending usage of the Apple SDK if our host triple isn't an apple triple - IIRC, the license terms don't permit usage of some parts of the SDK on non-apple hardware? |
Ah, yeah, the Xcode SLA does say in section "2.2 A Permitted Uses and Restrictions":
And in section "2.7 Restrictions; No Other Permitted Uses":
Btw, I can change the wording to state that what the user is trying to do (cross link) is (probably, IANAL) not allowed according to Apple's terms? Though I still feel it important to provide these instructions in some shape or form. Minutiae:
|
I think consulting with Foundation legal could be a good idea; I generally agree that as long as we're just pointing to Apple's pages on downloads etc. that's OK. Maybe adding some note around reading the terms would help. I think the larger goal of this PR is not as clear to me though. It seems like, today, if I want to produce e.g. a dylib with Rust's standard library/core but no C code, I don't need the Apple SDK to do so -- lld is more or less happy to produce a Mach-O shared object (or non-shared object) from a pure Rust crate. If I want to compile C code for an Apple target, it's also possible that Apple SDKs are not required (e.g., because I'm not calling anything that requires Apple SDK headers). But if we start requiring |
Hmm, perhaps I haven't been clear enough here. The Apple SDKs provides two things: headers and linker stubs.
|
This seems untrue to me -- e.g., I produced this:
Without linking any shared libraries on a x86_64-unknown-linux-gnu host with:
That fails with:
But, if I edit that command to:
That produces a libt.dylib that looks functional to me. Copying that to my macOS laptop, I can then link it with C and run it:
Unless lld has bundled something (or maybe Rust has), I didn't use zig or similar here and AFAIK there's no linker stubs involved in producing this result. |
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, sincexcrun
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:
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 anxcrun
-compatible interface can be present on other platforms, it's just unusual (e.g. Facebook developedxcbuild
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