[clang] [Darwin][Driver][clang] Prioritise command line args over `DEFAULT_SYSROOT` (PR #115993)

Carlo Cabrera via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 4 17:45:46 PST 2024


carlocab wrote:

> It's unclear to me how homebrew gets into a situation where there are conflicting sdks passed for `sysroot` and `isysroot` when you effectively want to ignore whatever is passed to `sysroot`.

Maybe this has already been answered, but just in case. You get conflicting SDKs when:

- You build a toolchain that is configured with `DEFAULT_SYSROOT` (or, you use a Clang configuration file that uses `--sysroot=`, which mostly mirrors the effects of setting `DEFAULT_SYSROOT`)
- Your user uses your toolchain and passes `-isysroot` to a different SDK (or, equivalently, sets `SDKROOT` pointing to a different SDK)

In each of the four possible scenarios above (two possibilities in each bullet point), you end up with `clang` using one SDK for headers (coming from `-isysroot`/`SDKROOT`) and a different one for libraries (coming from `DEFAULT_SYSROOT`/`--sysroot`).

> Hm, I had a thought which might meet the needs here, and not add additional confusion: we could have the Darwin SDKROOT environment variable override both `-isysroot` and `--sysroot`. Would that help the original issue?

This would help too, actually. I'll look into this. Thanks.

> I think the correct solution for Homebrew is to never use `--sysroot` and switch to `-isysroot` since the former is almost never used on Darwin platforms.

I'm looking at this in https://github.com/Homebrew/homebrew-core/pull/200047. However, based on [this comment](https://github.com/Homebrew/homebrew-core/pull/200047#issuecomment-2517969578), it doesn't quite solve the downstream bug report entirely. But that's something I'll have to look into.

Us switching to using `-isysroot` instead doesn't solve the problem of (other) users who configure a toolchain with `DEFAULT_SYSROOT`, but maybe the changes I've made here that you suggested at https://github.com/llvm/llvm-project/pull/115993#issuecomment-2518537500 will be enough for that.

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


More information about the cfe-commits mailing list