Skip to content

Commit 1305901

Browse files
authored
Merge pull request #68161 from compnerd/static-cxx
Cxx: build Cxx module statically on all platforms
2 parents 167aaea + ba9174d commit 1305901

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,15 @@ void IRGenModule::emitSourceFile(SourceFile &SF) {
488488
this->addLinkLibrary(LinkLibrary("stdc++", LibraryKind::Library));
489489

490490
// Do not try to link Cxx with itself.
491-
if (!getSwiftModule()->getName().is("Cxx"))
492-
this->addLinkLibrary(LinkLibrary("swiftCxx", LibraryKind::Library));
491+
if (!getSwiftModule()->getName().is("Cxx")) {
492+
bool isStatic = false;
493+
if (const auto *M = Context.getModuleByName("Cxx"))
494+
isStatic = M->isStaticLibrary();
495+
this->addLinkLibrary(LinkLibrary(target.isOSWindows() && isStatic
496+
? "libswiftCxx"
497+
: "swiftCxx",
498+
LibraryKind::Library));
499+
}
493500

494501
// Do not try to link CxxStdlib with the C++ standard library, Cxx or
495502
// itself.

stdlib/public/Cxx/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake/modules)
22
include(StdlibOptions)
33

4-
set(SWIFT_CXX_LIBRARY_KIND STATIC)
5-
if("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WINDOWS")
6-
set(SWIFT_CXX_LIBRARY_KIND SHARED)
7-
endif()
8-
94
set(SWIFT_CXX_DEPS symlink_clang_headers)
105
if(SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT)
116
list(APPEND SWIFT_CXX_DEPS copy-legacy-layouts)
127
endif()
138

14-
add_swift_target_library(swiftCxx ${SWIFT_CXX_LIBRARY_KIND} NO_LINK_NAME IS_STDLIB IS_SWIFT_ONLY IS_FRAGILE
9+
add_swift_target_library(swiftCxx STATIC NO_LINK_NAME IS_STDLIB IS_SWIFT_ONLY IS_FRAGILE
1510
CxxConvertibleToCollection.swift
1611
CxxDictionary.swift
1712
CxxPair.swift

0 commit comments

Comments
 (0)