swift-build icon indicating copy to clipboard operation
swift-build copied to clipboard

[sdk] Add "-Xlinker" to linker for Swift projects

Open Steelskin opened this issue 9 months ago • 1 comments
trafficstars

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.

Steelskin avatar Feb 06 '25 20:02 Steelskin

Test run: https://github.com/thebrowsercompany/swift-build/actions/runs/13188123501

Steelskin avatar Feb 06 '25 20:02 Steelskin

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.

Steelskin avatar Aug 29 '25 20:08 Steelskin