swift-build
swift-build copied to clipboard
[sdk] Add "-Xlinker" to linker for Swift projects
Since CMake 3.30, CMAKE_[*]_LINKER_FLAGS are passed to the linker invocation as-is. This causes issues in Swift-only projects where the linker invocation is swiftc used as a driver for the actual underlying linker. swiftc cannot parse these arguments and fails. As a workaround, this rewrites the shared_linker_flags and exe_linker_flags, adding -Xlinker for each flag, which solves the problem.
In the future, CMake 4.0 introduces CMP0181 which will allow CMAKE_[*]_LINKER_FLAGS to interpret the LINKER: prefix and generate the correct linker invocation.
Test run: https://github.com/thebrowsercompany/swift-build/actions/runs/13188123501
Abandoning this approach. I have been working on supporting more recent CMake versions in build.ps1 upstream and these changes will eventually roll into the new Configure CMake action.