Skip to content

Commit ceb54d3

Browse files
authored
Merge pull request #38123 from gottesmm/pr-ffc2f8bbbc47f85ce1988bfefd5b32d61085ca4e
[cmake] Prepare for stage2 bootstrap swift build
2 parents d08b2d5 + c0d6d8f commit ceb54d3

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
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

cmake/modules/AddSwift.cmake

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -600,13 +600,22 @@ function(add_swift_host_library name)
600600
# find all of the necessary swift libraries on Darwin.
601601
if (NOT ASHL_PURE_SWIFT)
602602
if (CMAKE_Swift_COMPILER)
603-
# Add in the SDK directory for the host platform and add an rpath.
604-
target_link_directories(${name} PRIVATE
605-
${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}/usr/lib/swift)
606603
# Add in the toolchain directory so we can grab compatibility libraries
607604
get_filename_component(TOOLCHAIN_BIN_DIR ${CMAKE_Swift_COMPILER} DIRECTORY)
608605
get_filename_component(TOOLCHAIN_LIB_DIR "${TOOLCHAIN_BIN_DIR}/../lib/swift/macosx" ABSOLUTE)
609606
target_link_directories(${name} PUBLIC ${TOOLCHAIN_LIB_DIR})
607+
608+
# Add in the SDK directory for the host platform.
609+
#
610+
# NOTE: We do this /after/ target_link_directorying TOOLCHAIN_LIB_DIR to
611+
# ensure that we first find libraries from the toolchain, rather than
612+
# from the SDK. The reason why this is important is that when we perform
613+
# a stage2 build, this path is into the stage1 build. This is not a pure
614+
# SDK and also contains compatibility libraries. We need to make sure
615+
# that the compiler sees the actual toolchain's compatibility libraries
616+
# first before the just built compability libraries or build errors occur.
617+
target_link_directories(${name} PRIVATE
618+
${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}/usr/lib/swift)
610619
endif()
611620
endif()
612621
@@ -808,14 +817,23 @@ function(add_swift_host_tool executable)
808817
# host side tools but link with clang, add the appropriate -L paths so we
809818
# find all of the necessary swift libraries on Darwin.
810819
if (CMAKE_Swift_COMPILER)
811-
# Add in the SDK directory for the host platform and add an rpath.
812-
target_link_directories(${executable} PRIVATE
813-
${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}/usr/lib/swift)
814820
# Add in the toolchain directory so we can grab compatibility libraries
815821
get_filename_component(TOOLCHAIN_BIN_DIR ${CMAKE_Swift_COMPILER} DIRECTORY)
816822
get_filename_component(TOOLCHAIN_LIB_DIR "${TOOLCHAIN_BIN_DIR}/../lib/swift/macosx" ABSOLUTE)
817823
target_link_directories(${executable} PUBLIC ${TOOLCHAIN_LIB_DIR})
818824
825+
# Add in the SDK directory for the host platform and add an rpath.
826+
#
827+
# NOTE: We do this /after/ target_link_directorying TOOLCHAIN_LIB_DIR to
828+
# ensure that we first find libraries from the toolchain, rather than from
829+
# the SDK. The reason why this is important is that when we perform a
830+
# stage2 build, this path is into the stage1 build. This is not a pure SDK
831+
# and also contains compatibility libraries. We need to make sure that the
832+
# compiler sees the actual toolchain's compatibility libraries first
833+
# before the just built compability libraries or build errors occur.
834+
target_link_directories(${executable} PRIVATE
835+
${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}/usr/lib/swift)
836+
819837
if (ASHT_HAS_LIBSWIFT AND SWIFT_TOOLS_ENABLE_LIBSWIFT)
820838
# Workaround to make lldb happy: we have to explicitly add all libswift modules
821839
# to the linker command line.

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)