Skip to content

Commit f63de71

Browse files
authored
Merge pull request #38507 from drexin/wip-llvm-build-script
[Build] Make LLVM a build-script product
2 parents 72e296e + 3f80cb6 commit f63de71

File tree

14 files changed

+792
-49
lines changed

14 files changed

+792
-49
lines changed

utils/build-script

-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ def apply_default_arguments(toolchain, args):
417417
args.extra_cmake_options.append(
418418
'-DSWIFT_DARWIN_MODULE_ARCHS:STRING={}'.format(
419419
args.swift_darwin_module_archs))
420-
421420
if (args.infer_cross_compile_hosts_on_darwin and
422421
platform.system() == "Darwin"):
423422
args.cross_compile_hosts = _infer_cross_compile_hosts_on_darwin(

utils/build_swift/build_swift/driver_arguments.py

+23
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ def create_argument_parser():
519519
option('--clang-profile-instr-use', store_path,
520520
help='profile file to use for clang PGO')
521521

522+
option('--swift-profile-instr-use', store_path,
523+
help='profile file to use for clang PGO while building swift')
524+
522525
option('--llvm-max-parallel-lto-link-jobs', store_int,
523526
default=defaults.LLVM_MAX_PARALLEL_LTO_LINK_JOBS,
524527
metavar='COUNT',
@@ -650,6 +653,9 @@ def create_argument_parser():
650653
option(['--back-deploy-concurrency'], toggle_true('build_backdeployconcurrency'),
651654
help='build back-deployment support for concurrency')
652655

656+
option('--install-llvm', toggle_true,
657+
help='install llvm')
658+
653659
option(['--install-back-deploy-concurrency'],
654660
toggle_true('install_backdeployconcurrency'),
655661
help='install back-deployment support libraries for concurrency')
@@ -762,6 +768,11 @@ def create_argument_parser():
762768
default=True,
763769
help='skip building clang-tools-extra as part of llvm')
764770

771+
option('--skip-build-compiler-rt',
772+
toggle_false('build_compiler_rt'),
773+
default=True,
774+
help='skip building compiler-rt as part of llvm')
775+
765776
# -------------------------------------------------------------------------
766777
in_group('Extra actions to perform before or in addition to building')
767778

@@ -1111,6 +1122,9 @@ def create_argument_parser():
11111122
'This can be useful to reduce build times when e.g. '
11121123
'tests do not need to run')
11131124

1125+
option('--build-toolchain-only', toggle_true,
1126+
help='only build the necessary tools to build an external toolchain')
1127+
11141128
# -------------------------------------------------------------------------
11151129
in_group('Skip testing specified targets')
11161130

@@ -1211,6 +1225,9 @@ def create_argument_parser():
12111225
# -------------------------------------------------------------------------
12121226
in_group('Build settings specific for LLVM')
12131227

1228+
option('--llvm-enable-modules', toggle_true('llvm_enable_modules'),
1229+
help='enable building llvm using modules')
1230+
12141231
option('--llvm-targets-to-build', store,
12151232
default='X86;ARM;AArch64;PowerPC;SystemZ;Mips',
12161233
help='LLVM target generators to build')
@@ -1230,6 +1247,9 @@ def create_argument_parser():
12301247
'Can be called multiple times '
12311248
'to add multiple such options.')
12321249

1250+
option('--no-llvm-include-tests', toggle_false('llvm_include_tests'),
1251+
help='do not generate testing targets for LLVM')
1252+
12331253
# -------------------------------------------------------------------------
12341254
in_group('Build settings for Android')
12351255

