From 87646b4649fd1eb124d606c69fce99dc8960c726 Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Mon, 23 Sep 2024 07:06:42 -0400 Subject: [PATCH 01/11] Enable the projection build with CMake --- Generator/InteropTests/WinRTComponent/CMakeLists.txt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Generator/InteropTests/WinRTComponent/CMakeLists.txt b/Generator/InteropTests/WinRTComponent/CMakeLists.txt index b85c7e5..a821eac 100644 --- a/Generator/InteropTests/WinRTComponent/CMakeLists.txt +++ b/Generator/InteropTests/WinRTComponent/CMakeLists.txt @@ -42,7 +42,6 @@ ExternalProject_Add(WinRTComponent TEST_COMMAND "") # Define the projection build -# TODO(https://github.com/tristanlabelle/swift-winrt/issues/302): Fix linking issues -# add_subdirectory( -# ${CMAKE_CURRENT_BINARY_DIR}/Projection/Sources -# ${CMAKE_CURRENT_BINARY_DIR}/Projection/Build) \ No newline at end of file +add_subdirectory( + "${PROJECTION_DIR}" + "${CMAKE_CURRENT_BINARY_DIR}/Projection/Build") \ No newline at end of file From 4a7baa8ffc44d58f400d092e7882dcea2631b70a Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Mon, 23 Sep 2024 07:38:35 -0400 Subject: [PATCH 02/11] Try to fix linker errors --- Generator/Sources/SwiftWinRT/writeProjectionFiles.swift | 5 +++++ Package.swift | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift b/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift index ab8e3ae..a97065d 100644 --- a/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift +++ b/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift @@ -106,6 +106,11 @@ fileprivate func writeSwiftModuleFiles(_ module: Module, directoryPath: String, writer.writeSingleLineCommand( "set_target_properties", .autoquote(targetName), "PROPERTIES", "Swift_MODULE_NAME", .autoquote(module.name)) + // Workaround CMake error with mismatching module names: + // "CMake can not determine linker language for target: " + writer.writeSingleLineCommand( + "set_target_properties", .autoquote(targetName), + "PROPERTIES", "LINKER_LANGUAGE", "Swift") } writer.writeTargetLinkLibraries(targetName, .public, [ cmakeOptions.getTargetName(moduleName: module.abiModuleName), SupportModules.WinRT.moduleName ] diff --git a/Package.swift b/Package.swift index 941293e..e9d73fc 100644 --- a/Package.swift +++ b/Package.swift @@ -9,7 +9,7 @@ let package = Package( targets: ["COM_ABI", "WindowsRuntime_ABI"]), .library( name: "WindowsRuntime", - targets: ["COM", "WindowsRuntime"]), + targets: ["ABIBindings", "COM", "WindowsRuntime"]), ], targets: [ .target( From 8fa1358a5c41fef5f1b91b5c75f13932ce81c60d Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Mon, 23 Sep 2024 07:48:59 -0400 Subject: [PATCH 03/11] More explicit LINKER_LANGUAGE properties --- Generator/Sources/SwiftWinRT/writeProjectionFiles.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift b/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift index a97065d..4815985 100644 --- a/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift +++ b/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift @@ -141,8 +141,13 @@ fileprivate func writeNamespaceModuleFiles(_ module: Module, directoryPath: Stri writer.writeAddLibrary(targetName, .static, ["Aliases.swift"]) if targetName != namespaceModuleName { writer.writeSingleLineCommand( - "set_target_properties", .unquoted(targetName), - "PROPERTIES", "Swift_MODULE_NAME", .unquoted(namespaceModuleName)) + "set_target_properties", .autoquote(targetName), + "PROPERTIES", "Swift_MODULE_NAME", .autoquote(namespaceModuleName)) + // Workaround CMake error with mismatching module names: + // "CMake can not determine linker language for target: " + writer.writeSingleLineCommand( + "set_target_properties", .autoquote(targetName), + "PROPERTIES", "LINKER_LANGUAGE", "Swift") } writer.writeTargetLinkLibraries(targetName, .public, [ cmakeOptions.getTargetName(moduleName: module.name) ]) } From c2e754f4655ec683ab8cd4b88a26ab670ab7e107 Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Wed, 25 Sep 2024 21:53:20 -0400 Subject: [PATCH 04/11] Fix generator subproject build --- Support/Sources/WindowsRuntime/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Support/Sources/WindowsRuntime/CMakeLists.txt b/Support/Sources/WindowsRuntime/CMakeLists.txt index 8f8213e..fb1e697 100644 --- a/Support/Sources/WindowsRuntime/CMakeLists.txt +++ b/Support/Sources/WindowsRuntime/CMakeLists.txt @@ -1,4 +1,7 @@ file(GLOB_RECURSE SOURCES *.swift) add_library(WindowsRuntime STATIC ${SOURCES}) target_link_libraries(WindowsRuntime PUBLIC COM WindowsRuntime_ABI) -target_link_libraries(WindowsRuntime PRIVATE SWRT_InternalABI) \ No newline at end of file +target_link_libraries(WindowsRuntime PRIVATE SWRT_InternalABI) + +# Workaround for CMake not propagating include dirs +target_include_directories(WindowsRuntime INTERFACE "$") \ No newline at end of file From 0d28f0390123e51d8992e0715aa647d72f07002e Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Fri, 27 Sep 2024 05:37:11 -0400 Subject: [PATCH 05/11] Comment out attempts --- Generator/InteropTests/WinRTComponent/CMakeLists.txt | 4 +--- .../Sources/SwiftWinRT/writeProjectionFiles.swift | 12 ++++++------ Support/Sources/WindowsRuntime/CMakeLists.txt | 3 ++- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Generator/InteropTests/WinRTComponent/CMakeLists.txt b/Generator/InteropTests/WinRTComponent/CMakeLists.txt index a821eac..9d7b91d 100644 --- a/Generator/InteropTests/WinRTComponent/CMakeLists.txt +++ b/Generator/InteropTests/WinRTComponent/CMakeLists.txt @@ -42,6 +42,4 @@ ExternalProject_Add(WinRTComponent TEST_COMMAND "") # Define the projection build -add_subdirectory( - "${PROJECTION_DIR}" - "${CMAKE_CURRENT_BINARY_DIR}/Projection/Build") \ No newline at end of file +add_subdirectory("${PROJECTION_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/Projection/Build") \ No newline at end of file diff --git a/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift b/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift index 4815985..9b2569b 100644 --- a/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift +++ b/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift @@ -108,9 +108,9 @@ fileprivate func writeSwiftModuleFiles(_ module: Module, directoryPath: String, "PROPERTIES", "Swift_MODULE_NAME", .autoquote(module.name)) // Workaround CMake error with mismatching module names: // "CMake can not determine linker language for target: " - writer.writeSingleLineCommand( - "set_target_properties", .autoquote(targetName), - "PROPERTIES", "LINKER_LANGUAGE", "Swift") + // writer.writeSingleLineCommand( + // "set_target_properties", .autoquote(targetName), + // "PROPERTIES", "LINKER_LANGUAGE", "Swift") } writer.writeTargetLinkLibraries(targetName, .public, [ cmakeOptions.getTargetName(moduleName: module.abiModuleName), SupportModules.WinRT.moduleName ] @@ -145,9 +145,9 @@ fileprivate func writeNamespaceModuleFiles(_ module: Module, directoryPath: Stri "PROPERTIES", "Swift_MODULE_NAME", .autoquote(namespaceModuleName)) // Workaround CMake error with mismatching module names: // "CMake can not determine linker language for target: " - writer.writeSingleLineCommand( - "set_target_properties", .autoquote(targetName), - "PROPERTIES", "LINKER_LANGUAGE", "Swift") + // writer.writeSingleLineCommand( + // "set_target_properties", .autoquote(targetName), + // "PROPERTIES", "LINKER_LANGUAGE", "Swift") } writer.writeTargetLinkLibraries(targetName, .public, [ cmakeOptions.getTargetName(moduleName: module.name) ]) } diff --git a/Support/Sources/WindowsRuntime/CMakeLists.txt b/Support/Sources/WindowsRuntime/CMakeLists.txt index fb1e697..49f5d0b 100644 --- a/Support/Sources/WindowsRuntime/CMakeLists.txt +++ b/Support/Sources/WindowsRuntime/CMakeLists.txt @@ -4,4 +4,5 @@ target_link_libraries(WindowsRuntime PUBLIC COM WindowsRuntime_ABI) target_link_libraries(WindowsRuntime PRIVATE SWRT_InternalABI) # Workaround for CMake not propagating include dirs -target_include_directories(WindowsRuntime INTERFACE "$") \ No newline at end of file +# target_include_directories(WindowsRuntime INTERFACE "$") +# target_include_directories(WindowsRuntime INTERFACE "$") \ No newline at end of file From d8e909a08fdf0750eed44b1d7a88f28e3e3cf41e Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Tue, 1 Oct 2024 21:59:31 -0400 Subject: [PATCH 06/11] Remove bad workarounds and add good ones --- .../Sources/SwiftWinRT/writeProjectionFiles.swift | 10 ---------- Support/Sources/ABIBindings/CMakeLists.txt | 4 +++- Support/Sources/COM/COMEmbedding.swift | 3 ++- Support/Sources/WindowsRuntime/CMakeLists.txt | 4 ---- 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift b/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift index 9b2569b..ebc3ad9 100644 --- a/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift +++ b/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift @@ -106,11 +106,6 @@ fileprivate func writeSwiftModuleFiles(_ module: Module, directoryPath: String, writer.writeSingleLineCommand( "set_target_properties", .autoquote(targetName), "PROPERTIES", "Swift_MODULE_NAME", .autoquote(module.name)) - // Workaround CMake error with mismatching module names: - // "CMake can not determine linker language for target: " - // writer.writeSingleLineCommand( - // "set_target_properties", .autoquote(targetName), - // "PROPERTIES", "LINKER_LANGUAGE", "Swift") } writer.writeTargetLinkLibraries(targetName, .public, [ cmakeOptions.getTargetName(moduleName: module.abiModuleName), SupportModules.WinRT.moduleName ] @@ -143,11 +138,6 @@ fileprivate func writeNamespaceModuleFiles(_ module: Module, directoryPath: Stri writer.writeSingleLineCommand( "set_target_properties", .autoquote(targetName), "PROPERTIES", "Swift_MODULE_NAME", .autoquote(namespaceModuleName)) - // Workaround CMake error with mismatching module names: - // "CMake can not determine linker language for target: " - // writer.writeSingleLineCommand( - // "set_target_properties", .autoquote(targetName), - // "PROPERTIES", "LINKER_LANGUAGE", "Swift") } writer.writeTargetLinkLibraries(targetName, .public, [ cmakeOptions.getTargetName(moduleName: module.name) ]) } diff --git a/Support/Sources/ABIBindings/CMakeLists.txt b/Support/Sources/ABIBindings/CMakeLists.txt index 8bf22f4..a6d9ac3 100644 --- a/Support/Sources/ABIBindings/CMakeLists.txt +++ b/Support/Sources/ABIBindings/CMakeLists.txt @@ -1,2 +1,4 @@ file(GLOB_RECURSE SOURCES *.swift) -add_library(ABIBindings STATIC ${SOURCES}) \ No newline at end of file +add_library(ABIBindings STATIC ${SOURCES}) +# Workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/26346 +target_include_directories(ABIBindings INTERFACE "${CMAKE_CURRENT_BINARY_DIR}") \ No newline at end of file diff --git a/Support/Sources/COM/COMEmbedding.swift b/Support/Sources/COM/COMEmbedding.swift index 8677b70..7ff74ff 100644 --- a/Support/Sources/COM/COMEmbedding.swift +++ b/Support/Sources/COM/COMEmbedding.swift @@ -1,5 +1,6 @@ import COM_ABI -import SWRT_SwiftCOMObject +// @_implementationOnly to work around https://gitlab.kitware.com/cmake/cmake/-/issues/26346 +@_implementationOnly import SWRT_SwiftCOMObject /// Protocol for Swift objects which embed COM interfaces. public protocol COMEmbedderWithDelegatedImplementation: IUnknownProtocol { diff --git a/Support/Sources/WindowsRuntime/CMakeLists.txt b/Support/Sources/WindowsRuntime/CMakeLists.txt index 49f5d0b..cd04cb2 100644 --- a/Support/Sources/WindowsRuntime/CMakeLists.txt +++ b/Support/Sources/WindowsRuntime/CMakeLists.txt @@ -2,7 +2,3 @@ file(GLOB_RECURSE SOURCES *.swift) add_library(WindowsRuntime STATIC ${SOURCES}) target_link_libraries(WindowsRuntime PUBLIC COM WindowsRuntime_ABI) target_link_libraries(WindowsRuntime PRIVATE SWRT_InternalABI) - -# Workaround for CMake not propagating include dirs -# target_include_directories(WindowsRuntime INTERFACE "$") -# target_include_directories(WindowsRuntime INTERFACE "$") \ No newline at end of file From 64538e6d0909b957ccf298fea9613aeaefd0f218 Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Wed, 2 Oct 2024 06:04:36 -0400 Subject: [PATCH 07/11] Tweaked ABI modules --- Generator/InteropTests/WinRTComponent/CMakeLists.txt | 2 +- Package.swift | 8 ++++---- Support/Sources/CMakeLists.txt | 2 +- Support/Sources/COM/CMakeLists.txt | 2 +- Support/Sources/COM_InternalABI/CMakeLists.txt | 3 +++ .../include/SwiftCOMObject.h | 0 Support/Sources/COM_InternalABI/include/module.modulemap | 4 ++++ Support/Sources/InternalABI/CMakeLists.txt | 3 --- Support/Sources/InternalABI/include/module.modulemap | 9 --------- Support/Sources/WindowsRuntime/CMakeLists.txt | 1 - .../include/SWRT/windows/windows.foundation.h | 0 .../Sources/WindowsRuntime_ABI/include/module.modulemap | 5 +++++ 12 files changed, 19 insertions(+), 20 deletions(-) create mode 100644 Support/Sources/COM_InternalABI/CMakeLists.txt rename Support/Sources/{InternalABI => COM_InternalABI}/include/SwiftCOMObject.h (100%) create mode 100644 Support/Sources/COM_InternalABI/include/module.modulemap delete mode 100644 Support/Sources/InternalABI/CMakeLists.txt delete mode 100644 Support/Sources/InternalABI/include/module.modulemap rename Support/Sources/{InternalABI => WindowsRuntime_ABI}/include/SWRT/windows/windows.foundation.h (100%) diff --git a/Generator/InteropTests/WinRTComponent/CMakeLists.txt b/Generator/InteropTests/WinRTComponent/CMakeLists.txt index 9d7b91d..16bbbb0 100644 --- a/Generator/InteropTests/WinRTComponent/CMakeLists.txt +++ b/Generator/InteropTests/WinRTComponent/CMakeLists.txt @@ -1,7 +1,7 @@ # Support using this directory as a standalone project or as a subdirectory. if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") cmake_minimum_required(VERSION 3.21.0) - project(WinRTComponent LANGUAGES CXX) + project(WinRTComponent LANGUAGES CXX Swift) endif() if (NOT DEFINED SWIFTWINRT_EXE) diff --git a/Package.swift b/Package.swift index e9d73fc..73ad3b7 100644 --- a/Package.swift +++ b/Package.swift @@ -22,9 +22,9 @@ let package = Package( path: "Support/Sources/WindowsRuntime_ABI", exclude: ["CMakeLists.txt"]), .target( - name: "InternalABI", + name: "COM_InternalABI", dependencies: ["COM_ABI", "WindowsRuntime_ABI"], - path: "Support/Sources/InternalABI", + path: "Support/Sources/COM_InternalABI", exclude: ["CMakeLists.txt"]), .target( name: "ABIBindings", @@ -32,12 +32,12 @@ let package = Package( exclude: ["CMakeLists.txt"]), .target( name: "COM", - dependencies: ["ABIBindings", "COM_ABI", "InternalABI"], + dependencies: ["ABIBindings", "COM_ABI", "COM_InternalABI"], path: "Support/Sources/COM", exclude: ["CMakeLists.txt"]), .target( name: "WindowsRuntime", - dependencies: ["COM", "WindowsRuntime_ABI", "InternalABI"], + dependencies: ["COM", "WindowsRuntime_ABI"], path: "Support/Sources/WindowsRuntime", exclude: [ "CMakeLists.txt", diff --git a/Support/Sources/CMakeLists.txt b/Support/Sources/CMakeLists.txt index 59d3780..31bb8a5 100644 --- a/Support/Sources/CMakeLists.txt +++ b/Support/Sources/CMakeLists.txt @@ -1,6 +1,6 @@ add_subdirectory(COM_ABI) +add_subdirectory(COM_InternalABI) add_subdirectory(WindowsRuntime_ABI) -add_subdirectory(InternalABI) add_subdirectory(ABIBindings) add_subdirectory(COM) diff --git a/Support/Sources/COM/CMakeLists.txt b/Support/Sources/COM/CMakeLists.txt index b5244e1..84033b6 100644 --- a/Support/Sources/COM/CMakeLists.txt +++ b/Support/Sources/COM/CMakeLists.txt @@ -1,4 +1,4 @@ file(GLOB_RECURSE SOURCES *.swift) add_library(COM STATIC ${SOURCES}) target_link_libraries(COM PUBLIC ABIBindings COM_ABI) -target_link_libraries(COM PRIVATE SWRT_InternalABI) \ No newline at end of file +target_link_libraries(COM PRIVATE COM_InternalABI) \ No newline at end of file diff --git a/Support/Sources/COM_InternalABI/CMakeLists.txt b/Support/Sources/COM_InternalABI/CMakeLists.txt new file mode 100644 index 0000000..8c6c9f0 --- /dev/null +++ b/Support/Sources/COM_InternalABI/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library(COM_InternalABI INTERFACE) +target_include_directories(COM_InternalABI INTERFACE include) +target_link_libraries(COM_InternalABI INTERFACE COM_ABI WindowsRuntime_ABI) \ No newline at end of file diff --git a/Support/Sources/InternalABI/include/SwiftCOMObject.h b/Support/Sources/COM_InternalABI/include/SwiftCOMObject.h similarity index 100% rename from Support/Sources/InternalABI/include/SwiftCOMObject.h rename to Support/Sources/COM_InternalABI/include/SwiftCOMObject.h diff --git a/Support/Sources/COM_InternalABI/include/module.modulemap b/Support/Sources/COM_InternalABI/include/module.modulemap new file mode 100644 index 0000000..62fc43f --- /dev/null +++ b/Support/Sources/COM_InternalABI/include/module.modulemap @@ -0,0 +1,4 @@ +module SWRT_SwiftCOMObject { + header "SwiftCOMObject.h" + export * +} diff --git a/Support/Sources/InternalABI/CMakeLists.txt b/Support/Sources/InternalABI/CMakeLists.txt deleted file mode 100644 index 4e3a25e..0000000 --- a/Support/Sources/InternalABI/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_library(SWRT_InternalABI INTERFACE) -target_include_directories(SWRT_InternalABI INTERFACE include) -target_link_libraries(SWRT_InternalABI INTERFACE COM_ABI WindowsRuntime_ABI) \ No newline at end of file diff --git a/Support/Sources/InternalABI/include/module.modulemap b/Support/Sources/InternalABI/include/module.modulemap deleted file mode 100644 index d142418..0000000 --- a/Support/Sources/InternalABI/include/module.modulemap +++ /dev/null @@ -1,9 +0,0 @@ -module SWRT_SwiftCOMObject { - header "SwiftCOMObject.h" - export * -} - -module SWRT_WindowsFoundation { - header "SWRT/windows/windows.foundation.h" - export * -} \ No newline at end of file diff --git a/Support/Sources/WindowsRuntime/CMakeLists.txt b/Support/Sources/WindowsRuntime/CMakeLists.txt index cd04cb2..2aad0a6 100644 --- a/Support/Sources/WindowsRuntime/CMakeLists.txt +++ b/Support/Sources/WindowsRuntime/CMakeLists.txt @@ -1,4 +1,3 @@ file(GLOB_RECURSE SOURCES *.swift) add_library(WindowsRuntime STATIC ${SOURCES}) target_link_libraries(WindowsRuntime PUBLIC COM WindowsRuntime_ABI) -target_link_libraries(WindowsRuntime PRIVATE SWRT_InternalABI) diff --git a/Support/Sources/InternalABI/include/SWRT/windows/windows.foundation.h b/Support/Sources/WindowsRuntime_ABI/include/SWRT/windows/windows.foundation.h similarity index 100% rename from Support/Sources/InternalABI/include/SWRT/windows/windows.foundation.h rename to Support/Sources/WindowsRuntime_ABI/include/SWRT/windows/windows.foundation.h diff --git a/Support/Sources/WindowsRuntime_ABI/include/module.modulemap b/Support/Sources/WindowsRuntime_ABI/include/module.modulemap index 5ac8c27..d7bda60 100644 --- a/Support/Sources/WindowsRuntime_ABI/include/module.modulemap +++ b/Support/Sources/WindowsRuntime_ABI/include/module.modulemap @@ -12,3 +12,8 @@ module WindowsRuntime_ABI { header "SWRT/windows/winstring.h" export * } + +module SWRT_WindowsFoundation { + header "SWRT/windows/windows.foundation.h" + export * +} From 2cf9c363f1387956bfccdf3e92372b36dd877822 Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Wed, 2 Oct 2024 06:15:59 -0400 Subject: [PATCH 08/11] Another workaround --- Support/Sources/COM/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Support/Sources/COM/CMakeLists.txt b/Support/Sources/COM/CMakeLists.txt index 84033b6..ab8d8ff 100644 --- a/Support/Sources/COM/CMakeLists.txt +++ b/Support/Sources/COM/CMakeLists.txt @@ -1,4 +1,6 @@ file(GLOB_RECURSE SOURCES *.swift) add_library(COM STATIC ${SOURCES}) target_link_libraries(COM PUBLIC ABIBindings COM_ABI) -target_link_libraries(COM PRIVATE COM_InternalABI) \ No newline at end of file +target_link_libraries(COM PRIVATE COM_InternalABI) +# Workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/26346 +target_include_directories(COM INTERFACE "${CMAKE_CURRENT_BINARY_DIR}") \ No newline at end of file From d768c9e259d5530da89eb4686027045b3cc03480 Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Wed, 2 Oct 2024 07:03:15 -0400 Subject: [PATCH 09/11] Remove @_implementationOnly causing crashes. --- Support/Sources/COM/COMEmbedding.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Support/Sources/COM/COMEmbedding.swift b/Support/Sources/COM/COMEmbedding.swift index 7ff74ff..8677b70 100644 --- a/Support/Sources/COM/COMEmbedding.swift +++ b/Support/Sources/COM/COMEmbedding.swift @@ -1,6 +1,5 @@ import COM_ABI -// @_implementationOnly to work around https://gitlab.kitware.com/cmake/cmake/-/issues/26346 -@_implementationOnly import SWRT_SwiftCOMObject +import SWRT_SwiftCOMObject /// Protocol for Swift objects which embed COM interfaces. public protocol COMEmbedderWithDelegatedImplementation: IUnknownProtocol { From 3af30069f3ef4f7d060116346dae86a55127f18a Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Wed, 2 Oct 2024 07:34:34 -0400 Subject: [PATCH 10/11] Merge InternalABI module in COM_ABI target --- Package.swift | 7 +------ Support/Sources/CMakeLists.txt | 1 - Support/Sources/COM/CMakeLists.txt | 1 - Support/Sources/COM/COMEmbedding.swift | 2 +- .../{COM_InternalABI => COM_ABI}/include/SwiftCOMObject.h | 0 Support/Sources/COM_ABI/include/module.modulemap | 5 +++++ Support/Sources/COM_InternalABI/CMakeLists.txt | 3 --- Support/Sources/COM_InternalABI/include/module.modulemap | 4 ---- 8 files changed, 7 insertions(+), 16 deletions(-) rename Support/Sources/{COM_InternalABI => COM_ABI}/include/SwiftCOMObject.h (100%) delete mode 100644 Support/Sources/COM_InternalABI/CMakeLists.txt delete mode 100644 Support/Sources/COM_InternalABI/include/module.modulemap diff --git a/Package.swift b/Package.swift index 73ad3b7..edac473 100644 --- a/Package.swift +++ b/Package.swift @@ -21,18 +21,13 @@ let package = Package( dependencies: ["COM_ABI"], path: "Support/Sources/WindowsRuntime_ABI", exclude: ["CMakeLists.txt"]), - .target( - name: "COM_InternalABI", - dependencies: ["COM_ABI", "WindowsRuntime_ABI"], - path: "Support/Sources/COM_InternalABI", - exclude: ["CMakeLists.txt"]), .target( name: "ABIBindings", path: "Support/Sources/ABIBindings", exclude: ["CMakeLists.txt"]), .target( name: "COM", - dependencies: ["ABIBindings", "COM_ABI", "COM_InternalABI"], + dependencies: ["ABIBindings", "COM_ABI"], path: "Support/Sources/COM", exclude: ["CMakeLists.txt"]), .target( diff --git a/Support/Sources/CMakeLists.txt b/Support/Sources/CMakeLists.txt index 31bb8a5..a364ade 100644 --- a/Support/Sources/CMakeLists.txt +++ b/Support/Sources/CMakeLists.txt @@ -1,5 +1,4 @@ add_subdirectory(COM_ABI) -add_subdirectory(COM_InternalABI) add_subdirectory(WindowsRuntime_ABI) add_subdirectory(ABIBindings) diff --git a/Support/Sources/COM/CMakeLists.txt b/Support/Sources/COM/CMakeLists.txt index ab8d8ff..26eb399 100644 --- a/Support/Sources/COM/CMakeLists.txt +++ b/Support/Sources/COM/CMakeLists.txt @@ -1,6 +1,5 @@ file(GLOB_RECURSE SOURCES *.swift) add_library(COM STATIC ${SOURCES}) target_link_libraries(COM PUBLIC ABIBindings COM_ABI) -target_link_libraries(COM PRIVATE COM_InternalABI) # Workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/26346 target_include_directories(COM INTERFACE "${CMAKE_CURRENT_BINARY_DIR}") \ No newline at end of file diff --git a/Support/Sources/COM/COMEmbedding.swift b/Support/Sources/COM/COMEmbedding.swift index 8677b70..3e0ed47 100644 --- a/Support/Sources/COM/COMEmbedding.swift +++ b/Support/Sources/COM/COMEmbedding.swift @@ -1,5 +1,5 @@ import COM_ABI -import SWRT_SwiftCOMObject +import COM_PrivateABI /// Protocol for Swift objects which embed COM interfaces. public protocol COMEmbedderWithDelegatedImplementation: IUnknownProtocol { diff --git a/Support/Sources/COM_InternalABI/include/SwiftCOMObject.h b/Support/Sources/COM_ABI/include/SwiftCOMObject.h similarity index 100% rename from Support/Sources/COM_InternalABI/include/SwiftCOMObject.h rename to Support/Sources/COM_ABI/include/SwiftCOMObject.h diff --git a/Support/Sources/COM_ABI/include/module.modulemap b/Support/Sources/COM_ABI/include/module.modulemap index 30c4188..0e5ea49 100644 --- a/Support/Sources/COM_ABI/include/module.modulemap +++ b/Support/Sources/COM_ABI/include/module.modulemap @@ -10,3 +10,8 @@ module COM_ABI { header "SWRT/windows/wtypes.h" export * } + +module COM_PrivateABI { + header "SwiftCOMObject.h" + export * +} diff --git a/Support/Sources/COM_InternalABI/CMakeLists.txt b/Support/Sources/COM_InternalABI/CMakeLists.txt deleted file mode 100644 index 8c6c9f0..0000000 --- a/Support/Sources/COM_InternalABI/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_library(COM_InternalABI INTERFACE) -target_include_directories(COM_InternalABI INTERFACE include) -target_link_libraries(COM_InternalABI INTERFACE COM_ABI WindowsRuntime_ABI) \ No newline at end of file diff --git a/Support/Sources/COM_InternalABI/include/module.modulemap b/Support/Sources/COM_InternalABI/include/module.modulemap deleted file mode 100644 index 62fc43f..0000000 --- a/Support/Sources/COM_InternalABI/include/module.modulemap +++ /dev/null @@ -1,4 +0,0 @@ -module SWRT_SwiftCOMObject { - header "SwiftCOMObject.h" - export * -} From 67cca5609fed058a744e666027440df23718d5a1 Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Thu, 3 Oct 2024 20:04:01 -0400 Subject: [PATCH 11/11] Work around supplemental output file map bug --- Generator/Sources/SwiftWinRT/writeProjectionFiles.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift b/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift index ebc3ad9..a1307d3 100644 --- a/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift +++ b/Generator/Sources/SwiftWinRT/writeProjectionFiles.swift @@ -96,17 +96,25 @@ fileprivate func writeSwiftModuleFiles(_ module: Module, directoryPath: String, path: "\(directoryPath)\\CMakeLists.txt", directoryCreation: .ancestors)) writer.writeSingleLineCommand("file", "GLOB_RECURSE", "SOURCES", "*.swift") + let targetName = cmakeOptions.getTargetName(moduleName: module.name) writer.writeSingleLineCommand( "add_library", .autoquote(targetName), .unquoted(cmakeOptions.dynamicLibraries ? "SHARED" : "STATIC"), .unquoted("${SOURCES}")) + if targetName != module.name { writer.writeSingleLineCommand( "set_target_properties", .autoquote(targetName), "PROPERTIES", "Swift_MODULE_NAME", .autoquote(module.name)) } + + // Workaround for https://github.com/swiftlang/swift-driver/issues/1477 + writer.writeSingleLineCommand( + "target_compile_options", .autoquote(targetName), + "PRIVATE", "-driver-filelist-threshold=9999") + writer.writeTargetLinkLibraries(targetName, .public, [ cmakeOptions.getTargetName(moduleName: module.abiModuleName), SupportModules.WinRT.moduleName ] + module.references.map { cmakeOptions.getTargetName(moduleName: $0.name) })