-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add support for automatically finding the macOS SDK #226
Comments
Since testing in CI was getting tedious I made a small app specifically for testing this issue on my Mac. With
The main one that's killing us is the first one. It's added by
With Apple Clang it is getting resolved by the first one, which doesn't apply to us since we aren't Apple Clang. Homebrew Clang uses that to resolve libc++ as well. Homebrew includes its own copy. In theory we could include it too. However it is not currently built by our build scripts. I feel like the more appropriate thing to do here is to use the one in the platform SDK like we (implicitly) do for Windows and Linux. |
I installed Homebrew which installed the Command Line Tools for Xcode and changed some other things. Apple Clang is provided by the command line tools instead now, so some paths changed:
Paths marked with ✨ are present even without Maybe worth noting: Without |
Back on the Same for the first one exception With
That just leaves that non-SDK This one (along with |
…chain on macOS. Fixes MochiLibraries#226
Putting this somewhere I'll end up finding it if it matters: I should poke around in https://opensource.apple.com/ to see if Also I forgot to note that I had a non-developer friend test Unfortunately it also shows this dialog: It's not clear if this dialog appears when |
Discovered while investigating the effort required to stand up CI for macOS even though we don't officially support it yet.
Similar to #201, libclang-pathogen does not automatically discover the macOS SDK on its own. This causes basic system headers to not be found.
Apple Clang and Homebrew Clang do automagically "discover" the SDK.
Running
clang -v
for either reveals-isysroot
is passed with a path to the SDK along with the resource directory, this (and maybe some of the other options near it) are probably what we're probably missing:Manually specifying (non-cc1 equivalents of) these flags seems to fix the issue, so definitely a step in the right direction.
The
-isysroot
option is described as being for setting the system root directory. This seems odd, but the macOS SDK is structured like a Unix root with a./usr/include
and all that. (My understanding is prior to 10.15 macOS used to put include files in/usr/include
but has transitioned to distributing them in Xcode like this.) Unfortunately this option alone is not enough to fix things.I have found references to setting the
SDKROOT
environment variable to specify this SDK root, but this does not seem to work andI didn't find where it was handled within LLVM. This seems to be related toNevermind, must've made a typo. It's handled inxcrun
so maybe Clang uses it somewhere? (And that somewhere is inactive with libclang?)Darwin::AddDeploymentTarget
. It being specified basically just implicitly adds-isysroot $SDKROOT
.I came across this PR from when they solved this issue for the Homebrew LLVM distribution: Homebrew/homebrew-core#45304 I'm not familiar with Homebrew formulas, but from what I can gather they just specify the preprocessor constant
DEFAULT_SYSROOT
with the path to the macOS SDK so it defaults to that.According to the documentation for this constant, this is the equivalent of adding
--sysroot
to your invocations. (Looking at the code this appears to be accurate.) Unfortunately just like-isysroot
this is not enough on its own.As far as locating the SDK programmatically, from what I've found the canonical way is by running
xcrun --sdk macosx --show-sdk-path
xcrun --show-sdk-path
***. I believe what this returns is primarily controlled using thexcode-select
, although there's some environment variables which can override it as well.***Including
--sdk macosx
is likely a mistake. This actually ends up using the versionless SDK (IE:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
). Without it, my machine usesMacOSX10.15.sdk
which feels more appropriate considering I'm running on 10.15. (MacOSX.sdk
is a symlink toMacOSX11.1.sdk
) I feel like this changed after installed Homebrew (and by extension - the Command Line Tools for Xcode), I seem to recall it usedMacOSX.sdk
regardless before.(One thing that's not 100% clear to me is how things are handled when the SDK is provided by the command line tools app instead of Xcode. For example, on my MacBook the SDK is at
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk
but on GitHub Actions it's at/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk
. I don't think we really need to worry about this though.)The text was updated successfully, but these errors were encountered: