Skip to content

Commit 78d759a

Browse files
authored
Merge pull request #22184 from hyp/buildInstallClangAndClangd
Build and install 'clang' and 'clangd' in the macOS & linux toolchains
2 parents e9d81e1 + 1941aaa commit 78d759a

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

utils/build-presets.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,8 @@ install-swiftpm
728728
install-xctest
729729
install-libicu
730730
install-prefix=/usr
731-
swift-install-components=autolink-driver;compiler;clang-builtin-headers;stdlib;swift-remote-mirror;sdk-overlay;parser-lib;license;sourcekit-inproc
732-
llvm-install-components=llvm-cov;llvm-profdata;IndexStore
731+
swift-install-components=autolink-driver;compiler;clang-resource-dir-symlink;stdlib;swift-remote-mirror;sdk-overlay;parser-lib;license;sourcekit-inproc
732+
llvm-install-components=llvm-cov;llvm-profdata;IndexStore;clang;clang-headers;compiler-rt;clangd
733733
build-swift-static-stdlib
734734
build-swift-static-sdk-overlay
735735
build-swift-stdlib-unittest-extra
@@ -1080,8 +1080,8 @@ test-installable-package
10801080
# If someone uses this for incremental builds, force reconfiguration.
10811081
reconfigure
10821082

1083-
swift-install-components=compiler;clang-builtin-headers;stdlib;sdk-overlay;parser-lib;license;sourcekit-xpc-service;swift-remote-mirror;swift-remote-mirror-headers
1084-
llvm-install-components=llvm-cov;llvm-profdata;IndexStore
1083+
swift-install-components=compiler;clang-resource-dir-symlink;stdlib;sdk-overlay;parser-lib;license;sourcekit-xpc-service;swift-remote-mirror;swift-remote-mirror-headers
1084+
llvm-install-components=llvm-cov;llvm-profdata;IndexStore;clang;clang-headers;compiler-rt;clangd
10851085

10861086
# Path to the .tar.gz package we would create.
10871087
installable-package=%(installable_package)s

utils/build-script-impl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,12 @@ if [ ! -d "${CLANG_SOURCE_DIR}" ] ; then
12211221
make_relative_symlink "${WORKSPACE}/clang" "${CLANG_SOURCE_DIR}"
12221222
fi
12231223

1224+
# Don't symlink clang-tools-extra into the tree as the 'clang' symlink prevents
1225+
# make_relative_symlink from working correctly.
1226+
if [ -e "${WORKSPACE}/clang-tools-extra" ] ; then
1227+
CLANG_TOOLS_EXTRA_SOURCE_DIR="${WORKSPACE}/clang-tools-extra"
1228+
fi
1229+
12241230
# Symlink compiler-rt into the llvm tree, if it exists.
12251231
COMPILER_RT_SOURCE_DIR="${LLVM_SOURCE_DIR}/projects/compiler-rt"
12261232
if [ -e "${WORKSPACE}/compiler-rt" ] ; then
@@ -1229,7 +1235,16 @@ if [ -e "${WORKSPACE}/compiler-rt" ] ; then
12291235
fi
12301236
fi
12311237

1238+
# Build libcxx, unless it doesn't exist.
1239+
LIBCXX_SOURCE_DIR="${WORKSPACE}/libcxx"
1240+
if [[ ! -e "${LIBCXX_SOURCE_DIR}" ]] ; then
1241+
SKIP_BUILD_LIBCXX=1
1242+
fi
1243+
12321244
PRODUCTS=(cmark llvm)
1245+
if [[ ! "${SKIP_BUILD_LIBCXX}" ]] ; then
1246+
PRODUCTS=("${PRODUCTS[@]}" libcxx)
1247+
fi
12331248
if [[ ! "${SKIP_BUILD_LIBICU}" ]] ; then
12341249
PRODUCTS=("${PRODUCTS[@]}" libicu)
12351250
fi
@@ -1575,6 +1590,10 @@ function build_directory_bin() {
15751590
llvm)
15761591
echo "${root}/${LLVM_BUILD_TYPE}/bin"
15771592
;;
1593+
libcxx)
1594+
# Reuse LLVM's build type.
1595+
echo "${root}/${LLVM_BUILD_TYPE}/bin"
1596+
;;
15781597
swift)
15791598
echo "${root}/${SWIFT_BUILD_TYPE}/bin"
15801599
;;
@@ -1722,6 +1741,10 @@ function cmake_config_opt() {
17221741
llvm)
17231742
echo "--config ${LLVM_BUILD_TYPE}"
17241743
;;
1744+
libcxx)
1745+
# Reuse LLVM's build type.
1746+
echo "--config ${LLVM_BUILD_TYPE}"
1747+
;;
17251748
swift)
17261749
echo "--config ${SWIFT_BUILD_TYPE}"
17271750
;;
@@ -2165,6 +2188,12 @@ for host in "${ALL_HOSTS[@]}"; do
21652188
"${llvm_cmake_options[@]}"
21662189
)
21672190

2191+
if [[ ! -z "${CLANG_TOOLS_EXTRA_SOURCE_DIR}" ]] ; then
2192+
cmake_options+=(
2193+
-DLLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR="${CLANG_TOOLS_EXTRA_SOURCE_DIR}"
2194+
)
2195+
fi
2196+
21682197
if [[ "${BUILD_TOOLCHAIN_ONLY}" ]]; then
21692198
cmake_options+=(
21702199
-DLLVM_BUILD_TOOLS=NO
@@ -2204,6 +2233,22 @@ for host in "${ALL_HOSTS[@]}"; do
22042233

22052234
;;
22062235

2236+
libcxx)
2237+
build_targets=(cxx-headers)
2238+
cmake_options=(
2239+
"${cmake_options[@]}"
2240+
-DCMAKE_C_FLAGS="$(llvm_c_flags ${host})"
2241+
-DCMAKE_CXX_FLAGS="$(llvm_c_flags ${host})"
2242+
-DCMAKE_C_FLAGS_RELWITHDEBINFO="-O2 -DNDEBUG"
2243+
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -DNDEBUG"
2244+
-DCMAKE_BUILD_TYPE:STRING="${LLVM_BUILD_TYPE}"
2245+
-DLLVM_INCLUDE_DOCS:BOOL=TRUE
2246+
-DLLVM_CONFIG_PATH="$(build_directory "${LOCAL_HOST}" llvm)/bin/llvm-config"
2247+
"${llvm_cmake_options[@]}"
2248+
)
2249+
2250+
;;
2251+
22072252
swift)
22082253

22092254
if [[ ! "${SKIP_BUILD_ANDROID}" ]]; then
@@ -2980,6 +3025,9 @@ for host in "${ALL_HOSTS[@]}"; do
29803025
llvm)
29813026
continue # We don't test LLVM
29823027
;;
3028+
libcxx)
3029+
continue # We don't test libc++
3030+
;;
29833031
swift)
29843032
executable_target=
29853033
results_targets=
@@ -3476,6 +3524,9 @@ for host in "${ALL_HOSTS[@]}"; do
34763524
fi
34773525
INSTALL_TARGETS=install-$(echo ${LLVM_INSTALL_COMPONENTS} | sed -E 's/;/ install-/g')
34783526
;;
3527+
libcxx)
3528+
INSTALL_TARGETS=install-cxx-headers
3529+
;;
34793530
swift)
34803531
if [[ -z "${INSTALL_SWIFT}" ]] ; then
34813532
continue

0 commit comments

Comments
 (0)