Skip to content

Commit f842782

Browse files
committed
[SR-15135] Copy over early swift-driver executable to the build dir instead of creating a symlink
The SwiftDriver searches `swift-frontend` based on `Bundle.main.executablePath` (which internally uses `CFGetProcessPath`). This search dir is resolved differently on macOS and Linux so swift-frontend can't be found on Linux, forcing the driver to fallback to using the host system toolchain instead of the just-built one.
1 parent c2fd49c commit f842782

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

cmake/modules/SwiftUtils.cmake

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ endfunction()
207207
# Once swift-frontend is built, if the standalone (early) swift-driver has been built,
208208
# we create a `swift-driver` symlink adjacent to the `swift` and `swiftc` executables
209209
# to ensure that `swiftc` forwards to the standalone driver when invoked.
210-
function(swift_create_early_driver_symlinks target)
210+
function(swift_create_early_driver_copies target)
211211
# Early swift-driver is built adjacent to the compiler (swift build dir)
212212
set(driver_bin_dir "${CMAKE_BINARY_DIR}/../earlyswiftdriver-${SWIFT_HOST_VARIANT}-${SWIFT_HOST_VARIANT_ARCH}/release/bin")
213213
set(swift_bin_dir "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
@@ -217,20 +217,18 @@ function(swift_create_early_driver_symlinks target)
217217
return()
218218
endif()
219219

220-
message(STATUS "Creating early SwiftDriver symlinks.")
220+
message(STATUS "Copying over early SwiftDriver executable.")
221221
message(STATUS "From: ${driver_bin_dir}/swift-driver")
222222
message(STATUS "To: ${swift_bin_dir}/swift-driver")
223-
swift_create_post_build_symlink(swift-frontend
224-
SOURCE "${driver_bin_dir}/swift-driver"
225-
DESTINATION "${swift_bin_dir}/swift-driver"
226-
COMMENT "Creating early SwiftDriver symlinks: swift-driver")
223+
# Use configure_file instead of file(COPY...) to establish a dependency.
224+
# Further Changes to `swift-driver` will cause it to be copied over.
225+
configure_file(${driver_bin_dir}/swift-driver ${swift_bin_dir}/swift-driver COPYONLY)
227226

228227
message(STATUS "From: ${driver_bin_dir}/swift-help")
229228
message(STATUS "To: ${swift_bin_dir}/swift-help")
230-
swift_create_post_build_symlink(swift-frontend
231-
SOURCE "${driver_bin_dir}/swift-help"
232-
DESTINATION "${swift_bin_dir}/swift-help"
233-
COMMENT "Creating early SwiftDriver symlinks: swift-help")
229+
# Use configure_file instead of file(COPY...) to establish a dependency.
230+
# Further Changes to `swift-driver` will cause it to be copied over.
231+
configure_file(${driver_bin_dir}/swift-help ${swift_bin_dir}/swift-help COPYONLY)
234232
endfunction()
235233

236234
function(dump_swift_vars)

tools/driver/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ target_link_libraries(swift-frontend
5252
swiftDriverTool
5353
libswift)
5454

55-
# Create a `swift-driver` symlinks adjacent to the `swift-frontend` executable
55+
# Create a `swift-driver` executable adjacent to the `swift-frontend` executable
5656
# to ensure that `swiftc` forwards to the standalone driver when invoked.
57-
swift_create_early_driver_symlinks(swift-frontend)
57+
swift_create_early_driver_copies(swift-frontend)
5858

5959
swift_create_post_build_symlink(swift-frontend
6060
SOURCE "swift-frontend${CMAKE_EXECUTABLE_SUFFIX}"

0 commit comments

Comments
 (0)