This is an archive of the discontinued LLVM Phabricator instance.

[clang][driver] Find Apple default SDK path
AbandonedPublic

Authored by thieta on Jul 10 2022, 7:35 AM.

Details

Summary

Currently if you download clang and install it on macOS it will
not be able to compile C++ applications out of the box. The
driver can't find the SDK path without help of SDKROOT or -isysroot.

For the Xcode toolchain this is always supplied with xcrun or
the wrapper binary that sets the correct SDKROOT.

But for new users this might be very confusing and since the
path for the SDKs is stable unless the user decide to install
Xcode to an alternative path we can try a naive search for it.

Currently this patch fails a bunch of tests that seems to assume
that no SDK is found and then the macosx-min stuff is set to
something very low. This changes when you have a real SDK.

I also haven't added any new tests to test this since I am didn't
want to assume that Xcode is installed on the system running the
tests. Does anyone have a good idea for testing this?

Tagged a bunch of apple people that have touched the driver
recently - but feel free to add more in here if needed.

Diff Detail

Event Timeline

thieta created this revision.Jul 10 2022, 7:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 10 2022, 7:35 AM
thieta requested review of this revision.Jul 10 2022, 7:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 10 2022, 7:35 AM
Herald added a subscriber: MaskRay. · View Herald Transcript

Ping - any thoughts on this one?

I’m not at Apple anymore, but this is a long-standing platform decision that is intentional and seems unlikely to change. Note that /usr/bin/clang isn’t really clang, but a tool called xcrun which adds environment variables to help find a default SDK before executing /path/to/toolchain/usr/bin/clang.

When the driver is called directly it expects the build system to provide the appropriate SDK. There are situations where it could cause a problem for the driver to hunt around tor arbitrary SDKs.

If you still want to pursue this, @arphaman might be able to help find someone in a position to consider the impact / policy.

thieta abandoned this revision.Oct 6 2022, 12:44 AM

(With configuration file improvement, you can express the intention with a default configuration file.)