Skip to content

[5.0] Build and install 'clang' and 'clangd' in the macOS & linux toolchains #22273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ llbuild
swiftpm
xctest
libicu
libcxx

dash-dash

Expand All @@ -728,8 +729,9 @@ install-swiftpm
install-xctest
install-libicu
install-prefix=/usr
swift-install-components=autolink-driver;compiler;clang-builtin-headers;stdlib;swift-remote-mirror;sdk-overlay;license;sourcekit-inproc
llvm-install-components=llvm-cov;llvm-profdata;IndexStore
swift-install-components=autolink-driver;compiler;clang-resource-dir-symlink;stdlib;swift-remote-mirror;sdk-overlay;license;sourcekit-inproc
llvm-install-components=llvm-cov;llvm-profdata;IndexStore;clang;clang-headers;compiler-rt
install-libcxx
build-swift-static-stdlib
build-swift-static-sdk-overlay
build-swift-stdlib-unittest-extra
Expand Down
4 changes: 4 additions & 0 deletions utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ class BuildScriptInvocation(object):
impl_args += ["--skip-build-lldb"]
if not args.build_llbuild:
impl_args += ["--skip-build-llbuild"]
if not args.build_libcxx:
impl_args += ["--skip-build-libcxx"]
if not args.build_libdispatch:
impl_args += ["--skip-build-libdispatch"]
if not args.build_libicu:
Expand Down Expand Up @@ -823,6 +825,8 @@ class BuildScriptInvocation(object):
product_classes = []
product_classes.append(products.CMark)
product_classes.append(products.LLVM)
if self.args.build_libcxx:
product_classes.append(products.LibCXX)
if self.args.build_libicu:
product_classes.append(products.LibICU)
product_classes.append(products.Swift)
Expand Down
52 changes: 52 additions & 0 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ KNOWN_SETTINGS=(
skip-build-android "" "set to skip building Swift stdlibs for Android"
skip-build-lldb "" "set to skip building LLDB"
skip-build-llbuild "" "set to skip building llbuild"
skip-build-libcxx "" "set to skip building libcxx"
skip-build-swiftpm "" "set to skip building swiftpm"
skip-build-swiftsyntax "" "set to skip building swiftSyntax"
skip-build-skstresstester "" "set to skip building the SourceKit stress tester"
Expand Down Expand Up @@ -199,6 +200,7 @@ KNOWN_SETTINGS=(
install-skstresstester "" "whether to install the SourceKit stress tester"
install-xctest "" "whether to install xctest"
install-foundation "" "whether to install foundation"
install-libcxx "" "whether to install libc++"
install-libdispatch "" "whether to install libdispatch"
install-libicu "" "whether to install libicu"
install-playgroundsupport "" "whether to install PlaygroundSupport"
Expand Down Expand Up @@ -255,6 +257,7 @@ KNOWN_SETTINGS=(
swiftpm-cmake-options "" "CMake options used for all swiftpm targets"
xctest-cmake-options "" "CMake options used for all xctest targets"
playgroundsupport-cmake-options "" "CMake options used for all playgroundsupport targets"
libcxx-cmake-options "" "CMake options used for all libcxx targets"
# TODO: Remove this some time later.
user-config-args "" "**Renamed to --extra-cmake-options**: User-supplied arguments to cmake when used to do configuration."
only-execute "all" "Only execute the named action (see implementation)"
Expand Down Expand Up @@ -1180,6 +1183,7 @@ XCTEST_SOURCE_DIR="${WORKSPACE}/swift-corelibs-xctest"
FOUNDATION_SOURCE_DIR="${WORKSPACE}/swift-corelibs-foundation"
LIBDISPATCH_SOURCE_DIR="${WORKSPACE}/swift-corelibs-libdispatch"
LIBICU_SOURCE_DIR="${WORKSPACE}/icu"
LIBCXX_SOURCE_DIR="${WORKSPACE}/libcxx"
PLAYGROUNDSUPPORT_SOURCE_DIR="${WORKSPACE}/swift-xcode-playground-support"

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

# Don't symlink clang-tools-extra into the tree as the 'clang' symlink prevents
# make_relative_symlink from working correctly.
if [ -e "${WORKSPACE}/clang-tools-extra" ] ; then
CLANG_TOOLS_EXTRA_SOURCE_DIR="${WORKSPACE}/clang-tools-extra"
fi

# Symlink compiler-rt into the llvm tree, if it exists.
COMPILER_RT_SOURCE_DIR="${LLVM_SOURCE_DIR}/projects/compiler-rt"
if [ -e "${WORKSPACE}/compiler-rt" ] ; then
Expand All @@ -1209,6 +1219,9 @@ if [ -e "${WORKSPACE}/compiler-rt" ] ; then
fi

PRODUCTS=(cmark llvm)
if [[ ! "${SKIP_BUILD_LIBCXX}" ]] ; then
PRODUCTS=("${PRODUCTS[@]}" libcxx)
fi
if [[ ! "${SKIP_BUILD_LIBICU}" ]] ; then
PRODUCTS=("${PRODUCTS[@]}" libicu)
fi
Expand Down Expand Up @@ -1545,6 +1558,10 @@ function build_directory_bin() {
llvm)
echo "${root}/${LLVM_BUILD_TYPE}/bin"
;;
libcxx)
# Reuse LLVM's build type.
echo "${root}/${LLVM_BUILD_TYPE}/bin"
;;
swift)
echo "${root}/${SWIFT_BUILD_TYPE}/bin"
;;
Expand Down Expand Up @@ -1687,6 +1704,10 @@ function cmake_config_opt() {
llvm)
echo "--config ${LLVM_BUILD_TYPE}"
;;
libcxx)
# Reuse LLVM's build type.
echo "--config ${LLVM_BUILD_TYPE}"
;;
swift)
echo "--config ${SWIFT_BUILD_TYPE}"
;;
Expand Down Expand Up @@ -2097,6 +2118,12 @@ for host in "${ALL_HOSTS[@]}"; do
"${llvm_cmake_options[@]}"
)

if [[ ! -z "${CLANG_TOOLS_EXTRA_SOURCE_DIR}" ]] ; then
cmake_options+=(
-DLLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR="${CLANG_TOOLS_EXTRA_SOURCE_DIR}"
)
fi

if [[ "${BUILD_TOOLCHAIN_ONLY}" ]]; then
cmake_options+=(
-DLLVM_BUILD_TOOLS=NO
Expand Down Expand Up @@ -2136,6 +2163,22 @@ for host in "${ALL_HOSTS[@]}"; do

;;

libcxx)
build_targets=(cxx-headers)
cmake_options=(
"${cmake_options[@]}"
-DCMAKE_C_FLAGS="$(llvm_c_flags ${host})"
-DCMAKE_CXX_FLAGS="$(llvm_c_flags ${host})"
-DCMAKE_C_FLAGS_RELWITHDEBINFO="-O2 -DNDEBUG"
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -DNDEBUG"
-DCMAKE_BUILD_TYPE:STRING="${LLVM_BUILD_TYPE}"
-DLLVM_INCLUDE_DOCS:BOOL=TRUE
-DLLVM_CONFIG_PATH="$(build_directory "${LOCAL_HOST}" llvm)/bin/llvm-config"
"${llvm_cmake_options[@]}"
)

;;

swift)

if [[ ! "${SKIP_BUILD_ANDROID}" ]]; then
Expand Down Expand Up @@ -2934,6 +2977,9 @@ for host in "${ALL_HOSTS[@]}"; do
llvm)
continue # We don't test LLVM
;;
libcxx)
continue # We don't test libc++
;;
swift)
executable_target=
results_targets=
Expand Down Expand Up @@ -3397,6 +3443,12 @@ for host in "${ALL_HOSTS[@]}"; do
fi
INSTALL_TARGETS=install-$(echo ${LLVM_INSTALL_COMPONENTS} | sed -E 's/;/ install-/g')
;;
libcxx)
if [[ -z "${INSTALL_LIBCXX}" ]] ; then
continue
fi
INSTALL_TARGETS=install-cxx-headers
;;
swift)
if [[ -z "${INSTALL_SWIFT}" ]] ; then
continue
Expand Down
4 changes: 4 additions & 0 deletions utils/build_swift/driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def _apply_default_arguments(args):
args.build_external_benchmarks = False
args.build_lldb = False
args.build_llbuild = False
args.build_libcxx = False
args.build_swiftpm = False
args.build_xctest = False
args.build_foundation = False
Expand Down Expand Up @@ -512,6 +513,9 @@ def create_argument_parser():
option(['-b', '--llbuild'], store_true('build_llbuild'),
help='build llbuild')

option(['--libcxx'], store_true('build_libcxx'),
help='build libcxx')

option(['-p', '--swiftpm'], store_true('build_swiftpm'),
help='build swiftpm')

Expand Down
2 changes: 2 additions & 0 deletions utils/build_swift/tests/expected_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
'build_linux': True,
'build_llbuild': False,
'build_lldb': False,
'build_libcxx': False,
'build_ninja': False,
'build_osx': True,
'build_playgroundsupport': False,
Expand Down Expand Up @@ -393,6 +394,7 @@ class IgnoreOption(_BaseOption):
SetTrueOption('--ios'),
SetTrueOption('--llbuild', dest='build_llbuild'),
SetTrueOption('--lldb', dest='build_lldb'),
SetTrueOption('--libcxx', dest='build_libcxx'),
SetTrueOption('--playgroundsupport', dest='build_playgroundsupport'),
SetTrueOption('--skip-build'),
SetTrueOption('--swiftpm', dest='build_swiftpm'),
Expand Down
1 change: 1 addition & 0 deletions utils/build_swift/tests/test_driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ def test_implied_defaults_skip_build(self):
self.assertFalse(namespace.build_libicu)
self.assertFalse(namespace.build_lldb)
self.assertFalse(namespace.build_llbuild)
self.assertFalse(namespace.build_libcxx)
self.assertFalse(namespace.build_playgroundsupport)
self.assertFalse(namespace.build_swiftpm)
self.assertFalse(namespace.build_xctest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from .cmark import CMark
from .foundation import Foundation
from .libcxx import LibCXX
from .libdispatch import LibDispatch
from .libicu import LibICU
from .llbuild import LLBuild
Expand All @@ -26,6 +27,7 @@
'CMark',
'Ninja',
'Foundation',
'LibCXX',
'LibDispatch',
'LibICU',
'LLBuild',
Expand Down
17 changes: 17 additions & 0 deletions utils/swift_build_support/swift_build_support/products/libcxx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# swift_build_support/products/libcxx.py -------------------------*- python -*-
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ----------------------------------------------------------------------------

from . import product


class LibCXX(product.Product):
pass