Skip to content

Commit 97e4067

Browse files
authored
LLVM fixes for latest OSX libcxx SDKs (#751)
* LLVM fixes for latest OSX SDKs * Try to fix Windows git patch error * Use ccache when rebuilding vcpkg tool * Try fixing Windows * Simplify ccache logic for vcpkg tool * Test MacOS 11 in CI * Fix Xcode version for 10.15 * Don't run MacOS 11 in CI The runners still aren't consistent in starting * Reduce ARM CI jobs
1 parent 9fa737a commit 97e4067

16 files changed

+580
-49
lines changed

.github/workflows/vcpkg_ci_linux.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ jobs:
3636
matrix:
3737
host:
3838
- { name: 'ubuntu-20.04', arch: 'amd64', triplet: 'x64-linux-rel', arch_docker: '' }
39-
- { name: ['self-hosted', 'Linux', 'ARM64'], arch: 'arm64', triplet: 'arm64-linux-rel', arch_docker: '_arm64' }
4039
image:
4140
- { name: 'ubuntu', tag: '18.04' }
4241
- { name: 'ubuntu', tag: '20.04' }
@@ -46,6 +45,14 @@ jobs:
4645
'llvm-11',
4746
'llvm-12'
4847
]
48+
# Only some LLVM versions for ARM CI
49+
include:
50+
- host: { name: ['self-hosted', 'Linux', 'ARM64'], arch: 'arm64', triplet: 'arm64-linux-rel', arch_docker: '_arm64' }
51+
llvm: 'llvm-11'
52+
image: { name: 'ubuntu', tag: '18.04' }
53+
- host: { name: ['self-hosted', 'Linux', 'ARM64'], arch: 'arm64', triplet: 'arm64-linux-rel', arch_docker: '_arm64' }
54+
llvm: 'llvm-11'
55+
image: { name: 'ubuntu', tag: '20.04' }
4956

5057
runs-on: ${{ matrix.host.name }}
5158
container:

.github/workflows/vcpkg_ci_mac.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ jobs:
3535
matrix:
3636
os:
3737
- { runner: 'macos-10.15', xcode: '12.4' }
38+
# - { runner: 'macos-11.0', xcode: '12.5' }
3839
llvm: [
40+
'llvm-10',
3941
'llvm-11',
4042
'llvm-12'
4143
]

