-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Swift SDKs: fix toolset.linker.path
not passed to -ld-path
#6719
Conversation
var swiftCompilerFlags = destination.toolset.knownTools[.swiftCompiler]?.extraCLIOptions ?? [] | ||
|
||
if let linker = destination.toolset.knownTools[.linker]?.path { | ||
swiftCompilerFlags += ["-use-ld=\(linker.pathString)"] |
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.
cc @compnerd could this interfere with the use-ld
check that's used to infer the librarian on Windows? Specifically, this uses an absolute path rather than just the name — so maybe determineLibrarian
should just look at the last path component?
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.
Does -use-ld=
support absolute paths? If so, yes, this would need to have an associated change to the testing for the librarian check for Windows. Additionally, I think that you should be using linker._nativePathString(escaped: false)
here ... to ensure that we actually test with the proper path on windows, e.g. -use-ld=C:\Program Files\Swift\Toolchain\0.0.0+Asserts\usr\bin\lld-link.exe
. Note the space in the path and the use of \
.
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.
If #6730 is merged _nativePathString(escaped: false)
will be applied automatically in that string interpolation.
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.
Does -use-ld= support absolute paths?
It does on macOS. As we assume we're always passing this to Clang, wouldn't Clang on Windows maintain this support for consistency?
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 it looks like passing a path to -fuse-ld
is supported but not recommended: https://github.com/apple/llvm-project/blob/1604b03867ff8c0ece77a61d16e3f609e3cfcb3c/clang/lib/Driver/ToolChain.cpp#L820
The correct flag expected by the clang driver seems to be --ld-path
. Will switch to that instead.
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.
This raises another question though: should we attempt to derive the linker flavor based on linker.path
? Or should we just pass --ld-path
and allow SDK vendors to specify the flavor via extraCLIArguments
if they wish?
@swift-ci smoke test |
toolset.linker.path
@swift-ci smoke test |
@swift-ci test windows |
toolset.linker.path
toolset.linker.path
not passed to -use-ld
I need to test these changes with some Swift SDKs I have generated locally, and then assuming that goes well it can be merged. |
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.
Just ran end-to-end tests on my side with this change, working well. Good stuff, thanks for cleaning it up!
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.
Please account for the absolute path in the librarian checks in Windows.
@compnerd what would the appropriate API for extracting the last path component from an absolute-or-relative path be? I'm assuming we don't want to use Foundation.URL here |
Note that a deserialized Although I then have another question, how exactly would you use this last path component? If Clang on Windows supports absolute paths (with spaces and all, quoted if needed), then wouldn't we prefer to always use absolute paths here and not deal with relative ones at all? |
my bad, I think my comment was a bit vague: we should be fine on L334 because we already have an |
It doesn't look like |
The concern is the other way around: |
It's likely to be @compnerd would using |
Switching to |
This PR introduces an `--ld-path` option, which is forwarded to the Clang linker-driver option with the same name. This change is required to support the `toolset.linker.path` option in [SE-0387](https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md). ## See also Upstream: swiftlang/swift#67956. Downstream: swiftlang/swift-package-manager#6719.
This PR defines an `--ld-path` option for the Swift Driver, which is forwarded to the Clang linker-driver option with the same name. This change is required to support the `toolset.linker.path` option in [SE-0387](https://github.com/apple/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md). ## See Also Downstream: swiftlang/swift-driver#1416, swiftlang/swift-package-manager#6719.
@swift-ci smoke test |
@swift-ci test windows |
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.
Thanks, sorry about the delay. This LGTM!
@swift-ci test windows |
@compnerd mind taking a look at this again please? I think I've addressed the changes that you requested — it should be possible to merge this PR once you approve. |
var swiftCompilerFlags = swiftSDK.toolset.knownTools[.swiftCompiler]?.extraCLIOptions ?? [] | ||
|
||
if let linker = swiftSDK.toolset.knownTools[.linker]?.path { | ||
swiftCompilerFlags += ["--ld-path=\(linker)"] |
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.
Why not use -use-ld=\(linker)
here? I'd really rather not introduce new spellings for existing functionality.
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.
@kabiroberai I had a chat about this offline and we landed on -ld-path
, I've submitted follow up PRs for that:
swiftlang/swift#68495
swiftlang/swift-driver#1441
There's a still a question what happens when both options are passed as -use-ld=silly-linker -ld-path=/usr/bin/funny-linker
. We also need a test to verify that, whatever behavior is when both of those options are passed, it doesn't regress.
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.
thanks for handling the upstream side of things! I believe -use-ld
and -ld-path
are (mostly) orthogonal but I see how that could regress; that test would be best suited to swift-driver right?
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.
Yes, tests for this are more appropriate in Swift Driver I believe. cc @artemcm
Upstream dependencies: swiftlang/swift#68495 swiftlang/swift-driver#1441
Head branch was pushed to by a user without write access
@swift-ci test |
@swift-ci test windows |
toolset.linker.path
not passed to --ld-path
toolset.linker.path
not passed to -ld-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.
I think that we should really follow up on this to determine the best way forward for the flags. It is unclear how -ld-path=
and -use-ld=
compose and feels like this is something we should be paying attention to. We should aim to avoid the mistakes of the gcc driver.
Looks like this broke existing Swift SDKs:
@tomerd suggested to revert, I'll open a PR for that. |
#6719)" This reverts commit d328002. This broke existing Swift SDKs: ``` ld.lld: error: unable to find library -ld-path=/Users/neonacho/Library/org.swift.swiftpm/swift-sdks/5.8-RELEASE_rhel_ubi9_aarch64.artifactbundle/5.8-RELEASE_rhel_ubi9_aarch64/aarch64-unknown-linux-gnu/swift.xctoolchain/usr/bin/ld.lld ```
#6719)" (#6939) This reverts commit d328002. This broke existing Swift SDKs: ``` ld.lld: error: unable to find library -ld-path=/Users/neonacho/Library/org.swift.swiftpm/swift-sdks/5.8-RELEASE_rhel_ubi9_aarch64.artifactbundle/5.8-RELEASE_rhel_ubi9_aarch64/aarch64-unknown-linux-gnu/swift.xctoolchain/usr/bin/ld.lld ```
…-ld-path` (swiftlang#6719)" (swiftlang#6939)" This reverts commit 57d0a55.
This PR implements support for the `linker.path` field in the Swift SDK toolset spec. Depends on swiftlang/swift#68495 and swiftlang/swift-driver#1441. ### Motivation: This field was previously parsed but not respected. ### Modifications: Add `-ld-path=\(linker.path)` to the toolchain's Swift flags if a linker path override is supplied ### Result: The linker path is now respected.
#6719)" (#6939) This reverts commit d328002. This broke existing Swift SDKs: ``` ld.lld: error: unable to find library -ld-path=/Users/neonacho/Library/org.swift.swiftpm/swift-sdks/5.8-RELEASE_rhel_ubi9_aarch64.artifactbundle/5.8-RELEASE_rhel_ubi9_aarch64/aarch64-unknown-linux-gnu/swift.xctoolchain/usr/bin/ld.lld ```
This PR implements support for the `linker.path` field in the Swift SDK toolset spec. Depends on swiftlang/swift#68495 and swiftlang/swift-driver#1441. ### Motivation: This field was previously parsed but not respected. ### Modifications: Add `-ld-path=\(linker.path)` to the toolchain's Swift flags if a linker path override is supplied ### Result: The linker path is now respected.
#6719)" (#6939) This reverts commit d328002. This broke existing Swift SDKs: ``` ld.lld: error: unable to find library -ld-path=/Users/neonacho/Library/org.swift.swiftpm/swift-sdks/5.8-RELEASE_rhel_ubi9_aarch64.artifactbundle/5.8-RELEASE_rhel_ubi9_aarch64/aarch64-unknown-linux-gnu/swift.xctoolchain/usr/bin/ld.lld ```
This PR implements support for the
linker.path
field in the Swift SDK toolset spec.Depends on swiftlang/swift#68495 and swiftlang/swift-driver#1441.
Motivation:
This field was previously parsed but not respected.
Modifications:
Add
-ld-path=\(linker.path)
to the toolchain's Swift flags if a linker path override is suppliedResult:
The linker path is now respected.