-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Fix the swiftCxxStdlib link with explicit module build on Windows #85904
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
Conversation
|
@swift-ci please test |
adc36da to
4ee2161
Compare
|
@swift-ci please test |
| [mainModuleName](StringRef Name) { | ||
| return mainModuleName == Name; | ||
| })) | ||
| if (ScanASTContext.LangOpts.Target.getOS() == llvm::Triple::Win32) |
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 is this scoped to just 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.
To match the IRGenModule code where it's scoped to windows
swift/lib/IRGen/IRGenModule.cpp
Line 1758 in 472937e
| if (Context.LangOpts.Target.getOS() == llvm::Triple::Win32) |
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 is the IRGenModule code scoped to just 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.
I think because the library names differ between static and dynamic on Windows and it needs to know whether it's static or dynamic #67776
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 removed the Windows scoping here
|
I suspect that @egorzhdan might have some thoughts on this as well. Currently, IRGen will inject the CxxStdlib unconditionally, which this mirrors. |
| return mainModuleName == Name; | ||
| })) | ||
| if (ScanASTContext.LangOpts.Target.getOS() == llvm::Triple::Win32) | ||
| mainDependencies.addModuleImport("CxxStdlib", /* isExported */ false, |
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 string literal can be replaced with scanASTContext.Id_CxxStdlib.str()
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.
Done
| break; | ||
| } | ||
|
|
||
| if (ScanASTContext.LangOpts.EnableCXXInterop) { |
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.
Could you please add a comment with a detailed explanation for why Windows behavior differs and why the default flow in
| if (lookupCxxStdLibOverlay) { |
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 (and the IRGenModule code) currently assume that we always link with and add dependency on CxxStdlib if C++ interop is enabled (dynamic or static but it needs to be currently static linking for Windows.) Hence this approach in this PR. But it looks like this lookupCxxStdLibOverlay code doesn't seem to assume that. Do you know why?
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 this code and the lookupCxxStdLibOverlay code are orthogonal. We currently and do always link with CxxStdlib if C++ interop is enabled, dynamic or static. So, we explicitly add CxxStdlib to the (transitive) dependency set by adding a dependency to the main/root module for all platforms but in particular for Windows because it needs to know if it's static or dynamic to determine the correct library name, which this new code does. The lookupCxxStdLibOverlay code differs in that it only adds a CxxStdlib dep if a module depends on the clang std module. We still need the lookupCxxStdLibOverlay code because it affects the direct dependencies of non-root/individual modules (like adding a CxxStdlib dep to what only has a dep on the underlying std module or not adding it to the Darwin module, etc.) as the no-cxx-overlay-for-non-interop-interface.swift test checks.
| [mainModuleName](StringRef Name) { | ||
| return mainModuleName == Name; | ||
| })) | ||
| if (ScanASTContext.LangOpts.Target.getOS() == llvm::Triple::Win32) |
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 is the IRGenModule code scoped to just windows?
We currently support static linking swiftCxxStdlib only on Windows. When C++ interop is enabled but swiftCxxStdlib isn't actually used or only when its underlying std module is used, we incorrectly emitted the dynamic version of the lib name and caused the link error. This change fixes it by always adding it to the dependency. Issue swiftlang#85876
4ee2161 to
f9722f0
Compare
|
@swift-ci please test |
|
well hello again
David Daniel Skoda
…On Mon, Dec 15, 2025 at 13:01 Saleem Abdulrasool ***@***.***> wrote:
***@***.**** approved this pull request.
—
Reply to this email directly, view it on GitHub
<#85904 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/B26S552VZNMVV5RNMH7V73D4B3ZPPAVCNFSM6AAAAACOMWABZ2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTKNZZGQ4DQMZTGQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
We currently support static linking swiftCxxStdlib only on Windows. When C++ interop is enabled but swiftCxxStdlib isn't actually used or only when its underlying std module is used, we incorrectly emitted the dynamic version of the lib name and caused the link error. This change fixes it by always adding it to the dependency.
Issue #85876