Skip to content

Commit 327773d

Browse files
committed
Fix building on Windows
1 parent 2bc160b commit 327773d

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

Package.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@
1212

1313
import PackageDescription
1414

15-
let targets: [PackageDescription.Target] = [
15+
let windowsPlatform: [Platform]
16+
#if os(Windows)
17+
windowsPlatform = [.windows]
18+
#else
19+
windowsPlatform = []
20+
#endif
21+
22+
let targets: [Target] = [
1623
.target(
1724
name: "SystemPackage",
1825
dependencies: ["CSystem"],
1926
path: "Sources/System",
27+
cSettings: [
28+
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: windowsPlatform)),
29+
],
2030
swiftSettings: [
2131
.define("SYSTEM_PACKAGE"),
2232
.define("ENABLE_MOCKING", .when(configuration: .debug))

Sources/System/Internals/Mocking.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private func originalSyscallName(_ function: String) -> String {
146146

147147
private func mockImpl(
148148
name: String,
149-
path: UnsafePointer<CChar>?,
149+
path: UnsafePointer<CInterop.PlatformChar>?,
150150
_ args: [AnyHashable]
151151
) -> CInt {
152152
precondition(mockingEnabled)
@@ -177,18 +177,18 @@ private func mockImpl(
177177
}
178178

179179
internal func _mock(
180-
name: String = #function, path: UnsafePointer<CChar>? = nil, _ args: AnyHashable...
180+
name: String = #function, path: UnsafePointer<CInterop.PlatformChar>? = nil, _ args: AnyHashable...
181181
) -> CInt {
182182
return mockImpl(name: name, path: path, args)
183183
}
184184
internal func _mockInt(
185-
name: String = #function, path: UnsafePointer<CChar>? = nil, _ args: AnyHashable...
185+
name: String = #function, path: UnsafePointer<CInterop.PlatformChar>? = nil, _ args: AnyHashable...
186186
) -> Int {
187187
Int(mockImpl(name: name, path: path, args))
188188
}
189189

190190
internal func _mockOffT(
191-
name: String = #function, path: UnsafePointer<CChar>? = nil, _ args: AnyHashable...
191+
name: String = #function, path: UnsafePointer<CInterop.PlatformChar>? = nil, _ args: AnyHashable...
192192
) -> _COffT {
193193
_COffT(mockImpl(name: name, path: path, args))
194194
}

Sources/System/Internals/Syscalls.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ internal func system_lseek(
7979
#if ENABLE_MOCKING
8080
if mockingEnabled { return _mockOffT(fd, off, whence) }
8181
#endif
82-
return lseek(fd, off, whence)
82+
return _lseek(fd, off, whence)
8383
}
8484

8585
// write
@@ -106,12 +106,12 @@ internal func system_dup(_ fd: Int32) -> Int32 {
106106
#if ENABLE_MOCKING
107107
if mockingEnabled { return _mock(fd) }
108108
#endif
109-
return dup(fd)
109+
return _dup(fd)
110110
}
111111

112112
internal func system_dup2(_ fd: Int32, _ fd2: Int32) -> Int32 {
113113
#if ENABLE_MOCKING
114114
if mockingEnabled { return _mock(fd, fd2) }
115115
#endif
116-
return dup2(fd, fd2)
116+
return _dup2(fd, fd2)
117117
}

0 commit comments

Comments
 (0)