[PATCH] D159292: [driver] Conditionally include installed libc++ headers for Android

Shoaib Meenai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 31 09:17:09 PDT 2023


smeenai created this revision.
smeenai added reviewers: danalbert, srhines, pcc, phosek, thakis, MaskRay, glandium.
Herald added a subscriber: danielkiss.
Herald added a project: All.
smeenai requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

https://reviews.llvm.org/D71154 prevented Clang from search for libc++
headers installed alongside the driver when targeting Android. The
motivation was the NDK's use of a different libc++ inline namespace
(`__ndk1` instead of the standard `__1`), which made regular libc++
headers incompatible with the NDK's libc++ library.

Since then, libc++ has gained the ability to install its `__config_site`
header (which controls the inline namespace, among other things) to a
per-target include directory, which enables per-target customizations.
If this directory is present, the user has expressly built libc++ for
Android, and we should use those headers.

The motivation is that, with the current setup, if a user builds their
own libc++ for Android, they'll use the library they built themselves
but the NDK's headers instead of their own, which is surprising at best
and can cause all sorts of problems (e.g. if you built your own libc++
with a different ABI configuration). It's important to match the headers
and libraries in that scenario, and checking for an Android per-target
include directory lets us do so without regressing the original scenario
which https://reviews.llvm.org/D71154 was addressing.

While I'm here, switch to using sys::path::append instead of slashes
directly, to get system path separators on Windows, which is consistent
with how library paths are constructed (and that consistency will be
important in a follow-up, where we use a common search function for the
include and library path construction).

(As an aside, one of the motivations for https://reviews.llvm.org/D71154
was to support targeting both Android and Apple platforms, which
expected libc++ headers to be provided by the toolcain at the time.
Apple has since switched to including libc++ headers in the platform SDK
instead of in the toolchain, so that specific motivation no longer
applies either.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159292

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/android-installed-libcxx.cpp
  clang/test/Driver/android-ndk-standalone.cpp
  clang/test/Driver/android-no-installed-libcxx.cpp
  clang/test/Driver/linux-header-search.cpp
  clang/test/Driver/linux-musl-header-search.cpp
  clang/test/Driver/linux-per-target-runtime-dir.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159292.555080.patch
Type: text/x-patch
Size: 15894 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230831/efb6d12a/attachment-0001.bin>


More information about the cfe-commits mailing list