From f9a57704bc73f88e622190443c528b0afa2cdeb5 Mon Sep 17 00:00:00 2001 From: Tristan Labelle Date: Mon, 16 Sep 2024 18:36:36 -0400 Subject: [PATCH] Extract an ABIBindings module. --- Package.swift | 6 +++++- .../Sources/{COM => ABIBindings}/ABIBinding.swift | 7 ------- .../ProjectedTypes => ABIBindings}/BoolBinding.swift | 0 Support/Sources/ABIBindings/CMakeLists.txt | 2 ++ Support/Sources/ABIBindings/ClosedEnumBinding.swift | 11 +++++++++++ Support/Sources/ABIBindings/IdentityBinding.swift | 7 +++++++ .../NumericBinding.swift | 0 .../OpenEnumBinding.swift} | 12 ------------ .../Sources/{COM => ABIBindings}/PODBinding.swift | 0 .../WideCharBinding.swift | 0 Support/Sources/CMakeLists.txt | 1 + Support/Sources/COM/ABIBindings.swift | 1 + Support/Sources/COM/CMakeLists.txt | 3 ++- Support/Sources/WindowsRuntime/CMakeLists.txt | 3 ++- 14 files changed, 31 insertions(+), 22 deletions(-) rename Support/Sources/{COM => ABIBindings}/ABIBinding.swift (87%) rename Support/Sources/{COM/ProjectedTypes => ABIBindings}/BoolBinding.swift (100%) create mode 100644 Support/Sources/ABIBindings/CMakeLists.txt create mode 100644 Support/Sources/ABIBindings/ClosedEnumBinding.swift create mode 100644 Support/Sources/ABIBindings/IdentityBinding.swift rename Support/Sources/{COM/ProjectedTypes => ABIBindings}/NumericBinding.swift (100%) rename Support/Sources/{COM/ProjectedTypes/EnumBinding.swift => ABIBindings/OpenEnumBinding.swift} (50%) rename Support/Sources/{COM => ABIBindings}/PODBinding.swift (100%) rename Support/Sources/{COM/ProjectedTypes => ABIBindings}/WideCharBinding.swift (100%) create mode 100644 Support/Sources/COM/ABIBindings.swift diff --git a/Package.swift b/Package.swift index 594e7c3e..6e6c913e 100644 --- a/Package.swift +++ b/Package.swift @@ -26,9 +26,13 @@ let package = Package( dependencies: ["COM_ABI", "WindowsRuntime_ABI"], path: "Support/Sources/InternalABI", exclude: ["CMakeLists.txt"]), + .target( + name: "ABIBindings", + path: "Support/Sources/ABIBindings", + exclude: ["CMakeLists.txt"]), .target( name: "COM", - dependencies: ["COM_ABI", "InternalABI"], + dependencies: ["ABIBindings", "COM_ABI", "InternalABI"], path: "Support/Sources/COM", exclude: ["CMakeLists.txt"]), .target( diff --git a/Support/Sources/COM/ABIBinding.swift b/Support/Sources/ABIBindings/ABIBinding.swift similarity index 87% rename from Support/Sources/COM/ABIBinding.swift rename to Support/Sources/ABIBindings/ABIBinding.swift index 0da9c5b9..5d5c0cbe 100644 --- a/Support/Sources/COM/ABIBinding.swift +++ b/Support/Sources/ABIBindings/ABIBinding.swift @@ -40,13 +40,6 @@ extension ABIBinding { } } -public protocol IdentityBinding: PODBinding where SwiftValue == ABIValue {} - -extension IdentityBinding { - public static func toABI(_ value: SwiftValue) -> ABIValue { value } - public static func toSwift(_ value: ABIValue) -> SwiftValue { value } -} - public enum ABIBindingError: Error { case unsupported(Any.Type) } \ No newline at end of file diff --git a/Support/Sources/COM/ProjectedTypes/BoolBinding.swift b/Support/Sources/ABIBindings/BoolBinding.swift similarity index 100% rename from Support/Sources/COM/ProjectedTypes/BoolBinding.swift rename to Support/Sources/ABIBindings/BoolBinding.swift diff --git a/Support/Sources/ABIBindings/CMakeLists.txt b/Support/Sources/ABIBindings/CMakeLists.txt new file mode 100644 index 00000000..8bf22f40 --- /dev/null +++ b/Support/Sources/ABIBindings/CMakeLists.txt @@ -0,0 +1,2 @@ +file(GLOB_RECURSE SOURCES *.swift) +add_library(ABIBindings STATIC ${SOURCES}) \ No newline at end of file diff --git a/Support/Sources/ABIBindings/ClosedEnumBinding.swift b/Support/Sources/ABIBindings/ClosedEnumBinding.swift new file mode 100644 index 00000000..7e4df8d7 --- /dev/null +++ b/Support/Sources/ABIBindings/ClosedEnumBinding.swift @@ -0,0 +1,11 @@ +/// Binding for an enumeration whose ABI representation is an integer, +/// and for which allowed values are limited to a set of defined enumerants. +public protocol ClosedEnumBinding: RawRepresentable, PODBinding + where ABIValue == RawValue, SwiftValue == Self, RawValue: FixedWidthInteger & Hashable { +} + +extension ClosedEnumBinding { + public static var abiDefaultValue: RawValue { RawValue.zero } + public static func toSwift(_ value: RawValue) -> Self { Self(rawValue: value)! } + public static func toABI(_ value: Self) -> RawValue { value.rawValue } +} diff --git a/Support/Sources/ABIBindings/IdentityBinding.swift b/Support/Sources/ABIBindings/IdentityBinding.swift new file mode 100644 index 00000000..7a749611 --- /dev/null +++ b/Support/Sources/ABIBindings/IdentityBinding.swift @@ -0,0 +1,7 @@ +/// Binds a Swift type to an identical ABI type. +public protocol IdentityBinding: PODBinding where SwiftValue == ABIValue {} + +extension IdentityBinding { + public static func toABI(_ value: SwiftValue) -> ABIValue { value } + public static func toSwift(_ value: ABIValue) -> SwiftValue { value } +} \ No newline at end of file diff --git a/Support/Sources/COM/ProjectedTypes/NumericBinding.swift b/Support/Sources/ABIBindings/NumericBinding.swift similarity index 100% rename from Support/Sources/COM/ProjectedTypes/NumericBinding.swift rename to Support/Sources/ABIBindings/NumericBinding.swift diff --git a/Support/Sources/COM/ProjectedTypes/EnumBinding.swift b/Support/Sources/ABIBindings/OpenEnumBinding.swift similarity index 50% rename from Support/Sources/COM/ProjectedTypes/EnumBinding.swift rename to Support/Sources/ABIBindings/OpenEnumBinding.swift index ab3fe159..dae0a262 100644 --- a/Support/Sources/COM/ProjectedTypes/EnumBinding.swift +++ b/Support/Sources/ABIBindings/OpenEnumBinding.swift @@ -11,15 +11,3 @@ extension OpenEnumBinding { public static func toSwift(_ value: RawValue) -> Self { Self(rawValue: value) } public static func toABI(_ value: Self) -> RawValue { value.rawValue } } - -/// Binding for an enumeration whose ABI representation is an integer, -/// and for which allowed values are limited to a set of defined enumerants. -public protocol ClosedEnumBinding: RawRepresentable, PODBinding - where ABIValue == RawValue, SwiftValue == Self, RawValue: FixedWidthInteger & Hashable { -} - -extension ClosedEnumBinding { - public static var abiDefaultValue: RawValue { RawValue.zero } - public static func toSwift(_ value: RawValue) -> Self { Self(rawValue: value)! } - public static func toABI(_ value: Self) -> RawValue { value.rawValue } -} diff --git a/Support/Sources/COM/PODBinding.swift b/Support/Sources/ABIBindings/PODBinding.swift similarity index 100% rename from Support/Sources/COM/PODBinding.swift rename to Support/Sources/ABIBindings/PODBinding.swift diff --git a/Support/Sources/COM/ProjectedTypes/WideCharBinding.swift b/Support/Sources/ABIBindings/WideCharBinding.swift similarity index 100% rename from Support/Sources/COM/ProjectedTypes/WideCharBinding.swift rename to Support/Sources/ABIBindings/WideCharBinding.swift diff --git a/Support/Sources/CMakeLists.txt b/Support/Sources/CMakeLists.txt index 5e0c9f98..59d37803 100644 --- a/Support/Sources/CMakeLists.txt +++ b/Support/Sources/CMakeLists.txt @@ -2,5 +2,6 @@ add_subdirectory(COM_ABI) add_subdirectory(WindowsRuntime_ABI) add_subdirectory(InternalABI) +add_subdirectory(ABIBindings) add_subdirectory(COM) add_subdirectory(WindowsRuntime) \ No newline at end of file diff --git a/Support/Sources/COM/ABIBindings.swift b/Support/Sources/COM/ABIBindings.swift new file mode 100644 index 00000000..e6a0f553 --- /dev/null +++ b/Support/Sources/COM/ABIBindings.swift @@ -0,0 +1 @@ +@_exported import ABIBindings \ No newline at end of file diff --git a/Support/Sources/COM/CMakeLists.txt b/Support/Sources/COM/CMakeLists.txt index af95fd7f..2b963a57 100644 --- a/Support/Sources/COM/CMakeLists.txt +++ b/Support/Sources/COM/CMakeLists.txt @@ -1,3 +1,4 @@ file(GLOB_RECURSE SOURCES *.swift) add_library(COM STATIC ${SOURCES}) -target_link_libraries(COM PRIVATE COM_ABI SWRT_InternalABI) \ No newline at end of file +target_link_libraries(COM PUBLIC ABIBindings COM_ABI SWRT_InternalABI) +target_link_libraries(COM PRIVATE SWRT_InternalABI) \ No newline at end of file diff --git a/Support/Sources/WindowsRuntime/CMakeLists.txt b/Support/Sources/WindowsRuntime/CMakeLists.txt index 599fddc3..8f8213e0 100644 --- a/Support/Sources/WindowsRuntime/CMakeLists.txt +++ b/Support/Sources/WindowsRuntime/CMakeLists.txt @@ -1,3 +1,4 @@ file(GLOB_RECURSE SOURCES *.swift) add_library(WindowsRuntime STATIC ${SOURCES}) -target_link_libraries(WindowsRuntime PRIVATE COM WindowsRuntime_ABI SWRT_InternalABI) \ No newline at end of file +target_link_libraries(WindowsRuntime PUBLIC COM WindowsRuntime_ABI) +target_link_libraries(WindowsRuntime PRIVATE SWRT_InternalABI) \ No newline at end of file