Skip to content

Commit 771c99f

Browse files
committed
cmake: add support for bootstrapping with swiftly
For hosts that have a swiftly-managed Swift compiler, we could not bootstrap using those tools, because of some hardcoded assumptions about where the `/lib` directory lives, relative to the `/bin` directory that contains the detected `swiftc`. This patch adds specific support for detecting when the `swiftc` is coming from a swiftly install and uses the correct paths. I've tested this patch on my Linux machine that has swiftly 1.0.1, with the Swift 6.1.2 toolchain.
1 parent 2caa726 commit 771c99f

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

SwiftCompilerSources/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,18 @@ function(add_swift_compiler_modules_library name)
195195

196196
# Workaround for https://github.com/swiftlang/llvm-project/issues/7172
197197
list(APPEND swift_compile_options "-Xcc" "-Xclang" "-Xcc" "-fmodule-format=raw")
198+
199+
elseif(swift_exec_bin_dir MATCHES ".*/swiftly/bin")
200+
# Detect and handle swiftly-managed hosts.
201+
execute_process(COMMAND swiftly use --print-location
202+
OUTPUT_VARIABLE swiftly_dir
203+
ERROR_VARIABLE err)
204+
if(err)
205+
message(SEND_ERROR "Failed to find swiftly Swift compiler")
206+
endif()
207+
string(STRIP "${swiftly_dir}" swiftly_dir)
208+
209+
list(APPEND sdk_option "-I" "${swiftly_dir}/usr/lib" "-I" "${swiftly_dir}/usr/lib")
198210
else()
199211
list(APPEND sdk_option "-I" "${swift_exec_bin_dir}/../lib" "-I" "${sdk_path}/usr/lib")
200212
endif()

cmake/modules/AddSwift.cmake

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,19 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
550550
else()
551551
get_filename_component(swift_bin_dir ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY)
552552
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
553+
554+
# Detect and handle swiftly-managed hosts.
555+
if(swift_bin_dir MATCHES ".*/swiftly/bin")
556+
execute_process(COMMAND swiftly use --print-location
557+
OUTPUT_VARIABLE swiftly_dir
558+
ERROR_VARIABLE err)
559+
if(err)
560+
message(SEND_ERROR "Failed to find swiftly Swift compiler")
561+
endif()
562+
string(STRIP "${swiftly_dir}" swiftly_dir)
563+
set(swift_dir "${swiftly_dir}/usr")
564+
endif()
565+
553566
endif()
554567
set(host_lib_dir "${swift_dir}/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
555568
else()
@@ -611,6 +624,19 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
611624
else()
612625
get_filename_component(swift_bin_dir ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY)
613626
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
627+
628+
# Detect and handle swiftly-managed hosts.
629+
if(swift_bin_dir MATCHES ".*/swiftly/bin")
630+
execute_process(COMMAND swiftly use --print-location
631+
OUTPUT_VARIABLE swiftly_dir
632+
ERROR_VARIABLE err)
633+
if(err)
634+
message(SEND_ERROR "Failed to find swiftly Swift compiler")
635+
endif()
636+
string(STRIP "${swiftly_dir}" swiftly_dir)
637+
set(swift_dir "${swiftly_dir}/usr")
638+
endif()
639+
614640
set(host_lib_dir "${swift_dir}/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
615641
target_link_directories(${target} PRIVATE ${host_lib_dir})
616642

cmake/modules/SwiftUtils.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ function(get_bootstrapping_swift_lib_dir bs_lib_dir bootstrapping)
115115
# FIXME: This assumes the ABI hasn't changed since the builder.
116116
get_filename_component(swift_bin_dir ${CMAKE_Swift_COMPILER} DIRECTORY)
117117
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
118+
119+
# Detect and handle swiftly-managed hosts.
120+
if(swift_bin_dir MATCHES ".*/swiftly/bin")
121+
execute_process(COMMAND swiftly use --print-location
122+
OUTPUT_VARIABLE swiftly_dir
123+
ERROR_VARIABLE err)
124+
if(err)
125+
message(SEND_ERROR "Failed to find swiftly Swift compiler")
126+
endif()
127+
string(STRIP "${swiftly_dir}" swiftly_dir)
128+
set(swift_dir "${swiftly_dir}/usr")
129+
endif()
130+
118131
set(bs_lib_dir "${swift_dir}/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
119132
endif()
120133
endif()

tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES)
111111
# installed host toolchain.
112112
get_filename_component(swift_bin_dir ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY)
113113
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
114+
115+
# Detect and handle swiftly-managed hosts.
116+
if(swift_bin_dir MATCHES ".*/swiftly/bin")
117+
execute_process(COMMAND swiftly use --print-location
118+
OUTPUT_VARIABLE swiftly_dir
119+
ERROR_VARIABLE err)
120+
if(err)
121+
message(SEND_ERROR "Failed to find swiftly Swift compiler")
122+
endif()
123+
string(STRIP "${swiftly_dir}" swiftly_dir)
124+
set(swift_dir "${swiftly_dir}/usr")
125+
endif()
126+
114127
set(host_lib_dir "${swift_dir}/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
115128
else()
116129
set(host_lib_dir "${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")

0 commit comments

Comments
 (0)