Skip to content

Commit eeee0df

Browse files
committed
CMake: option to disable swift in swift
Adding `SWIFT_ENABLE_SWIFT_IN_SWIFT` option to enable or disable the parts of Swift that require a Swift compiler to build. This is meant for bootstrapping compilers on new platforms and is not guaranteed to result in a compiler that will pass the test suite. This option is on by default so that folks won't forget. If the option is off, the resulting compiler does not include the Swift optimizer sources in SwiftCompilerSources nor does the resulting compiler have swift macro support.
1 parent 157e71a commit eeee0df

File tree

4 files changed

+92
-69
lines changed

4 files changed

+92
-69
lines changed

CMakeLists.txt

+58-46
Original file line numberDiff line numberDiff line change
@@ -352,17 +352,24 @@ option(SWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS
352352
debugging Swift)"
353353
FALSE)
354354

355-
set(BOOTSTRAPPING_MODE HOSTTOOLS CACHE STRING [=[
356-
How to build the swift compiler modules. Possible values are
357-
HOSTTOOLS: build with a pre-installed toolchain
358-
BOOTSTRAPPING: build with a 2-stage bootstrapping process
359-
BOOTSTRAPPING-WITH-HOSTLIBS: build with a 2-stage bootstrapping process,
360-
but the compiler links against the host system swift libs (macOS only)
361-
CROSSCOMPILE: cross-compiledwith a native host compiler, provided in
362-
`SWIFT_NATIVE_SWIFT_TOOLS_PATH` (non-Darwin only)
363-
CROSSCOMPILE-WITH-HOSTLIBS: build with a bootstrapping-with-hostlibs compiled
364-
compiler, provided in `SWIFT_NATIVE_SWIFT_TOOLS_PATH`
365-
]=])
355+
option(SWIFT_ENABLE_SWIFT_IN_SWIFT "Enable Swift sources in Swift compiler" ON)
356+
357+
if(SWIFT_ENABLE_SWIFT_IN_SWIFT)
358+
set(BOOTSTRAPPING_MODE HOSTTOOLS CACHE STRING [=[
359+
How to build the swift compiler modules. Possible values are
360+
HOSTTOOLS: build with a pre-installed toolchain
361+
BOOTSTRAPPING: build with a 2-stage bootstrapping process
362+
BOOTSTRAPPING-WITH-HOSTLIBS: build with a 2-stage bootstrapping process,
363+
but the compiler links against the host system swift libs (macOS only)
364+
CROSSCOMPILE: cross-compiledwith a native host compiler, provided in
365+
`SWIFT_NATIVE_SWIFT_TOOLS_PATH` (non-Darwin only)
366+
CROSSCOMPILE-WITH-HOSTLIBS: build with a bootstrapping-with-hostlibs compiled
367+
compiler, provided in `SWIFT_NATIVE_SWIFT_TOOLS_PATH`
368+
]=])
369+
else()
370+
set(BOOTSTRAPPING_MODE OFF)
371+
set(SWIFT_BUILD_SWIFT_SYNTAX OFF)
372+
endif()
366373

