Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Steelskin
Copy link
Collaborator

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 Steelskin requested a review from compnerd February 6, 2025 20:25
@Steelskin
Copy link
Collaborator Author

Steelskin commented Feb 6, 2025

@Steelskin Steelskin force-pushed the fabrice/sdk-workaround-cmake-3.30 branch from 53f5fb5 to 84d25da Compare February 6, 2025 20:27
# 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 " "
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if there is a space in a path?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I thought it was possible to get that passed properly. Well, I guess if it's no worse off ...

@Steelskin Steelskin force-pushed the fabrice/sdk-workaround-cmake-3.30 branch from 6566189 to f130b19 Compare February 7, 2025 00:54
@Steelskin Steelskin requested a review from compnerd February 7, 2025 01:02
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 Steelskin force-pushed the fabrice/sdk-workaround-cmake-3.30 branch from f130b19 to e5767fc Compare February 20, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants