RFC: Option to automatically use Xcode SDK

The recent improvements to configuration files make it easy to make a cross-compiler: simply provide the sysroot and a target-specific configuration file, and e.g. clang --target=aarch64-pc-linux-gnu “just works” from an x86-64 system.

MacOS is not as simple. The install location of Xcode’s sysroot must be determined with xcrun, putting the onus on build systems to find the sysroot.

To make cross-compilation with configuration files just as easy on macOS, I propose an option such as --xcode-sdk=iphoneos, which would be roughly identical to --sysroot=$(xcrun --sdk iphoneos --show-sdk-path).

I’m open to any other suggestions!

1 Like
> xcode-select
xcode-select: error: no command option given
Usage: xcode-select [options]

Print or change the path to the active developer directory. This directory
controls which tools are used for the Xcode command line tools (for example,
xcodebuild) as well as the BSD development commands (such as cc and make).

I don’t believe xcode-select can choose the sysroot (it may set the SYSROOT environment variable, I’m not sure), but that would have the same problem as xcrun. I’m interested in having the driver select the sysroot itself, so I can have an arm64-apple-ios.cfg configuration file that contains all compilation options.

For reference on the new behavior of configuration files, see this commit: [clang] [Driver] More flexible rules for loading default configs · llvm/llvm-project@063e17d · GitHub

You could put -isysroot path to iOS sdk into your config file?!?

As a user who knows where XCode is installed, correct, but the provider of a toolchain cannot. With a freely licensed sysroot (such as for Linux), the toolchain can distribute the sysroot and use a directory relative to the special <CFGDIR> token. Since this is not possible with XCode, someone must run xcrun.

Here’s an example of what I would like the clang driver to do, in rustc: rust/link.rs at db0597f5619d5ed93feca28e61226d3581cc7867 · rust-lang/rust · GitHub

Open-Source Clang does not know where the SDK is. Clang does not invoke xcrun. How could Clang invoke xcrun when cross-compiling?

I am proposing adding a new flag to the driver which causes it to run xcrun. It could be done similarly to how clangd already does it: llvm-project/CompileCommands.cpp at 23ace26e0d1aa2283d65d192c37592fb0eef1b1f · llvm/llvm-project · GitHub

Do you ship xcrun binaries on Linux?

The flag would only be available on macOS hosts.


Interesting, this is very similar to what I’m suggesting. I’m not sure about the implications of doing it by default, rather than a flag, but this is what I would like. Maybe I’ll pick up where that review left off.

1 Like