-
Notifications
You must be signed in to change notification settings - Fork 448
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
Straightening up messy Apple compilations #664
Comments
Moving #661 (comment) here. @indygreg, @dvc94ch, @vladimir-ea. Tangentially related to this, I've implemented Apple SDK discovery in pure Rust in https://github.com/indygreg/PyOxidizer/blob/ae848c9083c9c8563d5890f5d39a8e04a1d71832/tugger-apple/src/sdk.rs. This includes parsing the SDKSettings.json files to extract SDK metadata such as versions and which targets are supported. Like xcode-select and xcrun, it supports honoring DEVELOPER_DIR for finding the install root of SDKs. There's also some related code at https://github.com/indygreg/PyOxidizer/blob/ae848c9083c9c8563d5890f5d39a8e04a1d71832/pyoxidizer/src/environment.rs#L531 (and elsewhere in this file) for attempting to find an appropriate SDK to use given constraints. (This code should arguably be moved to the aforementioned crate/module.) This code probably isn't suitable for inclusion in this crate as-is. But if you want me to extract it to its own crate or incorporate it into cc-rs somehow, let's talk (in another issue presumably). As for this PR, externally specifying SDKROOT to force the Apple SDK to use seems reasonable to me. This is what I've done with PyOxidizer to allow users to override the built-in/default SDK finding. I say this without knowing how the Rust compiler internally handles SDKROOT, so I may be missing some important context! But my understanding is that build tools commonly export SDKROOT to force use of a specific SDK to avoid downstream tools performing their own SDK discovery. |
First of all I want to clarify that I'm just a cc-rs user responding to #663. Well, obviously in my own way, but nevertheless. #663 [among other things] effectively reads "keep it manageable" and I can't agree more. |
xcrun respects externally specified SDKROOT, so what's the problem? It "kicks in" only when you don't specify one and finds one suitable for
It doesn't matter for cc-rs. Its job is to compile suitable .o module, that's it. |
And the question in the context would be what would it take to implement xcrun replacement? Would it make more sense than to make cc-rs less manageable? [Recall that the "tangent" effectively is "cross-compiling on non-MacOS host."] |
This might be formally incorrect or misleading statement. xcrun "respects" SDKROOT only if you don't specify |
Don't think there is much point discussing this before #663 is resolved. I don't think this solution conflicts with the fairly simple and straightforward setting an environment variable solution. |
So to summarize the behaviour of xcrun (what @indygreg said):
On linux/windows we can then set the SDKROOT or DEVELOPER_DIR and it should just work. Extracting that logic into a crate seems reasonable. I don't think we need a binary called xcrun if the resulting behaviour is the same (use same environment variables). Not sure what the policy is of cc-rs on external crates, maybe it needs to be added to cc-rs. |
+1 will love to see this change landed. let me know how I can help! |
@indygreg does your offer to factor out the sdk selection logic into a separate crate still stand? |
What do you think about https://github.com/indygreg/toolchain-tools/tree/main/apple-sdk? This is effectively what exists in It still needs support for |
... and I guess I need to port some of PyOxidizer's code for finding an appropriate SDK to use. That should be easy enough. But it may not happen for a few days since I'm busy this week. I also have to think about how to do targeting without dependency bloat. Right now we pull in a few dozen crates (via |
I significantly refactored https://github.com/indygreg/toolchain-tools/tree/main/apple-sdk today. I think it is close to being generally usable. The My plan is to port PyOxidizer to use this crate. Once I'm convinced the API feels reasonable, I'll publish a 0.1 release on crates.io. If you build the crate without default features, it doesn't have any dependencies. You lose out on anything that needs to parse Please play around with the crate and let me know if you have any requests. |
And version 0.1 is published! https://crates.io/crates/apple-sdk |
@indygreg Haven't tried it yet, but looks very well documented and tested. Thank you! |
Once again,
And even though there were changes, they don't appear for the better. There is not a single member of the Rust organization on the watchers' list, and I see no signs that we are not still treading water... This is not to diminish @indygreg's contribution, not at all! But I'd still argue in favour of letting xcrun, or stand-in on non-MacOS hosts, do the weight lifting. |
So basically apple-sdk needs a bin called xcrun or cc-rs needs to replace their sdk selection logic with apple-sdk. I guess either option works, we really need to hear from maintainers here. cc @m-ou-se |
I'm fine with any outcome here. Shoring up the logic for I'll just sit tight and assess. |
Ran across this thread working through some issues in cc-rs. For Catalyst - cc-rs is still passing an old version of the build triple (noted in #678). The Bitcode flag is also being passed for Catalyst - even though Catalyst shouldn't use Bitcode. There's also the lurking elimination of Bitcode on Apple platforms (although I think Bitcode objects should compile fine into non-Bitcode targets.) Catalyst output basically isn't usable right now. Is there any forward progress with this PR, or would continued patches to the existing implementation be welcome? |
I'm concerned that using |
Yes. |
I don't know that we'd want to use That said, I'll do some investigation, it's possible those could be removed more easily, or the logic adapted in a way that's viable for us. |
For If |
Oh! Thanks. That wasn't clear to me from docs.rs (which just lists the dependencies, and not that they are optional), and I couldn't immediately find the source from the repo link listed on crates.io, but I didn't look very hard (I was mostly focused on triage and cleanup of cc's PR list last evening).
I'll look through it, but what you say is likely correct, and I suspect that |
I would like to make a case for instead of endlessly struggling to map all those Apple-specific environment variables, e.g. like in #661 and #662, one would simply let
xcrun
do all the work. I mean instead of calling composing all sorts of command line options and passing them tocc
, one would simply callxcrun -sdk [iphoneos|iphonesimulator|watchos|etc.] cc -arch [arm64|x86_64|armv7]
. In other words,cc-rs
would have to simply map Rust target triplet to a combination of -sdk and -arch parameters.The text was updated successfully, but these errors were encountered: