Skip to content

Commit 72b3e6b

Browse files
committed
[SwiftCompilerSources][build] Use CMAKE_Swift_COMPILER instead of SWIFT_EXEC_FOR_SWIFT_MODULES
The build process should only use one Swift compiler, and using CMake's built-in `CMAKE_Swift_COMPILER` variable allows using built-in version detection logic (`CMAKE_Swift_COMPILER_VERSION`).
1 parent 91c64f7 commit 72b3e6b

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,13 @@ set(SWIFT_RUNTIME_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin")
632632
set(SWIFT_LIBRARY_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib")
633633
if("${SWIFT_NATIVE_SWIFT_TOOLS_PATH}" STREQUAL "")
634634
set(SWIFT_NATIVE_SWIFT_TOOLS_PATH "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
635-
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER}")
636635
elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
637636
# If cross-compiling, we don't have to bootstrap. We can just use the previously
638637
# built native swiftc to build the swift compiler modules.
639638
message(STATUS "Building swift modules with previously built tools instead of bootstrapping")
640-
set(SWIFT_EXEC_FOR_SWIFT_MODULES "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc")
639+
if(NOT "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc" STREQUAL "${CMAKE_Swift_COMPILER}")
640+
message(FATAL_ERROR "The Swift compiler (${CMAKE_Swift_COMPILER}) differs from the Swift compiler in SWIFT_NATIVE_SWIFT_TOOLS_PATH (${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc).")
641+
endif()
641642
if(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING-WITH-HOSTLIBS")
642643
set(BOOTSTRAPPING_MODE "CROSSCOMPILE-WITH-HOSTLIBS")
643644
elseif(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING")

SwiftCompilerSources/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,12 @@ else()
200200

201201
if(${BOOTSTRAPPING_MODE} MATCHES "HOSTTOOLS|CROSSCOMPILE")
202202

203-
if (NOT SWIFT_EXEC_FOR_SWIFT_MODULES)
203+
if (NOT CMAKE_Swift_COMPILER)
204204
message(FATAL_ERROR "Need a swift toolchain building swift compiler sources")
205205
endif()
206206

207207
add_swift_compiler_modules_library(swiftCompilerModules
208-
SWIFT_EXEC "${SWIFT_EXEC_FOR_SWIFT_MODULES}")
208+
SWIFT_EXEC "${CMAKE_Swift_COMPILER}")
209209

210210
elseif(${BOOTSTRAPPING_MODE} MATCHES "BOOTSTRAPPING.*")
211211

cmake/modules/AddSwift.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ function(add_swift_host_tool executable)
707707
708708
if(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
709709
# Add in the toolchain directory so we can grab compatibility libraries
710-
get_filename_component(TOOLCHAIN_BIN_DIR ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY)
710+
get_filename_component(TOOLCHAIN_BIN_DIR ${CMAKE_Swift_COMPILER} DIRECTORY)
711711
get_filename_component(TOOLCHAIN_LIB_DIR "${TOOLCHAIN_BIN_DIR}/../lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}" ABSOLUTE)
712712
target_link_directories(${executable} PUBLIC ${TOOLCHAIN_LIB_DIR})
713713
@@ -788,7 +788,7 @@ function(add_swift_host_tool executable)
788788
if(${BOOTSTRAPPING_MODE} MATCHES "HOSTTOOLS|CROSSCOMPILE")
789789
# At build time and run time, link against the swift libraries in the
790790
# installed host toolchain.
791-
get_filename_component(swift_bin_dir ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY)
791+
get_filename_component(swift_bin_dir ${CMAKE_Swift_COMPILER} DIRECTORY)
792792
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
793793
set(host_lib_dir "${swift_dir}/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
794794

tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function(add_sourcekitd_swifrt_linking target path HAS_SWIFT_MODULES)
3535

3636
if(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
3737
# Add in the toolchain directory so we can grab compatibility libraries
38-
get_filename_component(TOOLCHAIN_BIN_DIR ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY)
38+
get_filename_component(TOOLCHAIN_BIN_DIR ${CMAKE_Swift_COMPILER} DIRECTORY)
3939
get_filename_component(TOOLCHAIN_LIB_DIR "${TOOLCHAIN_BIN_DIR}/../lib/swift/macosx" ABSOLUTE)
4040
target_link_directories(${target} PUBLIC ${TOOLCHAIN_LIB_DIR})
4141

@@ -113,7 +113,7 @@ function(add_sourcekitd_swifrt_linking target path HAS_SWIFT_MODULES)
113113
if(${BOOTSTRAPPING_MODE} MATCHES "HOSTTOOLS|CROSSCOMPILE")
114114
# At build time and and run time, link against the swift libraries in the
115115
# installed host toolchain.
116-
get_filename_component(swift_bin_dir ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY)
116+
get_filename_component(swift_bin_dir ${CMAKE_Swift_COMPILER} DIRECTORY)
117117
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
118118
set(host_lib_dir "${swift_dir}/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
119119

0 commit comments

Comments
 (0)