@@ -1294,6 +1314,9 @@ def create_argument_parser():
12941314
help='skip building cmark')
12951315
option('--skip-build-llvm', toggle_false('build_llvm'),
12961316
help='skip building llvm')
1317+
option('--build-llvm', toggle_true('_build_llvm'),
1318+
default=True,
1319+
help='build llvm and clang')
12971320
option('--skip-build-swift', toggle_false('build_swift'),
12981321
help='skip building swift')
12991322
option('--skip-build-libxml2', toggle_false('build_libxml2'),

utils/build_swift/tests/expected_options.py

+15
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@
5151
'build_backdeployconcurrency': False,
5252
'build_benchmarks': True,
5353
'build_clang_tools_extra': True,
54+
'build_compiler_rt': True,
5455
'build_cygwin': True,
5556
'build_external_benchmarks': False,
5657
'build_foundation': False,
5758
'build_cmark': True,
5859
'build_swift': True,
5960
'build_llvm': True,
61+
'_build_llvm': True,
6062
'build_freebsd': True,
6163
'build_ios': True,
6264
'build_ios_device': False,
@@ -100,6 +102,7 @@
100102
'test_indexstoredb_sanitize_all': False,
101103
'test_sourcekitlsp_sanitize_all': False,
102104
'build_sourcekitlsp': False,
105+
'install_llvm': False,
103106
'install_swiftpm': False,
104107
'install_swiftsyntax': False,
105108
'install_swift_driver': False,
@@ -111,6 +114,7 @@
111114
'install_skstresstester': False,
112115
'install_swiftevolve': False,
113116
'build_toolchainbenchmarks': False,
117+
'build_toolchain_only': False,
114118
'build_tvos': True,
115119
'build_tvos_device': False,
116120
'build_tvos_simulator': False,
@@ -197,6 +201,8 @@
197201
'lldb_build_with_xcode': '0',
198202
'llvm_assertions': True,
199203
'llvm_build_variant': 'Debug',
204+
'llvm_enable_modules': False,
205+
'llvm_include_tests': True,
200206
'llvm_ninja_targets': [],
201207
'llvm_ninja_targets_for_cross_compile_hosts': [],
202208
'llvm_max_parallel_lto_link_jobs':
@@ -226,6 +232,7 @@
226232
'swift_darwin_module_archs': None,
227233
'swift_darwin_supported_archs': None,
228234
'swift_freestanding_is_darwin': False,
235+
'swift_profile_instr_use': None,
229236
'swift_stdlib_assertions': True,
230237
'swift_stdlib_build_variant': 'Debug',
231238
'swift_tools_ld64_lto_codegen_only_for_supporting_targets': False,
@@ -496,6 +503,8 @@ class BuildScriptImplOption(_BaseOption):
496503
SetOption('--skip-test-early-swift-driver',
497504
dest='test_early_swift_driver', value=False),
498505

506+
SetFalseOption('--no-llvm-include-tests', dest='llvm_include_tests'),
507+
499508
SetTrueOption('--back-deploy-concurrency', dest='build_backdeployconcurrency'),
500509
SetTrueOption('--install-back-deploy-concurrency',
501510
dest='install_backdeployconcurrency'),
@@ -548,6 +557,7 @@ class BuildScriptImplOption(_BaseOption):
548557
EnableOption('--build-swift-static-stdlib'),
549558
EnableOption('--build-swift-stdlib-unittest-extra'),
550559
EnableOption('--build-swift-stdlib-static-print'),
560+
EnableOption('--build-toolchain-only'),
551561
EnableOption('--build-swift-private-stdlib'),
552562
EnableOption('--build-swift-stdlib-unicode-data'),
553563
EnableOption('--cross-compile-append-host-target-to-destdir'),
@@ -579,6 +589,7 @@ class BuildScriptImplOption(_BaseOption):
579589
EnableOption('--sourcekit-lsp', dest='build_sourcekitlsp'),
580590
EnableOption('--test-sourcekit-lsp-sanitize-all',
581591
dest='test_sourcekitlsp_sanitize_all'),
592+
EnableOption('--install-llvm', dest='install_llvm'),
582593
EnableOption('--install-swiftsyntax', dest='install_swiftsyntax'),
583594
EnableOption('--swiftsyntax-verify-generated-files',
584595
dest='swiftsyntax_verify_generated_files'),
@@ -607,6 +618,8 @@ class BuildScriptImplOption(_BaseOption):
607618
EnableOption('--xctest', dest='build_xctest'),
608619
EnableOption('--swift-disable-dead-stripping'),
609620
EnableOption('--clean-early-swift-driver', dest='clean_early_swift_driver'),
621+
EnableOption('--llvm-enable-modules'),
622+
EnableOption('--build-llvm', dest='_build_llvm'),
610623

611624
DisableOption('--skip-build-cmark', dest='build_cmark'),
612625
DisableOption('--skip-build-llvm', dest='build_llvm'),
@@ -679,6 +692,7 @@ class BuildScriptImplOption(_BaseOption):
679692
DisableOption('--skip-build-libxml2', dest='build_libxml2'),
680693
DisableOption('--skip-build-zlib', dest='build_zlib'),
681694
DisableOption('--skip-build-curl', dest='build_curl'),
695+
DisableOption('--skip-build-compiler-rt', dest='build_compiler_rt'),
682696

683697
ChoicesOption('--compiler-vendor',
684698
choices=['none', 'apple']),
@@ -725,6 +739,7 @@ class BuildScriptImplOption(_BaseOption):
725739
PathOption('--symbols-package'),
726740
PathOption('--cmake-c-launcher'),
727741
PathOption('--cmake-cxx-launcher'),
742+
PathOption('--swift-profile-instr-use'),
728743

729744
IntOption('--benchmark-num-o-iterations'),
730745
IntOption('--benchmark-num-onone-iterations'),

utils/swift_build_support/swift_build_support/build_script_invocation.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def compute_host_specific_variables(self):
534534
"SWIFT_TEST_TARGETS": " ".join(
535535
config.swift_test_run_targets),
536536
"SWIFT_FLAGS": config.swift_flags,
537-
"SWIFT_TARGET_CMAKE_OPTIONS": config.cmake_options,
537+
"SWIFT_TARGET_CMAKE_OPTIONS": " ".join(config.cmake_options),
538538
}
539539

