[clang] [clang] Match -isysroot behaviour with system compiler on Darwin (PR #80524)

Daniel Rodríguez Troitiño via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 5 12:57:40 PST 2024


drodriguez wrote:

> @drodriguez I'm not certain why you think AppleClang prefers `isysroot` over toolchain headers -- it might be because we simply don't ship libc++ toolchain headers anymore and we only ship libc++ SDK headers. But if you try installing libc++ headers in the toolchain alongside a reasonably recent AppleClang, it should prefer them over the SDK headers (which is consistent with the upstream behavior).

This is the tests I have done to verify:

```
$ mkdir -p /tmp/test-toolchains/
$ cd /tmp/test-toolchains/
$ cp -R /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain pristine
$ cp -R pristine modified
$ mkdir -p modified/usr/include/c++/v1
$ echo "#error Boom" > modified/usr/include/c++/v1/cxxabi.h
$ echo "#include <cxxabi.h>" > test.cpp

# Using pristine, which does not have any headers beside it
$ pristine/usr/bin/clang -c test.cpp -o test.pristine.o
test.cpp:1:10: fatal error: 'cxxabi.h' file not found
#include <cxxabi.h>
         ^~~~~~~~~~
1 error generated.

# Using modified, with the headers beside it
modified/usr/bin/clang -c test.cpp -o test.modified.o
In file included from test.cpp:1:
/tmp/test-toolchain/modified/usr/bin/../include/c++/v1/cxxabi.h:1:2: error: Boom
#error Boom
 ^
1 error generated.

# Using modified, but passing a isysroot (no errors)
$ modified/usr/bin/clang -c test.cpp -o test.sysroot.o -isysroot (xcrun --show-sdk-path)
$ ls test.sysroot.o
test.sysroot.o
```

Unless I am understanding the behaviour incorrectly, this seems to be the opposite of the upstream behaviour.

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


More information about the cfe-commits mailing list