Skip to content

Commit c0d6d8f

Browse files
committed
[cmake] Respect SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER when compiling the stdlib if SWIFT_NATIVE_SWIFT_TOOLS_PATH is not set and CMake_Swift_COMPILER is.
Previously, no matter if SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER was set, we would use for swiftc SWIFT_NATIVE_SWIFT_TOOLS_PATH/bin/swiftc. This is correct assuming that the user always passed in that flag. This will no longer always be true since we are attempting to transition the stdlib slowly to use more standard cmake. Instead, in that case if SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER is set and SWIFT_NATIVE_SWIFT_TOOLS_PATH is not set /and/ we have a CMAKE_Swift_COMPILER, we just use CMAKE_Swift_COMPILER. Hopefully with time we get rid of SWIFT_NATIVE_SWIFT_TOOLS_PATH.
1 parent c5fe4f0 commit c0d6d8f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} --version
507507
message(STATUS "CMake Make Program (${CMAKE_MAKE_PROGRAM}) Version: ${_CMAKE_MAKE_PROGRAM_VERSION}")
508508
message(STATUS "C Compiler (${CMAKE_C_COMPILER}) Version: ${CMAKE_C_COMPILER_VERSION}")
509509
message(STATUS "C++ Compiler (${CMAKE_CXX_COMPILER}) Version: ${CMAKE_CXX_COMPILER_VERSION}")
510+
if (CMAKE_Swift_COMPILER)
511+
message(STATUS "Swift Compiler (${CMAKE_Swift_COMPILER}) Version: ${CMAKE_Swift_COMPILER_VERSION}")
512+
else()
513+
message(STATUS "Swift Compiler (None).")
514+
endif()
510515
if(SWIFT_PATH_TO_CMARK_BUILD)
511516
execute_process(COMMAND ${SWIFT_PATH_TO_CMARK_BUILD}/src/cmark --version
512517
OUTPUT_VARIABLE _CMARK_VERSION
@@ -523,6 +528,13 @@ else()
523528
set(SWIFT_PREBUILT_CLANG TRUE)
524529
endif()
525530

531+
# Also mark if we have a prebuilt swift before we do anything.
532+
if("${SWIFT_NATIVE_SWIFT_TOOLS_PATH}" STREQUAL "")
533+
set(SWIFT_PREBUILT_SWIFT FALSE)
534+
else()
535+
set(SWIFT_PREBUILT_SWIFT TRUE)
536+
endif()
537+
526538
include(SwiftSharedCMakeConfig)
527539

528540
# NOTE: We include this before SwiftComponents as it relies on some LLVM CMake

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,17 @@ function(_compile_swift_files
630630
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
631631
set(HOST_EXECUTABLE_SUFFIX .exe)
632632
endif()
633-
set(swift_compiler_tool "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc${HOST_EXECUTABLE_SUFFIX}")
633+
if(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER)
634+
if(SWIFT_PREBUILT_SWIFT)
635+
set(swift_compiler_tool "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc${HOST_EXECUTABLE_SUFFIX}")
636+
elseif(CMAKE_Swift_COMPILER)
637+
set(swift_compiler_tool "${CMAKE_Swift_COMPILER}")
638+
else()
639+
message(ERROR "Must pass in prebuilt tools using SWIFT_NATIVE_SWIFT_TOOLS_PATH or set CMAKE_Swift_COMPILER")
640+
endif()
641+
else()
642+
set(swift_compiler_tool "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc${HOST_EXECUTABLE_SUFFIX}")
643+
endif()
634644

635645
set(swift_compiler_tool_dep)
636646
if(SWIFT_INCLUDE_TOOLS)

0 commit comments

Comments
 (0)