Skip to content

Commit 3366f65

Browse files
authored
Add CMake directions for the WinSDK overlay (#1296)
Add CMake scripting/etc. for the WinSDK cross-import overlay. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 03ec484 commit 3366f65

File tree

9 files changed

+50
-10
lines changed

9 files changed

+50
-10
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ let package = Package(
269269
"Testing",
270270
],
271271
path: "Sources/Overlays/_Testing_WinSDK",
272+
exclude: ["CMakeLists.txt"],
272273
swiftSettings: .packageSettings + .enableLibraryEvolution()
273274
),
274275

Sources/Overlays/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ add_subdirectory(_Testing_CoreGraphics)
1111
add_subdirectory(_Testing_CoreImage)
1212
add_subdirectory(_Testing_Foundation)
1313
add_subdirectory(_Testing_UIKit)
14+
add_subdirectory(_Testing_WinSDK)

Sources/Overlays/_Testing_WinSDK/Attachments/AttachableImageFormat+CLSID.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@_spi(Experimental) public import Testing
1313
public import WinSDK
1414

15+
@_spi(Experimental)
1516
extension AttachableImageFormat {
1617
private static let _encoderPathExtensionsByCLSID = Result<[UInt128: [String]], any Error> {
1718
var result = [UInt128: [String]]()
@@ -26,8 +27,8 @@ extension AttachableImageFormat {
2627
var enumerator: UnsafeMutablePointer<IEnumUnknown>?
2728
let rCreate = factory.pointee.lpVtbl.pointee.CreateComponentEnumerator(
2829
factory,
29-
DWORD(bitPattern: WICEncoder.rawValue),
30-
DWORD(bitPattern: WICComponentEnumerateDefault.rawValue),
30+
DWORD(WICEncoder.rawValue),
31+
DWORD(WICComponentEnumerateDefault.rawValue),
3132
&enumerator
3233
)
3334
guard rCreate == S_OK, let enumerator else {

Sources/Overlays/_Testing_WinSDK/Attachments/IWICBitmapSource+AttachableAsIWICBitmapSource.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ extension UnsafeMutablePointer where Pointee: IWICBitmapSourceProtocol {
9696

9797
// MARK: - _AttachableByAddressAsIWICBitmapSource implementation
9898

99+
@_spi(Experimental)
99100
extension IWICBitmapSourceProtocol {
100101
public static func _copyAttachableIWICBitmapSource(
101102
from imageAddress: UnsafeMutablePointer<Self>,
@@ -119,6 +120,7 @@ extension IWICBitmapSourceProtocol {
119120
}
120121

121122
extension IWICBitmapSource {
123+
@_spi(Experimental)
122124
public static func _copyAttachableIWICBitmapSource(
123125
from imageAddress: UnsafeMutablePointer<Self>,
124126
using factory: UnsafeMutablePointer<IWICImagingFactory>

Sources/Overlays/_Testing_WinSDK/Attachments/_AttachableImageWrapper+AttachableWrapper.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extension _AttachableImageWrapper: Attachable, AttachableWrapper where Image: At
4646
let rCreate = CoCreateInstance(
4747
&encoderCLSID,
4848
nil,
49-
DWORD(bitPattern: CLSCTX_INPROC_SERVER.rawValue),
49+
DWORD(CLSCTX_INPROC_SERVER.rawValue),
5050
IID_IWICBitmapEncoder,
5151
&encoder
5252
)
@@ -93,7 +93,7 @@ extension _AttachableImageWrapper: Attachable, AttachableWrapper where Image: At
9393
guard rCommit == S_OK else {
9494
throw ImageAttachmentError.imageWritingFailed(rCommit)
9595
}
96-
rCommit = stream.pointee.lpVtbl.pointee.Commit(stream, DWORD(bitPattern: STGC_DEFAULT.rawValue))
96+
rCommit = stream.pointee.lpVtbl.pointee.Commit(stream, DWORD(STGC_DEFAULT.rawValue))
9797
guard rCommit == S_OK else {
9898
throw ImageAttachmentError.imageWritingFailed(rCommit)
9999
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2024–2025 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
10+
add_library(_Testing_WinSDK
11+
Attachments/_AttachableImageWrapper+AttachableWrapper.swift
12+
Attachments/AttachableAsIWICBitmapSource.swift
13+
Attachments/AttachableImageFormat+CLSID.swift
14+
Attachments/Attachment+AttachableAsIWICBitmapSource.swift
15+
Attachments/HBITMAP+AttachableAsIWICBitmapSource.swift
16+
Attachments/HICON+AttachableAsIWICBitmapSource.swift
17+
Attachments/IWICBitmapSource+AttachableAsIWICBitmapSource.swift
18+
Attachments/UnsafeMutablePointer+AttachableAsIWICBitmapSource.swift
19+
Support/Additions/GUIDAdditions.swift
20+
Support/Additions/IPropertyBag2Additions.swift
21+
Support/Additions/IWICImagingFactoryAdditions.swift
22+
ReexportTesting.swift)
23+
24+
target_link_libraries(_Testing_WinSDK PUBLIC
25+
Testing)
26+
27+
target_compile_options(_Testing_WinSDK PRIVATE
28+
-enable-library-evolution
29+
-emit-module-interface -emit-module-interface-path $<TARGET_PROPERTY:_Testing_WinSDK,Swift_MODULE_DIRECTORY>/_Testing_WinSDK.swiftinterface)
30+
31+
_swift_testing_install_target(_Testing_WinSDK)
32+
endif()

Sources/Overlays/_Testing_WinSDK/Support/Additions/IWICImagingFactoryAdditions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension IWICImagingFactory {
2525
let rCreate = CoCreateInstance(
2626
CLSID_WICImagingFactory,
2727
nil,
28-
DWORD(bitPattern: CLSCTX_INPROC_SERVER.rawValue),
28+
DWORD(CLSCTX_INPROC_SERVER.rawValue),
2929
IID_IWICImagingFactory,
3030
&factory
3131
)

Sources/Testing/Attachments/Images/ImageAttachmentError.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ package enum ImageAttachmentError: Error {
2323
case couldNotConvertImage
2424
#elseif os(Windows)
2525
/// A call to `QueryInterface()` failed.
26-
case queryInterfaceFailed(Any.Type, Int32)
26+
case queryInterfaceFailed(Any.Type, CLong)
2727

2828
/// The testing library failed to create a COM object.
29-
case comObjectCreationFailed(Any.Type, Int32)
29+
case comObjectCreationFailed(Any.Type, CLong)
3030

3131
/// An image could not be written.
32-
case imageWritingFailed(Int32)
32+
case imageWritingFailed(CLong)
3333

3434
/// The testing library failed to get an in-memory stream's underlying buffer.
35-
case globalFromStreamFailed(Int32)
35+
case globalFromStreamFailed(CLong)
3636

3737
/// A property could not be written to a property bag.
38-
case propertyBagWritingFailed(String, Int32)
38+
case propertyBagWritingFailed(String, CLong)
3939
#endif
4040
}
4141

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version: 1
2+
modules:
3+
- name: _Testing_WinSDK

0 commit comments

Comments
 (0)