-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(windows): align static Foundation autolinks #5525
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?
Changes from all commits
12271eb
0243902
2d06f93
fcd833c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,8 +58,19 @@ target_link_libraries(FoundationNetworking | |
| if(NOT BUILD_SHARED_LIBS) | ||
| target_compile_options(FoundationNetworking PRIVATE | ||
| "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend _CFURLSessionInterface>") | ||
| target_compile_options(FoundationNetworking PRIVATE | ||
| "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend curl>") | ||
|
|
||
| # The Windows SDK's curl uses Schannel, zlib, and Brotli. The static Linux | ||
| # SDK's curl uses OpenSSL and zlib, which BUILD_FULLY_STATIC supplies below. | ||
| if(CMAKE_SYSTEM_NAME STREQUAL "Windows") | ||
| target_compile_options(FoundationNetworking PRIVATE | ||
| "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend libcurl>" | ||
| "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend zlibstatic>" | ||
| "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend brotlicommon>" | ||
| "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend brotlidec>") | ||
| else() | ||
| target_compile_options(FoundationNetworking PRIVATE | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why doesn't Linux need the extra auto linked libraries as well? The dependencies should be the same between Linux/Windows so I wouldn't expect anything to be windows specific here (except for maybe the name of the library if windows uses a different prefix for example)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Windows SDK builds and packages a static curl archive with zlib and Brotli enabled, but those archive dependencies are not encoded in its autolink metadata. Linux normally resolves the shared curl target and its dynamic dependencies; the existing
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think this is true - the static Linux SDK includes a
I don't think the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You are right about the underlying mechanism and my earlier comment conflated archive naming with linkage mode. On Unix, I checked the published Swift 6.3.3 Static Linux SDK and the latest main snapshot from 2026-07-11 for both x86_64 and aarch64. In all four configurations:
The generated autolink file contains Windows uses a different curl configuration: Schannel, zlib and Brotli. Its observed unresolved symbols are exactly the zlib and Brotli set. Therefore the platform-specific lists are intentional: Windows needs
I agree that The cross-repository full static SDK build @compnerd requested remains the final integration check. My |
||
| "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend curl>") | ||
| endif() | ||
| target_compile_options(FoundationNetworking PRIVATE | ||
| "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend $<$<PLATFORM_ID:Windows>:${CMAKE_STATIC_LIBRARY_PREFIX_Swift}>swiftSynchronization>") | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,8 +33,13 @@ target_link_libraries(FoundationXML | |
| if(NOT BUILD_SHARED_LIBS) | ||
| target_compile_options(FoundationXML PRIVATE | ||
| "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend _CFXMLInterface>") | ||
| target_compile_options(FoundationXML PRIVATE | ||
| "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend xml2>") | ||
| if(CMAKE_SYSTEM_NAME STREQUAL "Windows") | ||
| target_compile_options(FoundationXML PRIVATE | ||
| "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend libxml2s>") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that this might be
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I rechecked the installed SDK and the emitted directive. Both the x86_64 and ARM64 slices of the pinned WindowsExperimental SDK contain libxml2s.lib. Neither contains xml2s.lib or xml2.lib The autolink argument is literal on Windows apart from the .lib suffix. The previous xml2 entry emitted Are you seeing xml2s.lib in a different build-tree or SDK artifact? Could you please point me to it? Thanks! |
||
| else() | ||
| target_compile_options(FoundationXML PRIVATE | ||
| "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend xml2>") | ||
| endif() | ||
| target_compile_options(FoundationXML PRIVATE | ||
| "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend $<$<PLATFORM_ID:Windows>:${CMAKE_STATIC_LIBRARY_PREFIX_Swift}>swiftSynchronization>") | ||
|
|
||
|
|
||
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 don't understand why the name changes here. It worked as curl there? That said the rename is likely better as the name is supposed to be the actual name on disk.
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.
The CMake path emitted an autolink for
curl, which requestscurl.lib, while the Windows static SDK packages the archive aslibcurl.lib. A minimalFoundationNetworkingexecutable therefore failed with LNK1104. The package manifest already nameslibcurl.lib, so this makes the CMake build match the working SwiftPM configuration.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.
Right, but I mean, how has this been working? I suppose that this fix is for outside the CMake build as the curl target in CMake already points to the static library.
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.
Yeah, exactly. This change is for consumers of the installed static SDK that are outside the CMake target graph. In the in-tree build
_CFURLSessionInterfacelinksCURL::libcurlso final CMake targets resolve the imported target to the static archive and its link interface.An external swiftc consumer cannot see that CMake target. It only sees the
-public-autolink-librarymetadata embedded in the installed Swift module. On Windows those entries become/DEFAULTLIB:<name>.lib, so the names must match the SDK’s packaged files and the static curl dependencies must be listed explicitly. These directives are emitted only under NOT BUILD_SHARED_LIBS which is why the installed static-SDK reproducer exposed the problem