build_dependencies.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ fi
175175
msg "Boostrapping vcpkg"
176176
(
177177
set -x
178+
if command -v ccache &> /dev/null
179+
then
180+
export CMAKE_C_COMPILER_LAUNCHER="$(which ccache)"
181+
export CMAKE_CXX_COMPILER_LAUNCHER="$(which ccache)"
182+
fi
183+
178184
"${vcpkg_dir}/bootstrap-vcpkg.sh"
179185
)
180186

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
From a3a24316087d0e1b4db0b8fee19cdee8b7968032 Mon Sep 17 00:00:00 2001
2+
From: Louis Dionne <[email protected]>
3+
Date: Wed, 7 Oct 2020 14:27:55 -0400
4+
Subject: [PATCH] [clang] Don't look into <sysroot> for C++ headers if they are
5+
found alongside the toolchain
6+
7+
Currently, Clang looks for libc++ headers alongside the installation
8+
directory of Clang, and it also adds a search path for headers in the
9+
-isysroot. This is problematic if headers are found in both the toolchain
10+
and in the sysroot, since #include_next will end up finding the libc++
11+
headers in the sysroot instead of the intended system headers.
12+
13+
This patch changes the logic such that if the toolchain contains libc++
14+
headers, no C++ header paths are added in the sysroot. However, if the
15+
toolchain does *not* contain libc++ headers, the sysroot is searched as
16+
usual.
17+
18+
This should not be a breaking change, since any code that previously
19+
relied on some libc++ headers being found in the sysroot suffered from
20+
the #include_next issue described above, which renders any libc++ header
21+
basically useless.
22+
23+
Differential Revision: https://reviews.llvm.org/D89001
24+
---
25+
clang/lib/Driver/ToolChains/Darwin.cpp | 47 +++++---
26+
.../usr/include/c++/v1/.keep | 0
27+
.../basic_darwin_sdk_usr_cxx_v1/usr/lib/.keep | 0
28+
.../Driver/darwin-header-search-libcxx.cpp | 101 ++++++++++++++----
29+
4 files changed, 112 insertions(+), 36 deletions(-)
30+
create mode 100644 clang/test/Driver/Inputs/basic_darwin_sdk_usr_cxx_v1/usr/include/c++/v1/.keep
31+
create mode 100644 clang/test/Driver/Inputs/basic_darwin_sdk_usr_cxx_v1/usr/lib/.keep
32+
33+
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
34+
index 46265c1b9f1a..b1fafaeb727a 100644
35+
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
36+
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
37+
@@ -1957,21 +1957,42 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
38+
39+
switch (GetCXXStdlibType(DriverArgs)) {
40+
case ToolChain::CST_Libcxx: {
41+
- // On Darwin, libc++ is installed alongside the compiler in
42+
- // include/c++/v1, so get from '<install>/bin' to '<install>/include/c++/v1'.
43+
- {
44+
- llvm::SmallString<128> P = llvm::StringRef(getDriver().getInstalledDir());
45+
- // Note that P can be relative, so we have to '..' and not parent_path.
46+
- llvm::sys::path::append(P, "..", "include", "c++", "v1");
47+
- addSystemInclude(DriverArgs, CC1Args, P);
48+
+ // On Darwin, libc++ can be installed in one of the following two places:
49+
+ // 1. Alongside the compiler in <install>/include/c++/v1
50+
+ // 2. In a SDK (or a custom sysroot) in <sysroot>/usr/include/c++/v1
51+
+ //
52+
+ // The precendence of paths is as listed above, i.e. we take the first path
53+
+ // that exists. Also note that we never include libc++ twice -- we take the
54+
+ // first path that exists and don't send the other paths to CC1 (otherwise
55+
+ // include_next could break).
56+
+
57+
+ // Check for (1)
58+
+ // Get from '<install>/bin' to '<install>/include/c++/v1'.
59+
+ // Note that InstallBin can be relative, so we use '..' instead of
60+
+ // parent_path.
61+
+ llvm::SmallString<128> InstallBin =
62+
+ llvm::StringRef(getDriver().getInstalledDir()); // <install>/bin
63+
+ llvm::sys::path::append(InstallBin, "..", "include", "c++", "v1");
64+
+ if (getVFS().exists(InstallBin)) {
65+
+ addSystemInclude(DriverArgs, CC1Args, InstallBin);
66+
+ return;
67+
+ } else if (DriverArgs.hasArg(options::OPT_v)) {
68+
+ llvm::errs() << "ignoring nonexistent directory \"" << InstallBin
69+
+ << "\"\n";
70+
}
71+
- // Also add <sysroot>/usr/include/c++/v1 unless -nostdinc is used,
72+
- // to match the legacy behavior in CC1.
73+
- if (!DriverArgs.hasArg(options::OPT_nostdinc)) {
74+
- llvm::SmallString<128> P = Sysroot;
75+
- llvm::sys::path::append(P, "usr", "include", "c++", "v1");
76+
- addSystemInclude(DriverArgs, CC1Args, P);
77+
+
78+
+ // Otherwise, check for (2)
79+
+ llvm::SmallString<128> SysrootUsr = Sysroot;
80+
+ llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1");
81+
+ if (getVFS().exists(SysrootUsr)) {
82+
+ addSystemInclude(DriverArgs, CC1Args, SysrootUsr);
83+
+ return;
84+
+ } else if (DriverArgs.hasArg(options::OPT_v)) {
85+
+ llvm::errs() << "ignoring nonexistent directory \"" << SysrootUsr
86+
+ << "\"\n";
87+
}
88+
+
89+
+ // Otherwise, don't add any path.
90+
break;
91+
}
92+

ports/llvm-10/0023-clang-sys-include-dir-path.patch renamed to ports/llvm-10/0024-vcpkg-fix-clang-sys-include-dir-path.patch

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
2-
index 46265c1b9f1a..f15a4078e8b9 100644
2+
index b1fafaeb727a..a0aeb507d3b1 100644
33
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
44
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
5-
@@ -1958,10 +1958,11 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
6-
switch (GetCXXStdlibType(DriverArgs)) {
7-
case ToolChain::CST_Libcxx: {
8-
// On Darwin, libc++ is installed alongside the compiler in
9-
- // include/c++/v1, so get from '<install>/bin' to '<install>/include/c++/v1'.
10-
+ // include/c++/v1, so get from '<install>/tools/llvm' to '<install>/include/c++/v1'.
11-
{
12-
llvm::SmallString<128> P = llvm::StringRef(getDriver().getInstalledDir());
13-
// Note that P can be relative, so we have to '..' and not parent_path.
14-
+ llvm::sys::path::append(P, "..");
15-
llvm::sys::path::append(P, "..", "include", "c++", "v1");
16-
addSystemInclude(DriverArgs, CC1Args, P);
17-
}
5+
@@ -1967,11 +1967,12 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
6+
// include_next could break).
7+
8+
// Check for (1)
9+
- // Get from '<install>/bin' to '<install>/include/c++/v1'.
10+
+ // Get from '<install>/tools/llvm' to '<install>/include/c++/v1'.
11+
// Note that InstallBin can be relative, so we use '..' instead of
12+
// parent_path.
13+
llvm::SmallString<128> InstallBin =
14+
llvm::StringRef(getDriver().getInstalledDir()); // <install>/bin
15+
+ llvm::sys::path::append(InstallBin, "..");
16+
llvm::sys::path::append(InstallBin, "..", "include", "c++", "v1");
17+
if (getVFS().exists(InstallBin)) {
18+
addSystemInclude(DriverArgs, CC1Args, InstallBin);
1819
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
1920
index e8ef881e89ac..6711ebb12e06 100644
2021
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Tests cause failure on Mac when compiling NATIVE tablegen due to removing some
2+
compiler-rt architectures
3+
4+
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
5+
index 8d768a404f21..b6185e55e6fc 100644
6+
--- a/compiler-rt/CMakeLists.txt
7+
+++ b/compiler-rt/CMakeLists.txt
8+
@@ -506,20 +506,4 @@ pythonize_bool(COMPILER_RT_HAS_LLD)
9+
10+
add_subdirectory(lib)
11+
12+
-if(COMPILER_RT_INCLUDE_TESTS)
13+
- add_subdirectory(unittests)
14+
- add_subdirectory(test)
15+
- if (COMPILER_RT_STANDALONE_BUILD)
16+
- # If we have a valid source tree, generate llvm-lit into the bin directory.
17+
- # The user can still choose to have the check targets *use* a different lit
18+
- # by specifying -DLLVM_EXTERNAL_LIT, but we generate it regardless.
19+
- if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
20+
- add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)
21+
- elseif(NOT EXISTS ${LLVM_EXTERNAL_LIT})
22+
- message(WARNING "Could not find LLVM source directory and LLVM_EXTERNAL_LIT does not"
23+
- "point to a valid file. You will not be able to run tests.")
24+
- endif()
25+
- endif()
26+
-endif()
27+
-
28+
add_subdirectory(tools)

ports/llvm-10/portfile.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ vcpkg_from_github(
2121
0020-remove-FindZ3.cmake.patch
2222
0021-fix-FindZ3.cmake.patch
2323
0022-llvm-config-bin-path.patch
24-
0023-clang-sys-include-dir-path.patch
24+
0023-fix-macos-libcxx-header-handling.patch
25+
0024-vcpkg-fix-clang-sys-include-dir-path.patch
26+
0025-remove-compiler-rt-tests.patch
2527
)
2628

2729
include("${CURRENT_INSTALLED_DIR}/share/llvm-vcpkg-common/llvm-common-build.cmake")

0 commit comments

Comments
 (0)