[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 11:13:18 PST 2024


Bo98 wrote:

> I don't think it's deprecated in the sense we have plans to drop support for it. The problem here seems more like when those values conflict what should be expected?
>
> Today it seems expected that `sysroot` will be used for library search but not header search, which also matches the other platforms. I don't know if this adds confusion or helps unblock, but clang on Darwin also respects the env var `SDKROOT` which translates to `isysroot`.

I do agree with this and this does make sense. The problem has mostly come from two expectations:
* `DEFAULT_SYSROOT` was expected by some users to support setting a default SDK. Maybe this wasn't actually intended, but it came common enough knowledge to eventually be explicitly recommended in parts of LLVM documentation: https://github.com/llvm/llvm-project/blob/ee9e7867178bee16cc0976a83a8303c99c2f5326/flang/docs/GettingStarted.md?plain=1#L91-L93.
* `-isysroot` generally seems to preferred on macOS over `--sysroot`, despite that not being the case on other platforms.

However those two points are incompatible. And `DEFAULT_SYSROOT` was, until the introduction of config files recently, the only way to set a default as the Apple's SDK driver is closed source. We used `DEFAULT_SYSROOT` since the SDK changes in 10.14, but config files are becoming a possible alternative with #111387.

---

This probably crosses into #38193, but to paint the wider picture since I agree the problem here is more complicated than a prioritisation problem, it's generally expected from various build scripts that something like this:

```clang
#include <stdio.h>

int main() {
   printf("Hello, World!");
   return 0;
}
```

will just work out of the box without needing extra flags or to pipe it through other commands. It works out of the box on Linux and likely most other platforms but does not on macOS.

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


More information about the cfe-commits mailing list