build-script: Build lldb with CMake on Darwin

build-script can already build lldb on Darwin using its Xcode project,
but it's useful to support the CMake build as well.

The CMake build allows incremental rebuilds with build-script. I expect
this to significantly cut down on iteration time.

Taking advantage of CMake also lets lldb piggyback on existing support
for sanitizers -- or exciting new build configurations we don't know
about yet -- without having to update the Xcode project file.

rdar://problem/36751944
This commit is contained in:
Vedant Kumar
2018-01-22 16:31:21 -08:00
parent cc783dc45a
commit 330e47d869
4 changed files with 50 additions and 12 deletions

View File

@@ -477,6 +477,7 @@ class BuildScriptInvocation(object):
"--swift-build-type", args.swift_build_variant, "--swift-build-type", args.swift_build_variant,
"--swift-stdlib-build-type", args.swift_stdlib_build_variant, "--swift-stdlib-build-type", args.swift_stdlib_build_variant,
"--lldb-build-type", args.lldb_build_variant, "--lldb-build-type", args.lldb_build_variant,
"--lldb-build-with-xcode", args.lldb_build_with_xcode,
"--foundation-build-type", args.foundation_build_variant, "--foundation-build-type", args.foundation_build_variant,
"--libdispatch-build-type", args.libdispatch_build_variant, "--libdispatch-build-type", args.libdispatch_build_variant,
"--libicu-build-type", args.libicu_build_variant, "--libicu-build-type", args.libicu_build_variant,

View File

@@ -73,6 +73,7 @@ KNOWN_SETTINGS=(
swift-stdlib-enable-resilience "0" "build the Swift stdlib and overlays with resilience enabled" swift-stdlib-enable-resilience "0" "build the Swift stdlib and overlays with resilience enabled"
swift-stdlib-use-nonatomic-rc "0" "build the Swift stdlib and overlays with nonatomic reference count operations enabled" swift-stdlib-use-nonatomic-rc "0" "build the Swift stdlib and overlays with nonatomic reference count operations enabled"
lldb-build-type "Debug" "the CMake build variant for LLDB" lldb-build-type "Debug" "the CMake build variant for LLDB"
lldb-build-with-xcode "1" "Use xcodebuild to build LLDB, instead of CMake"
llbuild-build-type "Debug" "the CMake build variant for llbuild" llbuild-build-type "Debug" "the CMake build variant for llbuild"
foundation-build-type "Debug" "the build variant for Foundation" foundation-build-type "Debug" "the build variant for Foundation"
libdispatch-build-type "Debug" "the build variant for libdispatch" libdispatch-build-type "Debug" "the build variant for libdispatch"
@@ -2405,12 +2406,32 @@ for host in "${ALL_HOSTS[@]}"; do
) )
;; ;;
macosx-*) macosx-*)
# Set up flags to pass to xcodebuild if [[ "$(true_false ${LLDB_BUILD_WITH_XCODE})" == "TRUE" ]] ; then
set_lldb_xcodebuild_options # Set up flags to pass to xcodebuild
set_lldb_build_mode set_lldb_xcodebuild_options
with_pushd ${source_dir} \ set_lldb_build_mode
call xcodebuild -target desktop -configuration ${LLDB_BUILD_MODE} ${lldb_xcodebuild_options[@]} with_pushd ${source_dir} \
continue call xcodebuild -target desktop -configuration ${LLDB_BUILD_MODE} ${lldb_xcodebuild_options[@]}
continue
else
cmake_options=(
"${cmake_options[@]}"
-DCMAKE_BUILD_TYPE:STRING="${LLDB_BUILD_TYPE}"
-DLLDB_SWIFTC:PATH="$(build_directory ${LOCAL_HOST} swift)/bin/swiftc"
-DCMAKE_INSTALL_PREFIX:PATH="$(get_host_install_prefix ${host})"
-DLLDB_PATH_TO_LLVM_SOURCE:PATH="${LLVM_SOURCE_DIR}"
-DLLDB_PATH_TO_CLANG_SOURCE:PATH="${CLANG_SOURCE_DIR}"
-DLLDB_PATH_TO_SWIFT_SOURCE:PATH="${SWIFT_SOURCE_DIR}"
-DLLDB_PATH_TO_LLVM_BUILD:PATH="${llvm_build_dir}"
-DLLDB_PATH_TO_CLANG_BUILD:PATH="${llvm_build_dir}"
-DLLDB_PATH_TO_SWIFT_BUILD:PATH="${swift_build_dir}"
-DLLDB_PATH_TO_CMARK_BUILD:PATH="${cmark_build_dir}"
-DLLDB_IS_BUILDBOT_BUILD="${LLDB_IS_BUILDBOT_BUILD}"
-DLLDB_BUILD_DATE:STRING="\"${LLDB_BUILD_DATE}\""
-DLLDB_ALLOW_STATIC_BINDINGS=1
-DLLDB_CODESIGN_IDENTITY=""
)
fi
;; ;;
esac esac
;; ;;
@@ -2799,7 +2820,7 @@ for host in "${ALL_HOSTS[@]}"; do
lldb_build_dir=$(build_directory ${host} lldb) lldb_build_dir=$(build_directory ${host} lldb)
# Run the gtests. # Run the gtests.
if [[ "$(uname -s)" == "Darwin" ]] ; then if [[ "$(uname -s)" == "Darwin" && "$(true_false ${LLDB_BUILD_WITH_XCODE})" == "TRUE" ]] ; then
set_lldb_xcodebuild_options set_lldb_xcodebuild_options
# Run the LLDB unittests (gtests). # Run the LLDB unittests (gtests).
with_pushd ${LLDB_SOURCE_DIR} \ with_pushd ${LLDB_SOURCE_DIR} \
@@ -2810,14 +2831,13 @@ for host in "${ALL_HOSTS[@]}"; do
exit 1 exit 1
fi fi
else else
# FIXME run the gtests on other platforms. with_pushd ${lldb_build_dir} \
# There should be a CMake target for this already. ninja check-lldb-unit
echo Run LLDB gtests here.
fi fi
swift_build_dir=$(build_directory ${host} swift) swift_build_dir=$(build_directory ${host} swift)
# Setup lldb executable path # Setup lldb executable path
if [[ "$(uname -s)" == "Darwin" ]] ; then if [[ "$(uname -s)" == "Darwin" && "$(true_false ${LLDB_BUILD_WITH_XCODE})" == "TRUE" ]] ; then
lldb_executable="${lldb_build_dir}"/${LLDB_BUILD_MODE}/lldb lldb_executable="${lldb_build_dir}"/${LLDB_BUILD_MODE}/lldb
else else
lldb_executable="${lldb_build_dir}"/bin/lldb lldb_executable="${lldb_build_dir}"/bin/lldb

