Skip to content

Commit e044d9b

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 e044d9b

File tree

4 files changed

+105
-90
lines changed

4 files changed

+105
-90
lines changed

CMakeLists.txt

+47-38
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}" STREQUAL "")
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")

localization/CMakeLists.txt

+33-31
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1-
set(diagnostic_witness "${CMAKE_BINARY_DIR}/share/swift/diagnostics/generated")
1+
if(SWIFT_NATIVE_SWIFT_TOOLS_PATH)
2+
set(diagnostic_witness "${CMAKE_BINARY_DIR}/share/swift/diagnostics/generated")
23

3-
add_custom_command(
4-
OUTPUT
5-
${diagnostic_witness}
6-
COMMAND
7-
${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/diagnostics/ ${CMAKE_BINARY_DIR}/share/swift/diagnostics/
8-
COMMAND
9-
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swift-def-to-strings-converter"
10-
--output-directory ${CMAKE_BINARY_DIR}/share/swift/diagnostics/
11-
COMMAND
12-
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swift-serialize-diagnostics"
13-
--input-file-path ${CMAKE_BINARY_DIR}/share/swift/diagnostics/en.strings
14-
--output-directory ${CMAKE_BINARY_DIR}/share/swift/diagnostics/
15-
COMMAND
16-
${CMAKE_COMMAND} -E touch ${diagnostic_witness}
17-
DEPENDS
18-
swift-def-to-strings-converter
19-
swift-serialize-diagnostics
20-
# Add files in diagnostics subdirectory when they're created
21-
)
4+
add_custom_command(
5+
OUTPUT
6+
${diagnostic_witness}
7+
COMMAND
8+
${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/diagnostics/ ${CMAKE_BINARY_DIR}/share/swift/diagnostics/
9+
COMMAND
10+
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swift-def-to-strings-converter"
11+
--output-directory ${CMAKE_BINARY_DIR}/share/swift/diagnostics/
12+
COMMAND
13+
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swift-serialize-diagnostics"
14+
--input-file-path ${CMAKE_BINARY_DIR}/share/swift/diagnostics/en.strings
15+
--output-directory ${CMAKE_BINARY_DIR}/share/swift/diagnostics/
16+
COMMAND
17+
${CMAKE_COMMAND} -E touch ${diagnostic_witness}
18+
DEPENDS
19+
swift-def-to-strings-converter
20+
swift-serialize-diagnostics
21+
# Add files in diagnostics subdirectory when they're created
22+
)
2223

23-
add_custom_target(diagnostic-database DEPENDS ${diagnostic_witness})
24+
add_custom_target(diagnostic-database DEPENDS ${diagnostic_witness})
2425

25-
add_dependencies(swift-frontend diagnostic-database)
26+
add_dependencies(swift-frontend diagnostic-database)
2627

27-
swift_install_in_component(
28-
DIRECTORY ${CMAKE_BINARY_DIR}/share/swift/diagnostics/
29-
DESTINATION "share/swift/diagnostics"
30-
COMPONENT compiler
31-
FILES_MATCHING
32-
PATTERN "*.db"
33-
PATTERN "*.yaml"
34-
PATTERN "*.strings"
35-
)
28+
swift_install_in_component(
29+
DIRECTORY ${CMAKE_BINARY_DIR}/share/swift/diagnostics/
30+
DESTINATION "share/swift/diagnostics"
31+
COMPONENT compiler
32+
FILES_MATCHING
33+
PATTERN "*.db"
34+
PATTERN "*.yaml"
35+
PATTERN "*.strings"
36+
)
37+
endif()

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)