[clang] [clang] Match -isysroot behaviour with system compiler on Darwin (PR #80524)
Louis Dionne via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 5 07:57:43 PST 2024
ldionne wrote:
> > So the intent of the current ordering was to allow creating a toolchain by placing the libc++ headers alongside Clang, as is typically done (and exceptionally not done on Apple platforms). On Apple platforms, you basically always specify a sysroot, either explicitly or implicitly (via env vars). You have to, since the SDK is where you find everything you need to compile even the most basic program (like our libc headers).
>
> @ldionne thank you for explaining the reasoning behind the decision. Unfortunately, it makes the life of a non-system compilers and clang-tools much more complicated on Apple platforms. They usually don’t have system headers shipped with them so they rely on one provided in SDK. My interest in this issue started from clang-tidy that was not able to find cxxabi.h in the path specified with -isysroot due to the new order introduced in https://reviews.llvm.org/D89001.
If you ship libc++ headers in the toolchain directory as part of your non-system compiler, you should also be shipping the lib++abi headers in the toolchain directory. Libc++ and libc++abi always go hand in hand, that's a common source of confusion.
> But it seems my use case will be broken anyway if SDK stops providing libc++ headers. Is it the eventual future?
No. The libc++ headers are in the SDK right now and they will remain there in the future.
> If it is the case, checking -sysroot first will be only a temporary solution. I still think that it makes sense for the time being but also we need to think about a long term solution for non-system compilers and clang-tools. Perhaps it should be configured at build time if you are building the system default compiler or additional tools shipped separately.
The current setup is explicitly intended to make the life of non-system compilers easier. You pass `-isysroot <SDK>` for the system headers, and if you happen to want to build libc++ from source and ship it with your system compiler, you place the headers in the toolchain directory (as usually done in upstream LLVM) and everything will work. If you want to rely on the SDK-provided libc++ instead, you simply don't put any libc++ headers in the toolchain directory and Clang will use the ones it finds in `-isysroot`.
I feel like either I am fundamentally misunderstanding something or we're talking past each other. I don't see a problem with the current logic as done upstream, since it makes it easiest to build a non-system toolchain (from my point of view at least).
https://github.com/llvm/llvm-project/pull/80524
More information about the cfe-commits
mailing list