Skip to content

Commit ac11388

Browse files
committed
[Build Add --minimal-cxx-bootstrap to build a minimal Swift from C++ sources
Introduce an explicit build-script flag `--minimal-cxx-bootstrap` and the CMake option SWIFT_MINIMAL_CXX_BOOTSTRAP it maps to. This option turns off components that require a host Swift toolchain, and is intented to be used when bringing up a new host platform. It disables: * Macros in the compiler * Regular expression support in the compiler * The regular expression support libraries * Most of the unit-testing facilities for the compiler * The optimizer passes written in Swift (removing Embedded Swift support, among other things)
1 parent f10edf2 commit ac11388

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ option(SWIFT_BUILD_SWIFT_SYNTAX
816816
option(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER
817817
"Build the Swift regex parser as part of the compiler."
818818
TRUE)
819+
819820
if(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER AND NOT SWIFT_BUILD_SWIFT_SYNTAX)
820821
message(WARNING "Force setting SWIFT_BUILD_REGEX_PARSER_IN_COMPILER=OFF because Swift parser integration is disabled")
821822
set(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER OFF)
@@ -950,6 +951,26 @@ if (NOT BOOTSTRAPPING_MODE)
950951
message(FATAL_ERROR "turning off bootstrapping is not supported anymore")
951952
endif()
952953

954+
option(SWIFT_MINIMAL_CXX_BOOTSTRAP
955+
"Build a minimal Swift compiler from only C++ sources. This compiler is only suitable for bootstrapping a Swift toolchain in an environment where one isn't already available."
956+
FALSE)
957+
958+
if(SWIFT_MINIMAL_CXX_BOOTSTRAP)
959+
message(WARNING "Building minimal Swift compiler from only C++ sources. This compiler is only suitable for bootstrapping a full Swift compiler.")
960+
961+
# Disable swift-syntax integration
962+
set(SWIFT_BUILD_SWIFT_SYNTAX OFF)
963+
964+
# Disable regular expression support.
965+
set(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER OFF)
966+
967+
# Disable string processing library
968+
set(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING OFF)
969+
970+
# Disable bootstrapping
971+
set(BOOTSTRAPPING_MODE OFF)
972+
endif()
973+
953974
# As a temporary workaround, disable SwiftCompilerSources on
954975
# Windows/ARM64 because the compiler segfaults
955976
if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64")

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,12 @@ def create_argument_parser():
637637
default=defaults.llvm_install_components(),
638638
help='A semi-colon split list of llvm components to install')
639639

640+
option('--minimal-cxx-bootstrap', toggle_true, default=False,
641+
help='Build a minimal Swift compiler from only C++ sources '
642+
'(that does not require a host Swift compiler). The resulting '
643+
'toolchain is only suitable for bootstrapping Swift on a new '
644+
'host.')
645+
640646
option('--bootstrapping', store('bootstrapping_mode'),
641647
choices=['hosttools', 'bootstrapping', 'bootstrapping-with-hostlibs'],
642648
help='The bootstrapping build mode for swift compiler modules. '

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@
246246
'lto_type': None,
247247
'maccatalyst': False,
248248
'maccatalyst_ios_tests': False,
249+
'minimal_cxx_bootstrap': False,
249250
'musl_path': '/usr/local/musl',
250251
'linux_static_archs': ['x86_64', 'aarch64'],
251252
'native_clang_tools_path': None,
@@ -694,6 +695,7 @@ class BuildScriptImplOption(_BaseOption):
694695
EnableOption('--clean-early-swift-driver', dest='clean_early_swift_driver'),
695696
EnableOption('--llvm-enable-modules'),
696697
EnableOption('--build-llvm', dest='_build_llvm'),
698+
EnableOption('--minimal-cxx-bootstrap'),
697699

698700
DisableOption('--skip-build-cmark', dest='build_cmark'),
699701
DisableOption('--skip-build-llvm', dest='build_llvm'),

utils/swift_build_support/swift_build_support/build_script_invocation.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ def convert_to_impl_arguments(self):
275275
args.extra_cmake_options.append(
276276
'-DSWIFT_EARLY_SWIFT_DRIVER_BUILD={}'.format(swift_driver_build))
277277

278+
if args.minimal_cxx_bootstrap:
279+
if args.build_early_swift_driver:
280+
exit_rejecting_arguments(
281+
'cannot combine --minimal-cxx-bootstrap with the early '
282+
'Swift driver. Please remove --minimal-cxx-bootstrap or '
283+
'add --skip-early-swift-driver')
284+
285+
args.extra_cmake_options.append(
286+
'-DSWIFT_MINIMAL_CXX_BOOTSTRAP:BOOL=TRUE')
287+
278288
# Then add subproject install flags that either skip building them /or/
279289
# if we are going to build them and install_all is set, we also install
280290
# them.

0 commit comments

Comments
 (0)