540540
return options
@@ -571,6 +571,12 @@ def compute_product_pipelines(self):
571571
builder.add_product(products.CMark,
572572
is_enabled=self.args.build_cmark)
573573

574+
# If --skip-build-llvm is passed in, LLVM cannot be completely disabled, as
575+
# Swift still needs a few LLVM targets like tblgen to be built for it to be
576+
# configured. Instead, handle this in the product for now.
577+
builder.add_product(products.LLVM,
578+
is_enabled=True)
579+
574580
builder.add_product(products.LibXML2,
575581
is_enabled=self.args.build_libxml2)
576582

@@ -588,11 +594,6 @@ def compute_product_pipelines(self):
588594
# test, install like a normal build-script product.
589595
builder.begin_impl_pipeline(should_run_epilogue_operations=False)
590596

591-
# If --skip-build-llvm is passed in, LLVM cannot be completely disabled, as
592-
# Swift still needs a few LLVM targets like tblgen to be built for it to be
593-
# configured. Instead, handle this in build-script-impl for now.
594-
builder.add_impl_product(products.LLVM,
595-
is_enabled=True)
596597
builder.add_impl_product(products.LibCXX,
597598
is_enabled=self.args.build_libcxx)
598599
builder.add_impl_product(products.LibICU,

utils/swift_build_support/swift_build_support/cmake.py

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ def define(self, var, value):
4747
(var, value, type(value)))
4848
self._options.append('-D%s=%s' % (var, value))
4949

50+
def undefine(self, var):
51+
"""Utility to undefine cmake options in this object.
52+
53+
opts.undefine("FOO") # -> -UFOO
54+
"""
55+
self._options.append('-U%s' % var)
56+
5057
def extend(self, tuples_or_options):
5158
if isinstance(tuples_or_options, CMakeOptions):
5259
self += tuples_or_options

utils/swift_build_support/swift_build_support/host_specific_configuration.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from argparse import ArgumentError
1616

1717
from . import compiler_stage
18+
from .cmake import CMakeOptions
1819
from .targets import StdlibDeploymentTarget
1920

2021

@@ -83,7 +84,7 @@ def __init__(self, host_target, args, stage_dependent_args=None):
8384
self.swift_benchmark_build_targets = []
8485
self.swift_benchmark_run_targets = []
8586
self.swift_flags = ''
86-
self.cmake_options = ''
87+
self.cmake_options = CMakeOptions()
8788
for deployment_target_name in stdlib_targets_to_configure:
8889
# Get the target object.
8990
deployment_target = StdlibDeploymentTarget.get_target_for_name(

0 commit comments

Comments
 (0)