367374
option(BRIDGING_MODE [=[
368375
How swift-C++ bridging code is compiled:
@@ -939,41 +946,44 @@ set(SWIFT_MAIN_INCLUDE_DIR "${SWIFT_SOURCE_DIR}/include")
939946
set(SWIFT_SHIMS_INCLUDE_DIR "${SWIFT_SOURCE_DIR}/stdlib/public/SwiftShims")
940947
set(SWIFT_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/include")
941948

942-
if (NOT BOOTSTRAPPING_MODE)
949+
if (NOT BOOTSTRAPPING_MODE AND SWIFT_ENABLE_SWIFT_IN_SWIFT)
943950
message(FATAL_ERROR "turning off bootstrapping is not supported anymore")
944951
endif()
945952

946953
set(SWIFT_RUNTIME_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin")
947954
set(SWIFT_LIBRARY_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib")
948-
if("${SWIFT_NATIVE_SWIFT_TOOLS_PATH}" STREQUAL "")
949-
# This is the normal case. We are not cross-compiling.
950-
set(SWIFT_NATIVE_SWIFT_TOOLS_PATH "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
951-
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER}")
952-
if(NOT SWIFT_EXEC_FOR_SWIFT_MODULES)
953-
message(WARNING "BOOTSTRAPPING set to OFF because no Swift compiler is defined")
954-
set(BOOTSTRAPPING_MODE "OFF")
955-
endif()
956-
elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
957-
# If cross-compiling, we don't have to bootstrap. We can just use the previously
958-
# built native swiftc to build the swift compiler modules.
959-
message(STATUS "Building swift modules with previously built tools instead of bootstrapping")
960-
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc")
961-
if(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING-WITH-HOSTLIBS")
962-
set(BOOTSTRAPPING_MODE "CROSSCOMPILE-WITH-HOSTLIBS")
963-
elseif(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING")
964-
set(BOOTSTRAPPING_MODE "CROSSCOMPILE")
965-
else()
966-
set(BOOTSTRAPPING_MODE "HOSTTOOLS")
955+
956+
if(SWIFT_ENABLE_SWIFT_IN_SWIFT)
957+
if(NOT SWIFT_NATIVE_SWIFT_TOOLS_PATH)
958+
# This is the normal case. We are not cross-compiling.
959+
set(SWIFT_NATIVE_SWIFT_TOOLS_PATH "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
960+
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER}")
961+
if(NOT SWIFT_EXEC_FOR_SWIFT_MODULES)
962+
message(WARNING "BOOTSTRAPPING set to OFF because no Swift compiler is defined")
963+
set(BOOTSTRAPPING_MODE "OFF")
964+
endif()
965+
elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
966+
# If cross-compiling, we don't have to bootstrap. We can just use the previously
967+
# built native swiftc to build the swift compiler modules.
968+
message(STATUS "Building swift modules with previously built tools instead of bootstrapping")
969+
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc")
970+
if(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING-WITH-HOSTLIBS")
971+
set(BOOTSTRAPPING_MODE "CROSSCOMPILE-WITH-HOSTLIBS")
972+
elseif(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING")
973+
set(BOOTSTRAPPING_MODE "CROSSCOMPILE")
974+
else()
975+
set(BOOTSTRAPPING_MODE "HOSTTOOLS")
976+
endif()
977+
elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_BUILD_SWIFT_SYNTAX)
978+
# We are building using a pre-installed host toolchain but not bootstrapping
979+
# the Swift modules. This happens when building using 'build-tooling-libs'
980+
# where we haven't built a new Swift compiler. Use the Swift compiler from the
981+
# pre-installed host toolchain to build the Swift modules.
982+
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER}")
967983
endif()
968-
elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_BUILD_SWIFT_SYNTAX)
969-
# We are building using a pre-installed host toolchain but not bootstrapping
970-
# the Swift modules. This happens when building using 'build-tooling-libs'
971-
# where we haven't built a new Swift compiler. Use the Swift compiler from the
972-
# pre-installed host toolchain to build the Swift modules.
973-
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER}")
974984
endif()
975985

976-
if(SWIFT_INCLUDE_TOOLS AND SWIFT_BUILD_SWIFT_SYNTAX)
986+
if(SWIFT_INCLUDE_TOOLS AND SWIFT_BUILD_SWIFT_SYNTAX AND SWIFT_ENABLE_SWIFT_IN_SWIFT)
977987
# Only "HOSTTOOLS" is supported in Linux when Swift parser integration is enabled.
978988
if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|OPENBSD|FREEBSD" AND NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
979989
message(WARNING "Force setting BOOTSTRAPPING=HOSTTOOLS because Swift parser integration is enabled")
@@ -1530,14 +1540,16 @@ if(SWIFT_INCLUDE_TOOLS)
15301540
# https://github.com/apple/swift/issues/48534
15311541
add_subdirectory(tools)
15321542

1533-
# Localization targets are configured in a way that assume the swift
1534-
# frontend is being built, so trying to include them for other builds
1535-
# (like stdlib) fail!
1536-
#
1537-
# Diagnostics information is only useful for the frontend compiler
1538-
# anyway, so let's only include it if the compiler is being built,
1539-
# which at the moment seems like if SWIFT_INCLUDE_TOOLS is defined.
1540-
add_subdirectory(localization)
1543+
if(SWIFT_NATIVE_SWIFT_TOOLS_PATH)
1544+
# Localization targets are configured in a way that assume the swift
1545+
# frontend is being built, so trying to include them for other builds
1546+
# (like stdlib) fail!
1547+
#
1548+
# Diagnostics information is only useful for the frontend compiler
1549+
# anyway, so let's only include it if the compiler is being built,
1550+
# which at the moment seems like if SWIFT_INCLUDE_TOOLS is defined.
1551+
add_subdirectory(localization)
1552+
endif()
15411553
endif()
15421554

15431555
add_subdirectory(utils)

stdlib/cmake/modules/SwiftSource.cmake

+10-3
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,12 @@ function(_compile_swift_files
856856
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
857857
set(HOST_EXECUTABLE_SUFFIX .exe)
858858
endif()
859-
if(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER)
859+
if(NOT SWIFT_ENABLE_SWIFT_IN_SWIFT)
860+
# This is only for bootstrapping purposes. The just-built Swift is very
861+
# limited and only built for the builder to build the next stages with
862+
# hosttools.
863+
set(swift_compiler_tool "${Swift_BINARY_DIR}/bin/swiftc")
864+
elseif(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER)
860865
if(SWIFT_PREBUILT_SWIFT)
861866
set(swift_compiler_tool "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc${HOST_EXECUTABLE_SUFFIX}")
862867
elseif(CMAKE_Swift_COMPILER)
@@ -886,8 +891,10 @@ function(_compile_swift_files
886891
# cross-compiling the compiler.
887892
list(APPEND swift_compiler_tool_dep "swift-frontend${target_suffix}")
888893

889-
# If we aren't cross compiling, also depend on SwiftMacros.
890-
list(APPEND swift_compiler_tool_dep SwiftMacros)
894+
if(SWIFT_ENABLE_SWIFT_IN_SWIFT)
895+
# If we aren't cross compiling, also depend on SwiftMacros.
896+
list(APPEND swift_compiler_tool_dep SwiftMacros)
897+
endif()
891898
endif()
892899

893900
# If there are more than one output files, we assume that they are specified

stdlib/tools/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Keep in sync with test/CMakeLists.txt: swift-reflection-test is
22
# only used when testing dynamic stdlib.
3-
if(SWIFT_BUILD_DYNAMIC_STDLIB AND (SWIFT_INCLUDE_TESTS OR SWIFT_INCLUDE_TEST_BINARIES))
3+
if(SWIFT_BUILD_REMOTE_MIRROR AND
4+
SWIFT_BUILD_DYNAMIC_STDLIB AND
5+
(SWIFT_INCLUDE_TESTS OR SWIFT_INCLUDE_TEST_BINARIES))
46
add_subdirectory(swift-reflection-test)
57
endif()

tools/swift-compatibility-symbols/CMakeLists.txt

+21-19
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@ add_swift_host_tool(swift-compatibility-symbols
55
DOES_NOT_USE_SWIFT
66
)
77

8-
set(syms_file "${CMAKE_BINARY_DIR}/share/swift/compatibility-symbols")
8+
if(SWIFT_NATIVE_SWIFT_TOOLS_PATH)
9+
set(syms_file "${CMAKE_BINARY_DIR}/share/swift/compatibility-symbols")
910

10-
add_custom_command_target(copy_compat_target
11-
COMMAND
12-
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swift-compatibility-symbols"
13-
--output-filename ${syms_file}
14-
OUTPUT
15-
${syms_file}
16-
DEPENDS
17-
swift-compatibility-symbols
18-
)
11+
add_custom_command_target(copy_compat_target
12+
COMMAND
13+
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swift-compatibility-symbols"
14+
--output-filename ${syms_file}
15+
OUTPUT
16+
${syms_file}
17+
DEPENDS
18+
swift-compatibility-symbols
19+
)
1920

20-
add_dependencies(swift-frontend "${copy_compat_target}")
21+
add_dependencies(swift-frontend "${copy_compat_target}")
2122

22-
swift_install_in_component(
23-
FILES
24-
${syms_file}
25-
DESTINATION
26-
"share/swift"
27-
COMPONENT
28-
compiler
29-
)
23+
swift_install_in_component(
24+
FILES
25+
${syms_file}
26+
DESTINATION
27+
"share/swift"
28+
COMPONENT
29+
compiler
30+
)
31+
endif()

0 commit comments

Comments
 (0)