Provide cross-compiling guidance when Apple SDK is missing#139053
Provide cross-compiling guidance when Apple SDK is missing#139053madsmtm wants to merge 1 commit intorust-lang:mainfrom
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. |
wesleywiser
left a comment
There was a problem hiding this comment.
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. |
The SDK, along with a cross-linker, are the two main components required to link pure-Rust applications from non-macOS systems, but this can be hard to figure out.
5ade657 to
610b42d
Compare
|
Sorry for the delay in responding here. What you are saying is correct, by using Regardless, I have moved the "allow SDK to be missing" part to #131477, since it fits more clearly there, so this PR only contains the improved guidance when cross-compiling from non-macOS. And I have sent an email to the Foundation asking for legal help here. @rustbot blocked (on Foundation legal) |
|
Hello, checking progress here. Is this comment still actual? I think I don't see a discussion on Zulip with the Foundation about this. Are there any updates? |
|
I talked with some Rust Foundation people back in late August (email and a call), they were busy at the time with RustConf IIRC. I've sent a follow-up email now. |
|
One thing about Zig's approach is they're only copying in the one library-stubs file I actually want to propose that rustc bundle a copy of [build]
target = "x86_64-apple-darwin"
[target.x86_64-apple-darwin]
linker = "clang-20"
rustflags = ["-C", "link-args=-fuse-ld=lld -target x86_64-apple-darwin", "-L", "/tmp/libs"]
[target.aarch64-apple-darwin]
linker = "clang-20"
rustflags = ["-C", "link-args=-fuse-ld=lld -target aarch64-apple-darwin", "-L", "/tmp/libs"](There might be better syntax for this, but also I am proposing we get to the point where there is no need for any user-provided syntax for this!) So this would probably be a slightly different legal question. Instead of "Is it okay to suggest that users could download the whole SDK when they're likely on a system that you're not allowed to do that on," we're asking "is it okay for us to ship this one file which is derived from an APSL source but reaches us through a Mac, just like Zig has been doing for 4+ years". (I do suspect you could regenerate this file from the public Apple OSS code drops if you tried hard enough, but that would likely turn into more ongoing maintenance work in addition to the up-front work, and I'd also worry about the risk of discrepancies with the real SDK.) |
I've been considering the same thing. A semi-alternative would be #146357. One wrinkle is that this naturally forces
Assuming you don't use macOS-specific frameworks, then yes.
See rust-lang/cc-rs#1585 for ideas on that.
Not just slightly, it's significantly different. In the email I sent to the Rust Foundation I was trying to get clarification on how much of Feel free to send them an email yourself, that might help move things along. |
|
Yeah, the use cases I have in mind are for cross-platform code anyway which generally don't need the Apple-specific frameworks. That said, a good handful of other useful frameworks appear to be APSL (SystemConfiguration, Security, etc.) or Apache (CoreFoundation), so the same argument could apply to including their I've been super out of the loop in Rust for a while, are you just contacting the Foundation's public contact address or do you have a contact specifically with legal? I'm definitely happy to email the public contact address with the question of "can we do what Zig does for this one file" and see how that goes. Thanks for the link to that cc-rs issue! Seems like it would be helpful for -sys crates.
Do you actually see the behavior change, or are you just looking at the docs? Naively, if I compile #import <AppKit/NSView.h>
#import <AppKit/NSOpenGLView.h>
int main(void) {
NSOpenGLView *v = [[NSOpenGLView alloc] initWithFrame:NSMakeRect(1, 2, 3, 4) pixelFormat:[NSOpenGLView defaultPixelFormat]];
printf("%d\n", v.wantsBestResolutionOpenGLSurface);
}with In any case, Xcode only installs the single latest SDK and gives you |
I don't think
I wrote to them at It's on my todo-list to get a hold of some contacts internally Apple to help with these kinds of things too, so you might also just wanna wait for me to get around to doing that, idk.
The thing that influences this particular case is actually the SDK part of the I don't recall seeing cases that are influenced by the
Prooobably not, though I'm still wary of overriding the versions from the SDK (e.g. if users are intentionally using an older Xcode to build their applications, it'd be surprising if we started making their app behave as-if it was built using a newer Xcode). |
Aha, thanks, I can see the difference with
To be clear, I'm only proposing that we implicitly use a bundled libSystem.tbd if both we're not on macOS / are cross-compiling and SDKROOT isn't set. If you're on macOS and you're compiling software, there's little reason not to install the SDK the normal way, especially as you're going to need stuff like a linker anyway. (But we can make it available as an option.) If you're setting SDKROOT we should respect that. So this should only take effect in the case where you do not have an existing SDK available to override and have no obvious better (slash legal) way of getting one. Also, if it is just |
|
☔ The latest upstream changes (presumably #152156) made this pull request unmergeable. Please resolve the merge conflicts. |
Emit more guided warnings when cross-compiling to Apple platforms from non-host macOS.
Note that in the common cross-compilation case (to macOS while linking with
cc-like compiler), users won't actually hit this, sincexcrunisn'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 developedxcbuildfor 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