Skip to content

Commit cc066eb

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 cc066eb

File tree

3 files changed

+82
-67
lines changed

3 files changed

+82
-67
lines changed

CMakeLists.txt

+57-46
Original file line numberDiff line numberDiff line change
@@ -352,17 +352,23 @@ 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+
endif()
366372

367373
option(BRIDGING_MODE [=[
368374
How swift-C++ bridging code is compiled:
@@ -939,41 +945,44 @@ set(SWIFT_MAIN_INCLUDE_DIR "${SWIFT_SOURCE_DIR}/include")
939945
set(SWIFT_SHIMS_INCLUDE_DIR "${SWIFT_SOURCE_DIR}/stdlib/public/SwiftShims")
940946
set(SWIFT_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/include")
941947

942-
if (NOT BOOTSTRAPPING_MODE)
948+
if (NOT BOOTSTRAPPING_MODE AND SWIFT_ENABLE_SWIFT_IN_SWIFT)
943949
message(FATAL_ERROR "turning off bootstrapping is not supported anymore")
944950
endif()
945951

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

976-
if(SWIFT_INCLUDE_TOOLS AND SWIFT_BUILD_SWIFT_SYNTAX)
985+
if(SWIFT_INCLUDE_TOOLS AND SWIFT_BUILD_SWIFT_SYNTAX AND SWIFT_ENABLE_SWIFT_IN_SWIFT)
977986
# Only "HOSTTOOLS" is supported in Linux when Swift parser integration is enabled.
978987
if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|OPENBSD|FREEBSD" AND NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
979988
message(WARNING "Force setting BOOTSTRAPPING=HOSTTOOLS because Swift parser integration is enabled")
@@ -1530,14 +1539,16 @@ if(SWIFT_INCLUDE_TOOLS)
15301539
# https://github.com/apple/swift/issues/48534
15311540
add_subdirectory(tools)
15321541

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)
1542+
if(SWIFT_NATIVE_SWIFT_TOOLS_PATH)
1543+
# Localization targets are configured in a way that assume the swift
1544+
# frontend is being built, so trying to include them for other builds
1545+
# (like stdlib) fail!
1546+
#
1547+
# Diagnostics information is only useful for the frontend compiler
1548+
# anyway, so let's only include it if the compiler is being built,
1549+
# which at the moment seems like if SWIFT_INCLUDE_TOOLS is defined.
1550+
add_subdirectory(localization)
1551+
endif()
15411552
endif()
15421553

15431554
add_subdirectory(utils)

stdlib/cmake/modules/SwiftSource.cmake

+4-2
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,10 @@ function(_compile_swift_files
886886
# cross-compiling the compiler.
887887
list(APPEND swift_compiler_tool_dep "swift-frontend${target_suffix}")
888888

889-
# If we aren't cross compiling, also depend on SwiftMacros.
890-
list(APPEND swift_compiler_tool_dep SwiftMacros)
889+
if(SWIFT_ENABLE_SWIFT_IN_SWIFT)
890+
# If we aren't cross compiling, also depend on SwiftMacros.
891+
list(APPEND swift_compiler_tool_dep SwiftMacros)
892+
endif()
891893
endif()
892894

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

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)