Fix the swiftCxxStdlib link with explicit module build on Windows (#85904)

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 https://github.com/swiftlang/swift/issues/85876
This commit is contained in:
Hiroshi Yamauchi
2025-12-15 14:07:07 -08:00
committed by GitHub
parent fe3200ee19
commit b1058c8952
2 changed files with 60 additions and 0 deletions

View File

@@ -620,6 +620,23 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(ModuleDecl *mainModule) {
break;
}
if (ScanASTContext.LangOpts.EnableCXXInterop) {
StringRef mainModuleName = mainModule->getName().str();
if (mainModuleName != CXX_MODULE_NAME)
mainDependencies.addModuleImport(CXX_MODULE_NAME, /* isExported */ false,
AccessLevel::Public,
&alreadyAddedModules);
if (llvm::none_of(llvm::ArrayRef<StringRef>{CXX_MODULE_NAME,
ScanASTContext.Id_CxxStdlib.str(), "std"},
[mainModuleName](StringRef Name) {
return mainModuleName == Name;
}))
mainDependencies.addModuleImport(ScanASTContext.Id_CxxStdlib.str(),
/* isExported */ false,
AccessLevel::Public,
&alreadyAddedModules);
}
// Add any implicit module names.
for (const auto &import : importInfo.AdditionalUnloadedImports) {
mainDependencies.addModuleImport(