-
Notifications
You must be signed in to change notification settings - Fork 53
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
base: main
Are you sure you want to change the base?
Conversation
53f5fb5
to
84d25da
Compare
# 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 " " |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ...
6566189
to
f130b19
Compare
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
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 isswiftc
used as a driver for the actual underlying linker.swiftc
cannot parse these arguments and fails. As a workaround, this rewrites theshared_linker_flags
andexe_linker_flags
, adding-Xlinker
for each flag, which solves the problem.In the future, CMake 4.0 introduces
CMP0181
which will allowCMAKE_[*]_LINKER_FLAGS
to interpret theLINKER:
prefix and generate the correct linker invocation.