View File

@@ -53,7 +53,8 @@ def _apply_default_arguments(args):
# Build LLDB if any LLDB-related options were specified. # Build LLDB if any LLDB-related options were specified.
if args.lldb_build_variant is not None or \ if args.lldb_build_variant is not None or \
args.lldb_assertions is not None: args.lldb_assertions is not None or \
args.lldb_build_with_xcode is not None:
args.build_lldb = True args.build_lldb = True
# Set the default build variant. # Set the default build variant.
@@ -75,6 +76,9 @@ def _apply_default_arguments(args):
if args.lldb_build_variant is None: if args.lldb_build_variant is None:
args.lldb_build_variant = args.build_variant args.lldb_build_variant = args.build_variant
if args.lldb_build_with_xcode is None:
args.lldb_build_with_xcode = '1'
if args.foundation_build_variant is None: if args.foundation_build_variant is None:
args.foundation_build_variant = args.build_variant args.foundation_build_variant = args.build_variant
@@ -568,6 +572,14 @@ def create_argument_parser():
const='Debug', const='Debug',
help='build the Debug variant of LLDB') help='build the Debug variant of LLDB')
option('--lldb-build-with-xcode', store('lldb_build_with_xcode'),
const='1',
help='build LLDB using xcodebuild, if possible')
option('--lldb-build-with-cmake', store('lldb_build_with_xcode'),
const='0',
help='build LLDB using CMake')
option('--debug-cmark', store('cmark_build_variant'), option('--debug-cmark', store('cmark_build_variant'),
const='Debug', const='Debug',
help='build the Debug variant of CommonMark') help='build the Debug variant of CommonMark')

View File

@@ -139,6 +139,7 @@ EXPECTED_DEFAULTS = {
'lit_args': '-sv', 'lit_args': '-sv',
'lldb_assertions': None, 'lldb_assertions': None,
'lldb_build_variant': 'Debug', 'lldb_build_variant': 'Debug',
'lldb_build_with_xcode': '1',
'llvm_assertions': True, 'llvm_assertions': True,
'llvm_build_variant': 'Debug', 'llvm_build_variant': 'Debug',
'llvm_max_parallel_lto_link_jobs': 'llvm_max_parallel_lto_link_jobs':
@@ -330,6 +331,10 @@ EXPECTED_OPTIONS = [
dest='libdispatch_build_variant', value='Debug'), dest='libdispatch_build_variant', value='Debug'),
SetOption('--debug-libicu', dest='libicu_build_variant', value='Debug'), SetOption('--debug-libicu', dest='libicu_build_variant', value='Debug'),
SetOption('--debug-lldb', dest='lldb_build_variant', value='Debug'), SetOption('--debug-lldb', dest='lldb_build_variant', value='Debug'),
SetOption('--lldb-build-with-xcode', dest='lldb_build_with_xcode',
value='1'),
SetOption('--lldb-build-with-cmake', dest='lldb_build_with_xcode',
value='0'),
SetOption('--debug-llvm', dest='llvm_build_variant', value='Debug'), SetOption('--debug-llvm', dest='llvm_build_variant', value='Debug'),
SetOption('--debug-swift', dest='swift_build_variant', value='Debug'), SetOption('--debug-swift', dest='swift_build_variant', value='Debug'),
SetOption('--debug-swift-stdlib', SetOption('--debug-swift-stdlib',