Skip to content

Commit 624112d

Browse files
authored
Merge pull request #22273 from hyp/buildInstallClangAndClangd-swift5.0
[5.0] Build and install 'clang' and 'clangd' in the macOS & linux toolchains
2 parents 5834830 + c221dd6 commit 624112d

File tree

8 files changed

+86
-2
lines changed

8 files changed

+86
-2
lines changed

utils/build-presets.ini

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ llbuild
717717
swiftpm
718718
xctest
719719
libicu
720+
libcxx
720721

721722
dash-dash
722723

@@ -728,8 +729,9 @@ install-swiftpm
728729
install-xctest
729730
install-libicu
730731
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
732+
swift-install-components=autolink-driver;compiler;clang-resource-dir-symlink;stdlib;swift-remote-mirror;sdk-overlay;license;sourcekit-inproc
733+
llvm-install-components=llvm-cov;llvm-profdata;IndexStore;clang;clang-headers;compiler-rt
734+
install-libcxx
733735
build-swift-static-stdlib
734736
build-swift-static-sdk-overlay
735737
build-swift-stdlib-unittest-extra

utils/build-script

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ class BuildScriptInvocation(object):
586586
impl_args += ["--skip-build-lldb"]
587587
if not args.build_llbuild:
588588
impl_args += ["--skip-build-llbuild"]
589+
if not args.build_libcxx:
590+
impl_args += ["--skip-build-libcxx"]
589591
if not args.build_libdispatch:
590592
impl_args += ["--skip-build-libdispatch"]
591593
if not args.build_libicu:
@@ -823,6 +825,8 @@ class BuildScriptInvocation(object):
823825
product_classes = []
824826
product_classes.append(products.CMark)
825827
product_classes.append(products.LLVM)
828+
if self.args.build_libcxx:
829+
product_classes.append(products.LibCXX)
826830
if self.args.build_libicu:
827831
product_classes.append(products.LibICU)
828832
product_classes.append(products.Swift)

utils/build-script-impl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ KNOWN_SETTINGS=(
123123
skip-build-android "" "set to skip building Swift stdlibs for Android"
124124
skip-build-lldb "" "set to skip building LLDB"
125125
skip-build-llbuild "" "set to skip building llbuild"
126+
skip-build-libcxx "" "set to skip building libcxx"
126127
skip-build-swiftpm "" "set to skip building swiftpm"
127128
skip-build-swiftsyntax "" "set to skip building swiftSyntax"
128129
skip-build-skstresstester "" "set to skip building the SourceKit stress tester"
@@ -199,6 +200,7 @@ KNOWN_SETTINGS=(
199200
install-skstresstester "" "whether to install the SourceKit stress tester"
200201
install-xctest "" "whether to install xctest"
201202
install-foundation "" "whether to install foundation"
203+
install-libcxx "" "whether to install libc++"
202204
install-libdispatch "" "whether to install libdispatch"
203205
install-libicu "" "whether to install libicu"
204206
install-playgroundsupport "" "whether to install PlaygroundSupport"
@@ -255,6 +257,7 @@ KNOWN_SETTINGS=(
255257
swiftpm-cmake-options "" "CMake options used for all swiftpm targets"
256258
xctest-cmake-options "" "CMake options used for all xctest targets"
257259
playgroundsupport-cmake-options "" "CMake options used for all playgroundsupport targets"
260+
libcxx-cmake-options "" "CMake options used for all libcxx targets"
258261
# TODO: Remove this some time later.
259262
user-config-args "" "**Renamed to --extra-cmake-options**: User-supplied arguments to cmake when used to do configuration."
260263
only-execute "all" "Only execute the named action (see implementation)"
@@ -1180,6 +1183,7 @@ XCTEST_SOURCE_DIR="${WORKSPACE}/swift-corelibs-xctest"
11801183
FOUNDATION_SOURCE_DIR="${WORKSPACE}/swift-corelibs-foundation"
11811184
LIBDISPATCH_SOURCE_DIR="${WORKSPACE}/swift-corelibs-libdispatch"
11821185
LIBICU_SOURCE_DIR="${WORKSPACE}/icu"
1186+
LIBCXX_SOURCE_DIR="${WORKSPACE}/libcxx"
11831187
PLAYGROUNDSUPPORT_SOURCE_DIR="${WORKSPACE}/swift-xcode-playground-support"
11841188

11851189
if [[ ! "${SKIP_BUILD_PLAYGROUNDSUPPORT}" && ! -d ${PLAYGROUNDSUPPORT_SOURCE_DIR} ]]; then
@@ -1200,6 +1204,12 @@ if [ ! -d "${CLANG_SOURCE_DIR}" ] ; then
12001204
make_relative_symlink "${WORKSPACE}/clang" "${CLANG_SOURCE_DIR}"
12011205
fi
12021206

1207+
# Don't symlink clang-tools-extra into the tree as the 'clang' symlink prevents
1208+
# make_relative_symlink from working correctly.
1209+
if [ -e "${WORKSPACE}/clang-tools-extra" ] ; then
1210+
CLANG_TOOLS_EXTRA_SOURCE_DIR="${WORKSPACE}/clang-tools-extra"
1211+
fi
1212+
12031213
# Symlink compiler-rt into the llvm tree, if it exists.
12041214
COMPILER_RT_SOURCE_DIR="${LLVM_SOURCE_DIR}/projects/compiler-rt"
12051215
if [ -e "${WORKSPACE}/compiler-rt" ] ; then
@@ -1209,6 +1219,9 @@ if [ -e "${WORKSPACE}/compiler-rt" ] ; then
12091219
fi
12101220

12111221
PRODUCTS=(cmark llvm)
1222+
if [[ ! "${SKIP_BUILD_LIBCXX}" ]] ; then
1223+
PRODUCTS=("${PRODUCTS[@]}" libcxx)
1224+
fi
12121225
if [[ ! "${SKIP_BUILD_LIBICU}" ]] ; then
12131226
PRODUCTS=("${PRODUCTS[@]}" libicu)
12141227
fi
@@ -1545,6 +1558,10 @@ function build_directory_bin() {
15451558
llvm)
15461559
echo "${root}/${LLVM_BUILD_TYPE}/bin"
15471560
;;
1561+
libcxx)
1562+
# Reuse LLVM's build type.
1563+
echo "${root}/${LLVM_BUILD_TYPE}/bin"
1564+
;;
15481565
swift)
15491566
echo "${root}/${SWIFT_BUILD_TYPE}/bin"
15501567
;;
@@ -1687,6 +1704,10 @@ function cmake_config_opt() {
16871704
llvm)
16881705
echo "--config ${LLVM_BUILD_TYPE}"
16891706
;;
1707+
libcxx)
1708+
# Reuse LLVM's build type.
1709+
echo "--config ${LLVM_BUILD_TYPE}"
1710+
;;
16901711
swift)
16911712
echo "--config ${SWIFT_BUILD_TYPE}"
16921713
;;
@@ -2097,6 +2118,12 @@ for host in "${ALL_HOSTS[@]}"; do
20972118
"${llvm_cmake_options[@]}"
20982119
)
20992120

