[clang] [Darwin][Driver][clang] Prioritise `-isysroot` over `--sysroot` consistently (PR #115993)
Cyndy Ishida via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 2 09:15:37 PST 2024
cyndyishida wrote:
> > However, notably, even on Darwin, if you pass _both_ flags, you still get the intended behavior of `-isysroot` affecting headers, and `--sysroot` affecting libraries. Your change would break that.
>
> What's the use-case for this?
>
> Because for most users, you almost certainly don't want to mix headers and libraries of different versions, and keeping the existing behavior is essentially a big footgun when trying to build a useful toolchain on Darwin.
>
> At Homebrew, we used to configure the toolchain with `DEFAULT_SYSROOT` but have recently switched that to setting the `--sysroot` flag in a Clang `.cfg` file.[1](#user-content-fn-1-21a5728b47e790352033de78c44bc2e4) In either case, if you set `SDKROOT` in your environment or try to run our `clang` using Apple's `xcrun`, this becomes equivalent to setting `-isysroot` and you most likely will end up with headers that mismatch the libraries you try to link to.
The expected flow on Apple platforms is to only pass an `isysroot` argument whether it's inherited from `xcrun -sdk <sdk version> clang` or passed explicitly. Could homebrew instead only pass `isysroot` for Darwin targets? Or check that `sysroot` and `isysroot` inputs are the same when creating an invocation. 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`.
https://github.com/llvm/llvm-project/pull/115993
More information about the cfe-commits
mailing list