-
Notifications
You must be signed in to change notification settings - Fork 131
Set linker settings for non-Apple platform when use static swift stdlib #942
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
base: main
Are you sure you want to change the base?
Set linker settings for non-Apple platform when use static swift stdlib #942
Conversation
|
@swift-ci test |
e226a68 to
8d4b214
Compare
|
@swift-ci test |
| args += [sdkPathArgument] | ||
|
|
||
| if !forTAPI { | ||
| if shouldStaticLinkStdlib { |
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.
Curious why we are making changes here if the feature is not supported on macOS?
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'm keeping this here in there event there is a use case I am not aware off, possibly needed for some Apple platforms but not macOS
owenv
left a comment
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.
lgtm aside from the comment about linker drivers
| } else { | ||
| // Non-Apple platforms (Linux, etc.) use static library linking | ||
| // Note: Foundation is not available as a framework on non-Apple platforms | ||
| args += [["-static-stdlib"]] |
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 is only supported when LINKER_DRIVER=swiftc, so we probably need some kind of check for that here
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.
For SwiftPM's usage we probably don't need to attempt to support the option with LINKER_DRIVER=clang right away, we'd have to reimplement some of swift-driver's static stdlib support for that
8d4b214 to
2b57385
Compare
|
@swift-ci test |
|
@swift-ci test windows |
2b57385 to
59268c6
Compare
|
@swift-ci test |
Update the linker settings on non-Apple platforms when use static Swift stdlib is set.
59268c6 to
26f6f8e
Compare
|
@swift-ci test |
| } else { | ||
| switch scope.evaluate(BuiltinMacros.LINKER_DRIVER, lookup: lookup) { | ||
| case .swiftc: | ||
| // Non-Apple platforms (Linux, etc.) use static library linking |
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.
question: Are you certain that all other platforms support this? I'm not certain it is support in Windows, for example because SwiftPM will skip it on Windows.
The native build system in SwiftPM currently only allows this to happen for Linux and 32-bit WASM: https://github.com/swiftlang/swift-package-manager/blob/5547e32a30a8c40cbd6d977f85c62551df6b9eb1/Sources/Build/BuildPlan/BuildPlan.swift#L1361
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.
Statically linked stdlib for Windows is under development by @compnerd.
That said, I'm not sure it's useful to constrain it in the first place, it is just a maintenance burden to try to keep it up to date and would tend to unintentionally block functionality for less common platforms -- e.g. FreeBSD probably supports static stdlib if Linux does, but no one's going to remember to keep such allowlists up to date.
| args += [["-Xlinker", "-force_load_swift_libs"]] | ||
| // The Swift runtime requires libc++ & Foundation. | ||
| args += [["-lc++", "-framework", "Foundation"]] | ||
| // Platform-specific static linking flags |
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.
question: Does this need to be restricted to only executable/snippet target types in some way? The native build system currently only does this for them, and not library products, for example. https://github.com/swiftlang/swift-package-manager/blob/5547e32a30a8c40cbd6d977f85c62551df6b9eb1/Sources/Build/BuildDescription/ProductBuildDescription.swift#L233
Update the linker settings on non-Apple platforms when use static Swift. stdlib is set.
Fixes: swiftlang/swift-package-manager#9320
Issue: rdar://163948614
Depends on #890