-
Notifications
You must be signed in to change notification settings - Fork 199
Distro-overridable default Unix linker #1448
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
Distro-overridable default Unix linker #1448
Conversation
Being able to specify various defaults that the driver should assume is necessary for building specialized distributions of the toolchain. This mostly affects the non-Darwin Unix environment, where folks may be using a whole smorgasbord of different linkers in their toolchain. The original experience made it impossible to generally build the driver to default to a specific linker without editing source, which isn't great. Swift has the challenge of not allowing values assigned to macro definitions though, and neither does SwiftPM. Unless you have some fun with the clang importer, of course :). So we introduce a new DriverDefaults module that really just contains strings that were set as defaults. It seems that that clang importer was unable to import macros directly if they involved more than the literal, so I was unable to use `SWIFT_DEFAULT_LINKER` directly since I want to quote it, but instead have to assign it to an actual value. To configure the default linker while building with SwiftPM, `swift build -Xcc -DSWIFT_DEFAULT_LINKER=lld`, and you will end up with a Swift driver that will default to using lld on Linux.
Yes, the default behavior on windows would be to use the system linker ( The current implementation on Windows uses a I think that I would prefer to avoid this path on Windows in light of the above. |
So does that mean the Windows driver is using
Where do we put that plist? Is it installed next to the driver, or do we need a way to configure it? Or do we embed it in the binary itself and unpack it? I'm not entirely enthusiastic about the idea of a |
It means the tools used when the driver is running on that platform. Toolchain type is selected based on the specified target triple: |
@@ -46,13 +46,18 @@ let package = Package( | |||
.target(name: "CSwiftScan", | |||
exclude: [ "CMakeLists.txt" ]), | |||
|
|||
/// Header containing distribution-configurable defaults. | |||
.target(name: "DriverDefaults", |
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.
We must also implement the building of this module in our CMake build infrastructure.
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.
heh, I thought I put that comment in my draft notes. Yeah, I put up the draft to get feedback on the approach at the moment. :)
Overall I am happy with this approach to defining a build-time constant and for selecting the linker! |
As @artemcm already mentioned, it is platform specific (it is selected by that host that we are building for).
We place that into the platform SDK: |
I don't think the platform SDK should dictate what linker you use. I could build a toolchain that runs on macOS that contains |
The SDK can have content that dictates the linker - I think that the SDK does need to dictate the linker for the platform. |
Rejecting in favor of just using the clang-linker to decide (along with all of its logic for build-time configuration, configuration files, flags, etc...) |
DRAFT NOTES AND QUESTIONS:
I didn't modify the Darwin or Windows paths here. I think it would be a bit confusing if it didn't. That said, I'm a little bit confused about what this "toolchain" means. Is it referring to the tools used when the driver is running on that platform, or when the driver is compiling code for that platform? e.g. if I managed to legally obtain the Windows headers on Linux, would the driver try to use
link.exe
to fail, or would it try to use.. I guessgold
?Being able to specify various defaults that the driver should assume is necessary for building specialized distributions of the toolchain. This mostly affects the non-Darwin Unix environment, where folks may be using a whole smorgasbord of different linkers in their toolchain. The original experience made it impossible to generally build the driver to default to a specific linker without editing source, which isn't great.
Swift has the challenge of not allowing values assigned to macro definitions though, and neither does SwiftPM. Unless you have some fun with the clang importer, of course :). So we introduce a new DriverDefaults module that really just contains strings that were set as defaults. It seems that that clang importer was unable to import macros directly if they involved more than the literal, so I was unable to use
SWIFT_DEFAULT_LINKER
directly since I want to quote it, but instead have to assign it to an actual value.To configure the default linker while building with SwiftPM,
swift build -Xcc -DSWIFT_DEFAULT_LINKER=lld
, and you will end up with a Swift driver that will default to using lld on Linux.