Skip to content

[cmake] Prepare for stage2 bootstrap swift build #38123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 24 additions & 6 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,22 @@ function(add_swift_host_library name)
# find all of the necessary swift libraries on Darwin.
if (NOT ASHL_PURE_SWIFT)
if (CMAKE_Swift_COMPILER)
# Add in the SDK directory for the host platform and add an rpath.
target_link_directories(${name} PRIVATE
${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}/usr/lib/swift)
# Add in the toolchain directory so we can grab compatibility libraries
get_filename_component(TOOLCHAIN_BIN_DIR ${CMAKE_Swift_COMPILER} DIRECTORY)
get_filename_component(TOOLCHAIN_LIB_DIR "${TOOLCHAIN_BIN_DIR}/../lib/swift/macosx" ABSOLUTE)
target_link_directories(${name} PUBLIC ${TOOLCHAIN_LIB_DIR})

# Add in the SDK directory for the host platform.
#
# NOTE: We do this /after/ target_link_directorying TOOLCHAIN_LIB_DIR to
# ensure that we first find libraries from the toolchain, rather than
# from the SDK. The reason why this is important is that when we perform
# a stage2 build, this path is into the stage1 build. This is not a pure
# SDK and also contains compatibility libraries. We need to make sure
# that the compiler sees the actual toolchain's compatibility libraries
# first before the just built compability libraries or build errors occur.
target_link_directories(${name} PRIVATE
${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}/usr/lib/swift)
endif()
endif()

Expand Down Expand Up @@ -808,14 +817,23 @@ function(add_swift_host_tool executable)
# host side tools but link with clang, add the appropriate -L paths so we
# find all of the necessary swift libraries on Darwin.
if (CMAKE_Swift_COMPILER)
# Add in the SDK directory for the host platform and add an rpath.
target_link_directories(${executable} PRIVATE
${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}/usr/lib/swift)
# Add in the toolchain directory so we can grab compatibility libraries
get_filename_component(TOOLCHAIN_BIN_DIR ${CMAKE_Swift_COMPILER} DIRECTORY)
get_filename_component(TOOLCHAIN_LIB_DIR "${TOOLCHAIN_BIN_DIR}/../lib/swift/macosx" ABSOLUTE)
target_link_directories(${executable} PUBLIC ${TOOLCHAIN_LIB_DIR})

# Add in the SDK directory for the host platform and add an rpath.
#
# NOTE: We do this /after/ target_link_directorying TOOLCHAIN_LIB_DIR to
# ensure that we first find libraries from the toolchain, rather than from
# the SDK. The reason why this is important is that when we perform a
# stage2 build, this path is into the stage1 build. This is not a pure SDK
# and also contains compatibility libraries. We need to make sure that the
# compiler sees the actual toolchain's compatibility libraries first
# before the just built compability libraries or build errors occur.
target_link_directories(${executable} PRIVATE
${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}/usr/lib/swift)

if (ASHT_HAS_LIBSWIFT AND SWIFT_TOOLS_ENABLE_LIBSWIFT)
# Workaround to make lldb happy: we have to explicitly add all libswift modules
# to the linker command line.
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