Skip to content

Conversation

@bkhouri
Copy link
Contributor

@bkhouri bkhouri commented Nov 25, 2025

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

@bkhouri
Copy link
Contributor Author

bkhouri commented Nov 25, 2025

@swift-ci test

@bkhouri bkhouri force-pushed the t/main/gh9320_rdar163948614_add_swift-static-stdlib_support branch from e226a68 to 8d4b214 Compare November 25, 2025 21:24
@bkhouri
Copy link
Contributor Author

bkhouri commented Nov 25, 2025

@swift-ci test

args += [sdkPathArgument]

if !forTAPI {
if shouldStaticLinkStdlib {
Copy link
Contributor

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?

Copy link
Contributor Author

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

@bkhouri bkhouri requested a review from rconnell9 December 1, 2025 14:39
Copy link
Collaborator

@owenv owenv left a 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"]]
Copy link
Collaborator

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

Copy link
Collaborator

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

@bkhouri bkhouri force-pushed the t/main/gh9320_rdar163948614_add_swift-static-stdlib_support branch from 8d4b214 to 2b57385 Compare December 3, 2025 03:43
@bkhouri
Copy link
Contributor Author

bkhouri commented Dec 3, 2025

@swift-ci test

@bkhouri
Copy link
Contributor Author

bkhouri commented Dec 3, 2025

@swift-ci test windows

@bkhouri bkhouri force-pushed the t/main/gh9320_rdar163948614_add_swift-static-stdlib_support branch from 2b57385 to 59268c6 Compare December 3, 2025 19:30
@bkhouri
Copy link
Contributor Author

bkhouri commented Dec 3, 2025

@swift-ci test

Update the linker settings on non-Apple platforms when use static Swift
stdlib is set.
@bkhouri bkhouri force-pushed the t/main/gh9320_rdar163948614_add_swift-static-stdlib_support branch from 59268c6 to 26f6f8e Compare December 3, 2025 19:31
@bkhouri
Copy link
Contributor Author

bkhouri commented Dec 3, 2025

@swift-ci test

} else {
switch scope.evaluate(BuiltinMacros.LINKER_DRIVER, lookup: lookup) {
case .swiftc:
// Non-Apple platforms (Linux, etc.) use static library linking
Copy link
Member

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

Copy link
Collaborator

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
Copy link
Member

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

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.

[Parity] Add parity support for --[no-]static-swift-stdlib support (SwiftBuild)

5 participants