[clang] [Darwin][Driver][clang] Prioritise `-isysroot` over `--sysroot` consistently (PR #115993)

Bo Anderson via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 4 12:29:45 PST 2024


Bo98 wrote:

> There is no standard location for macOS SDK, and it can be anywhere you want. DEFAULT_SYSROOT can't fix any problem for distribution.

To be clear: the build I talked about there required the CLT where the SDK location is standardised, so this isn't entirely true for the use case I had. But yes a general LLVM solution would require something more like `xcrun`.

The major-fixed `MacOSX.sdk` (e.g. `MacOSX15.sdk`) distributed with the CLT was in fact something we requested from Apple a few years back and was implemented for the precise use case where downstream tools (mostly GCC but it ended up being used for LLVM too) needed a fixed location. (I don't have the `rdar` number on hand as I don't have the conversation saved but hopefully you get what I mean here)

> all SDKs are backwards compatible to older OS versions, which allows you to build software for older OS on latest version

This is mostly true but there are notable exceptions such as:
* `libcurl` does not have OS availability APIs and it is known that using `libcurl` headers can lead to runtime crashes on older OS
* `unguarded-availability-new` is a warning by default and not all configure scripts set `-Werror` for it so will not detect feature availability properly

And we have seen these break real world applications, even high profile ones like `git`.

This doesn't really change anything here though. Distributing `clang` in a way that doesn't need extra flags is still an expectation the vast majority of downstream build scripts expect, regardless what SDK that is.

>  If you intended to make this less a problem for unsuspecting users, I would change to pass -isysroot on Darwin, instead of using `--sysroot` for `DEFAULT_SYSROOT`. That should be safe enough to not disrupt any users.

`DEFAULT_SYSROOT` is a LLVM feature. It cannot be made to use `-isysroot`.

Migrating to config files does give us the option to use `-isysroot` instead and we will do that. The v1 initial port to config files was simply a 1:1 behavioural match to the previous `DEFAULT_SYSROOT` behaviour. We've been contributing patches upstream to make config files work better for this use case (such as the separate Darwin PR linked above) and getting feedback from users from edge cases where config files still aren't being applied correctly such as `clang-tidy`.

https://github.com/llvm/llvm-project/pull/115993


More information about the cfe-commits mailing list