From d9ef817bb9d2ee3b9c291fa74403b75f7f377452 Mon Sep 17 00:00:00 2001 From: YR Chen Date: Tue, 8 Jun 2021 16:13:05 +0800 Subject: [PATCH 1/2] Fix building on Windows --- Package.swift | 10 +++++++++- Sources/System/Internals/Mocking.swift | 8 ++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index 4c6e4ab2..12755d94 100644 --- a/Package.swift +++ b/Package.swift @@ -12,11 +12,19 @@ import PackageDescription -let targets: [PackageDescription.Target] = [ +var windowsPlatform: [Platform] = [] +#if os(Windows) +windowsPlatform.append(.windows) +#endif + +let targets: [Target] = [ .target( name: "SystemPackage", dependencies: ["CSystem"], path: "Sources/System", + cSettings: [ + .define("_CRT_SECURE_NO_WARNINGS", .when(platforms: windowsPlatform)), + ], swiftSettings: [ .define("SYSTEM_PACKAGE"), .define("ENABLE_MOCKING", .when(configuration: .debug)) diff --git a/Sources/System/Internals/Mocking.swift b/Sources/System/Internals/Mocking.swift index 4c74b6a4..eb1fe834 100644 --- a/Sources/System/Internals/Mocking.swift +++ b/Sources/System/Internals/Mocking.swift @@ -146,7 +146,7 @@ private func originalSyscallName(_ function: String) -> String { private func mockImpl( name: String, - path: UnsafePointer?, + path: UnsafePointer?, _ args: [AnyHashable] ) -> CInt { precondition(mockingEnabled) @@ -177,18 +177,18 @@ private func mockImpl( } internal func _mock( - name: String = #function, path: UnsafePointer? = nil, _ args: AnyHashable... + name: String = #function, path: UnsafePointer? = nil, _ args: AnyHashable... ) -> CInt { return mockImpl(name: name, path: path, args) } internal func _mockInt( - name: String = #function, path: UnsafePointer? = nil, _ args: AnyHashable... + name: String = #function, path: UnsafePointer? = nil, _ args: AnyHashable... ) -> Int { Int(mockImpl(name: name, path: path, args)) } internal func _mockOffT( - name: String = #function, path: UnsafePointer? = nil, _ args: AnyHashable... + name: String = #function, path: UnsafePointer? = nil, _ args: AnyHashable... ) -> _COffT { _COffT(mockImpl(name: name, path: path, args)) } From b2a95c581294b6b501f8d5a8af5d3d98ba6f8b4b Mon Sep 17 00:00:00 2001 From: YR Chen Date: Fri, 18 Jun 2021 10:16:55 +0800 Subject: [PATCH 2/2] Simplify Package.swift --- Package.swift | 51 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/Package.swift b/Package.swift index 12755d94..b081a872 100644 --- a/Package.swift +++ b/Package.swift @@ -12,39 +12,32 @@ import PackageDescription -var windowsPlatform: [Platform] = [] -#if os(Windows) -windowsPlatform.append(.windows) -#endif - -let targets: [Target] = [ - .target( - name: "SystemPackage", - dependencies: ["CSystem"], - path: "Sources/System", - cSettings: [ - .define("_CRT_SECURE_NO_WARNINGS", .when(platforms: windowsPlatform)), - ], - swiftSettings: [ - .define("SYSTEM_PACKAGE"), - .define("ENABLE_MOCKING", .when(configuration: .debug)) - ]), - .target( - name: "CSystem", - dependencies: []), - .testTarget( - name: "SystemTests", - dependencies: ["SystemPackage"], - swiftSettings: [ - .define("SYSTEM_PACKAGE") - ]), -] - let package = Package( name: "swift-system", products: [ .library(name: "SystemPackage", targets: ["SystemPackage"]), ], dependencies: [], - targets: targets + targets: [ + .target( + name: "CSystem", + dependencies: []), + .target( + name: "SystemPackage", + dependencies: ["CSystem"], + path: "Sources/System", + cSettings: [ + .define("_CRT_SECURE_NO_WARNINGS") + ], + swiftSettings: [ + .define("SYSTEM_PACKAGE"), + .define("ENABLE_MOCKING", .when(configuration: .debug)) + ]), + .testTarget( + name: "SystemTests", + dependencies: ["SystemPackage"], + swiftSettings: [ + .define("SYSTEM_PACKAGE") + ]), + ] )