-
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
test/ScanDependencies/win-explicit-cxx-interop-cxxstdlib.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // REQUIRES: OS=windows-msvc | ||
|
|
||
| // RUN: %empty-directory(%t) | ||
| // RUN: split-file %s %t | ||
| // RUN: %target-swift-frontend -scan-dependencies -module-name NoCpp \ | ||
| // RUN: -module-cache-path %t/clang-module-cache -disable-objc-interop \ | ||
| // RUN: -cxx-interoperability-mode=default \ | ||
| // RUN: %t/NoCpp.swift -o %t/NoCpp-deps.json -I %t 2>&1 | ||
| // RUN: %target-swift-frontend -scan-dependencies -module-name Cpp \ | ||
| // RUN: -module-cache-path %t/clang-module-cache -disable-objc-interop \ | ||
| // RUN: -cxx-interoperability-mode=default \ | ||
| // RUN: %t/Cpp.swift -o %t/Cpp-deps.json -I %t 2>&1 | ||
| // RUN: %target-swift-frontend -scan-dependencies -module-name Crt \ | ||
| // RUN: -module-cache-path %t/clang-module-cache -disable-objc-interop \ | ||
| // RUN: -cxx-interoperability-mode=default \ | ||
| // RUN: %t/Crt.swift -o %t/Crt-deps.json -I %t 2>&1 | ||
| // RUN: %FileCheck %s --check-prefix=NOCPP < %t/NoCpp-deps.json | ||
| // RUN: %FileCheck %s --check-prefix=CPP < %t/Cpp-deps.json | ||
| // RUN: %FileCheck %s --check-prefix=CRT < %t/Crt-deps.json | ||
|
|
||
| // NOCPP: "mainModuleName": "NoCpp" | ||
| // NOCPP: "linkName": "swiftCxxStdlib", | ||
| // NOCPP-NEXT: "isStatic": true, | ||
|
|
||
| // CPP: "mainModuleName": "Cpp" | ||
| // CPP: "linkName": "swiftCxxStdlib", | ||
| // CPP-NEXT: "isStatic": true, | ||
|
|
||
| // CRT: "mainModuleName": "Crt" | ||
| // CRT: "linkName": "swiftCxxStdlib", | ||
| // CRT-NEXT: "isStatic": true, | ||
|
|
||
| //--- NoCpp.swift | ||
| // Empty | ||
|
|
||
| //--- Cpp.swift | ||
| import CxxStdlib | ||
|
|
||
| //--- Crt.swift | ||
| import CRT | ||
|
|
||
|
|
||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
swift/lib/DependencyScan/ModuleDependencyScanner.cpp
Line 1618 in a4ae171
Uh oh!
There was an error while loading. Please reload this page.
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
IRGenModulecode) currently assume that we always link with and add dependency onCxxStdlibif 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 thislookupCxxStdLibOverlaycode 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
lookupCxxStdLibOverlaycode 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. ThelookupCxxStdLibOverlaycode differs in that it only adds a CxxStdlib dep if a module depends on the clang std module. We still need thelookupCxxStdLibOverlaycode 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 theno-cxx-overlay-for-non-interop-interface.swifttest checks.