[sdk] Add "-Xlinker" to linker for Swift projects#895
Closed
Conversation
Collaborator
Author
53f5fb5 to
84d25da
Compare
compnerd
reviewed
Feb 6, 2025
| # Worarkound CMake 3.30 issue where CMAKE_[*]_FLAGS are passed as-is to the linker driver. | ||
| # TODO: Once we have CMake 4.0, set CMP0181 to NEW and pass these as "LINKER:" flags. | ||
| $CMAKE_SHARED_LINKER_FLAGS = | ||
| ("${{ matrix.shared_linker_flags }}".Split(" ").Where({ $_.Trim() -ne ''}) | ForEach-Object { "-Xlinker $_" }) -join " " |
Owner
There was a problem hiding this comment.
What happens if there is a space in a path?
Collaborator
Author
There was a problem hiding this comment.
It will break, but it also breaks currently too as CMake also parses the space as a separator. Note that we don't perform any kind of escape for quotes here either.
The good news is that when we switch to CMake 4.0, we'll be able to handle these properly since LINKER: supports comma-separated values.
Owner
There was a problem hiding this comment.
Hmm, I thought it was possible to get that passed properly. Well, I guess if it's no worse off ...
6566189 to
f130b19
Compare
compnerd
approved these changes
Feb 7, 2025
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.
f130b19 to
e5767fc
Compare
Collaborator
Author
|
Abandoning this approach. I have been working on supporting more recent CMake versions in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since CMake 3.30,
CMAKE_[*]_LINKER_FLAGSare passed to the linker invocation as-is. This causes issues in Swift-only projects where the linker invocation isswiftcused as a driver for the actual underlying linker.swiftccannot parse these arguments and fails. As a workaround, this rewrites theshared_linker_flagsandexe_linker_flags, adding-Xlinkerfor each flag, which solves the problem.In the future, CMake 4.0 introduces
CMP0181which will allowCMAKE_[*]_LINKER_FLAGSto interpret theLINKER:prefix and generate the correct linker invocation.