Skip to content

Commit 76e66e9

Browse files
committed
Build and install 'clang' in the linux toolchains
- Build script now builds clang_tools_extra as part of LLVM's build. - Build script now has a new libc++ build step to allow libc++ headers to be installed in the resulting toolchain. - 'clang', 'clang-headers' & 'compiler-rt' targets are now installed for the package build configurations for linux. - 'clang-resource-dir-symlink' is used in the package build configuration for linux to avoid duplication of Clang's headers and compiler-rt archives. rdar://24912710 (cherry picked from commit 1941aaa)
1 parent bdf70d1 commit 76e66e9

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

utils/build-presets.ini

Lines changed: 2 additions & 2 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;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;license;sourcekit-inproc
732+
llvm-install-components=llvm-cov;llvm-profdata;IndexStore;clang;clang-headers;compiler-rt
733733
build-swift-static-stdlib
734734
build-swift-static-sdk-overlay
735735
build-swift-stdlib-unittest-extra

utils/build-script-impl

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

1203+
# Don't symlink clang-tools-extra into the tree as the 'clang' symlink prevents
1204+
# make_relative_symlink from working correctly.
1205+
if [ -e "${WORKSPACE}/clang-tools-extra" ] ; then
1206+
CLANG_TOOLS_EXTRA_SOURCE_DIR="${WORKSPACE}/clang-tools-extra"
1207+
fi
1208+
12031209
# Symlink compiler-rt into the llvm tree, if it exists.
12041210
COMPILER_RT_SOURCE_DIR="${LLVM_SOURCE_DIR}/projects/compiler-rt"
12051211
if [ -e "${WORKSPACE}/compiler-rt" ] ; then
@@ -1208,7 +1214,16 @@ if [ -e "${WORKSPACE}/compiler-rt" ] ; then
12081214
fi
12091215
fi
12101216

1217+
# Build libcxx, unless it doesn't exist.
1218+
LIBCXX_SOURCE_DIR="${WORKSPACE}/libcxx"
1219+
if [[ ! -e "${LIBCXX_SOURCE_DIR}" ]] ; then
1220+
SKIP_BUILD_LIBCXX=1
1221+
fi
1222+
12111223
PRODUCTS=(cmark llvm)
1224+
if [[ ! "${SKIP_BUILD_LIBCXX}" ]] ; then
1225+
PRODUCTS=("${PRODUCTS[@]}" libcxx)
1226+
fi
12121227
if [[ ! "${SKIP_BUILD_LIBICU}" ]] ; then
12131228
PRODUCTS=("${PRODUCTS[@]}" libicu)
12141229
fi
@@ -1545,6 +1560,10 @@ function build_directory_bin() {
15451560
llvm)
15461561
echo "${root}/${LLVM_BUILD_TYPE}/bin"
15471562
;;
1563+
libcxx)
1564+
# Reuse LLVM's build type.
1565+
echo "${root}/${LLVM_BUILD_TYPE}/bin"
1566+
;;
15481567
swift)
15491568
echo "${root}/${SWIFT_BUILD_TYPE}/bin"
15501569
;;
@@ -1687,6 +1706,10 @@ function cmake_config_opt() {
16871706
llvm)
16881707
echo "--config ${LLVM_BUILD_TYPE}"
16891708
;;
1709+
libcxx)
1710+
# Reuse LLVM's build type.
1711+
echo "--config ${LLVM_BUILD_TYPE}"
1712+
;;
16901713
swift)
16911714
echo "--config ${SWIFT_BUILD_TYPE}"
16921715
;;
@@ -2097,6 +2120,12 @@ for host in "${ALL_HOSTS[@]}"; do
20972120
"${llvm_cmake_options[@]}"
20982121
)
20992122

2123+
if [[ ! -z "${CLANG_TOOLS_EXTRA_SOURCE_DIR}" ]] ; then
2124+
cmake_options+=(
2125+
-DLLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR="${CLANG_TOOLS_EXTRA_SOURCE_DIR}"
2126+
)
2127+
fi
2128+
21002129
if [[ "${BUILD_TOOLCHAIN_ONLY}" ]]; then
21012130
cmake_options+=(
21022131
-DLLVM_BUILD_TOOLS=NO
@@ -2136,6 +2165,22 @@ for host in "${ALL_HOSTS[@]}"; do
21362165

21372166
;;
21382167

2168+
libcxx)
2169+
build_targets=(cxx-headers)
2170+
cmake_options=(
2171+
"${cmake_options[@]}"
2172+
-DCMAKE_C_FLAGS="$(llvm_c_flags ${host})"
2173+
-DCMAKE_CXX_FLAGS="$(llvm_c_flags ${host})"
2174+
-DCMAKE_C_FLAGS_RELWITHDEBINFO="-O2 -DNDEBUG"
2175+
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -DNDEBUG"
2176+
-DCMAKE_BUILD_TYPE:STRING="${LLVM_BUILD_TYPE}"
2177+
-DLLVM_INCLUDE_DOCS:BOOL=TRUE
2178+
-DLLVM_CONFIG_PATH="$(build_directory "${LOCAL_HOST}" llvm)/bin/llvm-config"
2179+
"${llvm_cmake_options[@]}"
2180+
)
2181+
2182+
;;
2183+
21392184
swift)
21402185

21412186
if [[ ! "${SKIP_BUILD_ANDROID}" ]]; then
@@ -2934,6 +2979,9 @@ for host in "${ALL_HOSTS[@]}"; do
29342979
llvm)
29352980
continue # We don't test LLVM
29362981
;;
2982+
libcxx)
2983+
continue # We don't test libc++
2984+
;;
29372985
swift)
29382986
executable_target=
29392987
results_targets=
@@ -3397,6 +3445,9 @@ for host in "${ALL_HOSTS[@]}"; do
33973445
fi
33983446
INSTALL_TARGETS=install-$(echo ${LLVM_INSTALL_COMPONENTS} | sed -E 's/;/ install-/g')
33993447
;;
3448+
libcxx)
3449+
INSTALL_TARGETS=install-cxx-headers
3450+
;;
34003451
swift)
34013452
if [[ -z "${INSTALL_SWIFT}" ]] ; then
34023453
continue

0 commit comments

Comments
 (0)