From 96042b19ff36174db2572cd26d81f6db5f38d006 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 25 Aug 2023 11:30:33 -0700 Subject: [PATCH 1/3] Cxx: mark as fragile This library is still fragile as C++ Interop is in preview. Mark it as fragile to match cxxStdlib. --- stdlib/public/Cxx/CMakeLists.txt | 2 +- test/Interop/Cxx/class/constructors-copy-irgen-macosx.swift | 2 +- test/Interop/Cxx/class/constructors-irgen-macosx.swift | 2 +- validation-test/SIL/verify_all_overlays.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/public/Cxx/CMakeLists.txt b/stdlib/public/Cxx/CMakeLists.txt index f71de4e37173d..73346e5d2fb18 100644 --- a/stdlib/public/Cxx/CMakeLists.txt +++ b/stdlib/public/Cxx/CMakeLists.txt @@ -11,7 +11,7 @@ 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 +add_swift_target_library(swiftCxx ${SWIFT_CXX_LIBRARY_KIND} NO_LINK_NAME IS_STDLIB IS_SWIFT_ONLY IS_FRAGILE CxxConvertibleToCollection.swift CxxDictionary.swift CxxPair.swift diff --git a/test/Interop/Cxx/class/constructors-copy-irgen-macosx.swift b/test/Interop/Cxx/class/constructors-copy-irgen-macosx.swift index 0c37b25abe99a..776bba5d2ef6f 100644 --- a/test/Interop/Cxx/class/constructors-copy-irgen-macosx.swift +++ b/test/Interop/Cxx/class/constructors-copy-irgen-macosx.swift @@ -1,6 +1,6 @@ // Target-specific tests for C++ copy constructor code generation. -// RUN: %swift -module-name MySwift -target x86_64-apple-macosx10.9 -dump-clang-diagnostics -I %S/Inputs -enable-experimental-cxx-interop -emit-ir %s -parse-stdlib -parse-as-library -disable-legacy-type-info -Xcc -fignore-exceptions | %FileCheck %s -check-prefix=ITANIUM_X64 +// RUN: %swift -module-name MySwift -target x86_64-apple-macosx10.13 -dump-clang-diagnostics -I %S/Inputs -enable-experimental-cxx-interop -emit-ir %s -parse-stdlib -parse-as-library -disable-legacy-type-info -Xcc -fignore-exceptions | %FileCheck %s -check-prefix=ITANIUM_X64 // REQUIRES: OS=macosx // REQUIRES: CPU=x86_64 diff --git a/test/Interop/Cxx/class/constructors-irgen-macosx.swift b/test/Interop/Cxx/class/constructors-irgen-macosx.swift index 2a645e71c6f2e..e45ae171af307 100644 --- a/test/Interop/Cxx/class/constructors-irgen-macosx.swift +++ b/test/Interop/Cxx/class/constructors-irgen-macosx.swift @@ -1,6 +1,6 @@ // Target-specific tests for C++ constructor call code generation. -// RUN: %swift -module-name MySwift -target x86_64-apple-macosx10.9 -dump-clang-diagnostics -I %S/Inputs -enable-experimental-cxx-interop -emit-ir %s -parse-stdlib -parse-as-library -disable-legacy-type-info -Xcc -fignore-exceptions | %FileCheck %s -check-prefix=ITANIUM_X64 +// RUN: %swift -module-name MySwift -target x86_64-apple-macosx10.13 -dump-clang-diagnostics -I %S/Inputs -enable-experimental-cxx-interop -emit-ir %s -parse-stdlib -parse-as-library -disable-legacy-type-info -Xcc -fignore-exceptions | %FileCheck %s -check-prefix=ITANIUM_X64 // REQUIRES: OS=macosx // REQUIRES: CPU=x86_64 diff --git a/validation-test/SIL/verify_all_overlays.py b/validation-test/SIL/verify_all_overlays.py index d4b6a15083db8..a29a9cd1ce2ff 100755 --- a/validation-test/SIL/verify_all_overlays.py +++ b/validation-test/SIL/verify_all_overlays.py @@ -28,7 +28,7 @@ continue # Skip the C++ standard library overlay because it's not yet shipped # in any released SDK. - if module_name == "CxxStdlib": + if module_name in ("Cxx", "CxxStdlib"): continue # TODO(TF-1229): Fix the "_Differentiation" module. if module_name == "_Differentiation": From 82b4aa5004cc1bf19a62f2aba0f37d2fd169c15c Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sun, 27 Aug 2023 09:49:31 -0700 Subject: [PATCH 2/3] Cxx: build Cxx module statically on all platforms This adjusts Cxx to be built statically on all platforms including Windows. The static library support is sufficient to support this module linking statically on Windows. --- lib/IRGen/GenDecl.cpp | 11 +++++++++-- stdlib/public/Cxx/CMakeLists.txt | 7 +------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index 18b233751c226..c3b65de0d0c6b 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -487,8 +487,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. diff --git a/stdlib/public/Cxx/CMakeLists.txt b/stdlib/public/Cxx/CMakeLists.txt index 73346e5d2fb18..8cc6453799ed3 100644 --- a/stdlib/public/Cxx/CMakeLists.txt +++ b/stdlib/public/Cxx/CMakeLists.txt @@ -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 From 84a9733d500899836da42d2f61dcb678c822cc98 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 30 Aug 2023 15:08:19 -0700 Subject: [PATCH 3/3] Update CMakeLists.txt Remove flag that is unsupported on 5.9 --- stdlib/public/Cxx/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/public/Cxx/CMakeLists.txt b/stdlib/public/Cxx/CMakeLists.txt index 8cc6453799ed3..f211f7594ad72 100644 --- a/stdlib/public/Cxx/CMakeLists.txt +++ b/stdlib/public/Cxx/CMakeLists.txt @@ -6,7 +6,7 @@ if(SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT) list(APPEND SWIFT_CXX_DEPS copy-legacy-layouts) endif() -add_swift_target_library(swiftCxx STATIC NO_LINK_NAME IS_STDLIB IS_SWIFT_ONLY IS_FRAGILE +add_swift_target_library(swiftCxx STATIC NO_LINK_NAME IS_STDLIB IS_SWIFT_ONLY CxxConvertibleToCollection.swift CxxDictionary.swift CxxPair.swift