@@ -491,13 +491,32 @@ void IRGenModule::emitSourceFile(SourceFile &SF) {
491491 if (!getSwiftModule ()->getName ().is (" Cxx" ))
492492 this ->addLinkLibrary (LinkLibrary (" swiftCxx" , LibraryKind::Library));
493493
494- // Only link with CxxStdlib on platforms where the overlay is available.
495- // Do not try to link CxxStdlib with itself.
496- if ((target.isOSDarwin () || (target.isOSLinux () && !target.isAndroid ())) &&
497- !getSwiftModule ()->getName ().is (" Cxx" ) &&
498- !getSwiftModule ()->getName ().is (" CxxStdlib" ) &&
499- !getSwiftModule ()->getName ().is (" std" )) {
500- this ->addLinkLibrary (LinkLibrary (" swiftCxxStdlib" , LibraryKind::Library));
494+ // Do not try to link CxxStdlib with the C++ standard library, Cxx or
495+ // itself.
496+ if (llvm::none_of (llvm::ArrayRef{" Cxx" , " CxxStdlib" , " std" },
497+ [M = getSwiftModule ()->getName ().str ()](StringRef Name) {
498+ return M == Name;
499+ })) {
500+ // Only link with CxxStdlib on platforms where the overlay is available.
501+ switch (target.getOS ()) {
502+ case llvm::Triple::Linux:
503+ if (!target.isAndroid ())
504+ this ->addLinkLibrary (LinkLibrary (" swiftCxxStdlib" ,
505+ LibraryKind::Library));
506+ break ;
507+ case llvm::Triple::Win32: {
508+ bool isStatic = Context.getModuleByName (" CxxStdlib" )->isStaticLibrary ();
509+ this ->addLinkLibrary (
510+ LinkLibrary (isStatic ? " libswiftCxxStdlib" : " swiftCxxStdlib" ,
511+ LibraryKind::Library));
512+ break ;
513+ }
514+ default :
515+ if (target.isOSDarwin ())
516+ this ->addLinkLibrary (LinkLibrary (" swiftCxxStdlib" ,
517+ LibraryKind::Library));
518+ break ;
519+ }
501520 }
502521 }
503522
0 commit comments