Skip to content

Cxx: build Cxx module statically on all platforms #68161

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 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,15 @@ void IRGenModule::emitSourceFile(SourceFile &SF) {
this->addLinkLibrary(LinkLibrary("stdc++", LibraryKind::Library));

// Do not try to link Cxx with itself.
if (!getSwiftModule()->getName().is("Cxx"))
this->addLinkLibrary(LinkLibrary("swiftCxx", LibraryKind::Library));
if (!getSwiftModule()->getName().is("Cxx")) {
bool isStatic = false;
if (const auto *M = Context.getModuleByName("Cxx"))
isStatic = M->isStaticLibrary();
this->addLinkLibrary(LinkLibrary(target.isOSWindows() && isStatic
? "libswiftCxx"
: "swiftCxx",
LibraryKind::Library));
}

// Do not try to link CxxStdlib with the C++ standard library, Cxx or
// itself.
Expand Down
7 changes: 1 addition & 6 deletions stdlib/public/Cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake/modules)
include(StdlibOptions)

set(SWIFT_CXX_LIBRARY_KIND STATIC)
if("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WINDOWS")
set(SWIFT_CXX_LIBRARY_KIND SHARED)
endif()

set(SWIFT_CXX_DEPS symlink_clang_headers)
if(SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT)
list(APPEND SWIFT_CXX_DEPS copy-legacy-layouts)
endif()

add_swift_target_library(swiftCxx ${SWIFT_CXX_LIBRARY_KIND} NO_LINK_NAME IS_STDLIB IS_SWIFT_ONLY IS_FRAGILE
add_swift_target_library(swiftCxx STATIC NO_LINK_NAME IS_STDLIB IS_SWIFT_ONLY IS_FRAGILE
CxxConvertibleToCollection.swift
CxxDictionary.swift
CxxPair.swift
Expand Down