Skip to content

Commit

Permalink
[cmake] Respect SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER when compiling…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
gottesmm committed Jun 27, 2021
1 parent c5fe4f0 commit c0d6d8f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} --version
message(STATUS "CMake Make Program (${CMAKE_MAKE_PROGRAM}) Version: ${_CMAKE_MAKE_PROGRAM_VERSION}")
message(STATUS "C Compiler (${CMAKE_C_COMPILER}) Version: ${CMAKE_C_COMPILER_VERSION}")
message(STATUS "C++ Compiler (${CMAKE_CXX_COMPILER}) Version: ${CMAKE_CXX_COMPILER_VERSION}")
if (CMAKE_Swift_COMPILER)
message(STATUS "Swift Compiler (${CMAKE_Swift_COMPILER}) Version: ${CMAKE_Swift_COMPILER_VERSION}")
else()
message(STATUS "Swift Compiler (None).")
endif()
if(SWIFT_PATH_TO_CMARK_BUILD)
execute_process(COMMAND ${SWIFT_PATH_TO_CMARK_BUILD}/src/cmark --version
OUTPUT_VARIABLE _CMARK_VERSION
Expand All @@ -523,6 +528,13 @@ else()
set(SWIFT_PREBUILT_CLANG TRUE)
endif()

# Also mark if we have a prebuilt swift before we do anything.
if("${SWIFT_NATIVE_SWIFT_TOOLS_PATH}" STREQUAL "")
set(SWIFT_PREBUILT_SWIFT FALSE)
else()
set(SWIFT_PREBUILT_SWIFT TRUE)
endif()

include(SwiftSharedCMakeConfig)

# NOTE: We include this before SwiftComponents as it relies on some LLVM CMake
Expand Down
12 changes: 11 additions & 1 deletion stdlib/cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,17 @@ function(_compile_swift_files
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
set(HOST_EXECUTABLE_SUFFIX .exe)
endif()
set(swift_compiler_tool "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc${HOST_EXECUTABLE_SUFFIX}")
if(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER)
if(SWIFT_PREBUILT_SWIFT)
set(swift_compiler_tool "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc${HOST_EXECUTABLE_SUFFIX}")
elseif(CMAKE_Swift_COMPILER)
set(swift_compiler_tool "${CMAKE_Swift_COMPILER}")
else()
message(ERROR "Must pass in prebuilt tools using SWIFT_NATIVE_SWIFT_TOOLS_PATH or set CMAKE_Swift_COMPILER")
endif()
else()
set(swift_compiler_tool "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc${HOST_EXECUTABLE_SUFFIX}")
endif()

set(swift_compiler_tool_dep)
if(SWIFT_INCLUDE_TOOLS)
Expand Down

0 comments on commit c0d6d8f

Please sign in to comment.