2121+
if [[ ! -z "${CLANG_TOOLS_EXTRA_SOURCE_DIR}" ]] ; then
2122+
cmake_options+=(
2123+
-DLLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR="${CLANG_TOOLS_EXTRA_SOURCE_DIR}"
2124+
)
2125+
fi
2126+
21002127
if [[ "${BUILD_TOOLCHAIN_ONLY}" ]]; then
21012128
cmake_options+=(
21022129
-DLLVM_BUILD_TOOLS=NO
@@ -2136,6 +2163,22 @@ for host in "${ALL_HOSTS[@]}"; do
21362163

21372164
;;
21382165

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

21412184
if [[ ! "${SKIP_BUILD_ANDROID}" ]]; then
@@ -2934,6 +2977,9 @@ for host in "${ALL_HOSTS[@]}"; do
29342977
llvm)
29352978
continue # We don't test LLVM
29362979
;;
2980+
libcxx)
2981+
continue # We don't test libc++
2982+
;;
29372983
swift)
29382984
executable_target=
29392985
results_targets=
@@ -3397,6 +3443,12 @@ for host in "${ALL_HOSTS[@]}"; do
33973443
fi
33983444
INSTALL_TARGETS=install-$(echo ${LLVM_INSTALL_COMPONENTS} | sed -E 's/;/ install-/g')
33993445
;;
3446+
libcxx)
3447+
if [[ -z "${INSTALL_LIBCXX}" ]] ; then
3448+
continue
3449+
fi
3450+
INSTALL_TARGETS=install-cxx-headers
3451+
;;
34003452
swift)
34013453
if [[ -z "${INSTALL_SWIFT}" ]] ; then
34023454
continue

utils/build_swift/driver_arguments.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def _apply_default_arguments(args):
142142
args.build_external_benchmarks = False
143143
args.build_lldb = False
144144
args.build_llbuild = False
145+
args.build_libcxx = False
145146
args.build_swiftpm = False
146147
args.build_xctest = False
147148
args.build_foundation = False
@@ -512,6 +513,9 @@ def create_argument_parser():
512513
option(['-b', '--llbuild'], store_true('build_llbuild'),
513514
help='build llbuild')
514515

516+
option(['--libcxx'], store_true('build_libcxx'),
517+
help='build libcxx')
518+
515519
option(['-p', '--swiftpm'], store_true('build_swiftpm'),
516520
help='build swiftpm')
517521

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
'build_linux': True,
6868
'build_llbuild': False,
6969
'build_lldb': False,
70+
'build_libcxx': False,
7071
'build_ninja': False,
7172
'build_osx': True,
7273
'build_playgroundsupport': False,
@@ -393,6 +394,7 @@ class IgnoreOption(_BaseOption):
393394
SetTrueOption('--ios'),
394395
SetTrueOption('--llbuild', dest='build_llbuild'),
395396
SetTrueOption('--lldb', dest='build_lldb'),
397+
SetTrueOption('--libcxx', dest='build_libcxx'),
396398
SetTrueOption('--playgroundsupport', dest='build_playgroundsupport'),
397399
SetTrueOption('--skip-build'),
398400
SetTrueOption('--swiftpm', dest='build_swiftpm'),

utils/build_swift/tests/test_driver_arguments.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ def test_implied_defaults_skip_build(self):
590590
self.assertFalse(namespace.build_libicu)
591591
self.assertFalse(namespace.build_lldb)
592592
self.assertFalse(namespace.build_llbuild)
593+
self.assertFalse(namespace.build_libcxx)
593594
self.assertFalse(namespace.build_playgroundsupport)
594595
self.assertFalse(namespace.build_swiftpm)
595596
self.assertFalse(namespace.build_xctest)

utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from .cmark import CMark
1414
from .foundation import Foundation
15+
from .libcxx import LibCXX
1516
from .libdispatch import LibDispatch
1617
from .libicu import LibICU
1718
from .llbuild import LLBuild
@@ -26,6 +27,7 @@
2627
'CMark',
2728
'Ninja',
2829
'Foundation',
30+
'LibCXX',
2931
'LibDispatch',
3032
'LibICU',
3133
'LLBuild',
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# swift_build_support/products/libcxx.py -------------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
from . import product
14+
15+
16+
class LibCXX(product.Product):
17+
pass

0 commit comments

Comments
 (0)