Skip to content

Commit dda06cd

Browse files
committed
Add support for visionOS
1 parent cc1962b commit dda06cd

File tree

11 files changed

+45
-43
lines changed

11 files changed

+45
-43
lines changed

Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ let package = Package(
3030
.define("_CRT_SECURE_NO_WARNINGS")
3131
],
3232
swiftSettings: [
33+
.define("DARWIN", .when(platforms: [.macOS, .iOS, .watchOS, .tvOS, .visionOS])),
3334
.define("SYSTEM_PACKAGE"),
3435
.define("ENABLE_MOCKING", .when(configuration: .debug))
3536
]),
3637
.testTarget(
3738
name: "SystemTests",
3839
dependencies: ["SystemPackage"],
3940
swiftSettings: [
41+
.define("DARWIN", .when(platforms: [.macOS, .iOS, .watchOS, .tvOS, .visionOS])),
4042
.define("SYSTEM_PACKAGE")
4143
]),
4244
]

Sources/System/Errno.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
2323
@_alwaysEmitIntoClient
2424
private init(_ raw: CInt) { self.init(rawValue: raw) }
2525

26-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
26+
#if DARWIN
2727
/// Error. Not used.
2828
@_alwaysEmitIntoClient
2929
public static var notUsed: Errno { Errno(_ERRNO_NOT_USED) }
@@ -911,7 +911,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
911911
@available(*, unavailable, renamed: "directoryNotEmpty")
912912
public static var ENOTEMPTY: Errno { directoryNotEmpty }
913913

914-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
914+
#if DARWIN
915915
/// Too many processes.
916916
///
917917
/// The corresponding C error is `EPROCLIM`.
@@ -968,7 +968,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
968968
public static var ESTALE: Errno { staleNFSFileHandle }
969969

970970
// TODO: Add Linux's RPC equivalents
971-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
971+
#if DARWIN
972972

973973
/// The structure of the remote procedure call (RPC) is bad.
974974
///
@@ -1060,7 +1060,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
10601060
public static var ENOSYS: Errno { noFunction }
10611061

10621062
// BSD
1063-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1063+
#if DARWIN
10641064
/// Inappropriate file type or format.
10651065
///
10661066
/// The file was the wrong type for the operation,
@@ -1075,7 +1075,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
10751075
public static var EFTYPE: Errno { badFileTypeOrFormat }
10761076
#endif
10771077

1078-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1078+
#if DARWIN
10791079
/// Authentication error.
10801080
///
10811081
/// The authentication ticket used to mount an NFS file system was invalid.
@@ -1102,7 +1102,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
11021102
public static var ENEEDAUTH: Errno { needAuthenticator }
11031103
#endif
11041104

1105-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1105+
#if DARWIN
11061106
/// Device power is off.
11071107
///
11081108
/// The corresponding C error is `EPWROFF`.
@@ -1142,7 +1142,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
11421142
public static var EOVERFLOW: Errno { overflow }
11431143
#endif
11441144

1145-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1145+
#if DARWIN
11461146
/// Bad executable or shared library.
11471147
///
11481148
/// The executable or shared library being referenced was malformed.
@@ -1246,7 +1246,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
12461246
@available(*, unavailable, renamed: "illegalByteSequence")
12471247
public static var EILSEQ: Errno { illegalByteSequence }
12481248

1249-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1249+
#if DARWIN
12501250
/// Attribute not found.
12511251
///
12521252
/// The specified extended attribute doesn't exist.
@@ -1413,7 +1413,7 @@ extension Errno {
14131413
@available(*, unavailable, renamed: "tooManyRemoteLevels")
14141414
public static var EREMOTE: Errno { tooManyRemoteLevels }
14151415

1416-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1416+
#if DARWIN
14171417
/// No such policy registered.
14181418
///
14191419
/// The corresponding C error is `ENOPOLICY`.
@@ -1447,7 +1447,7 @@ extension Errno {
14471447
public static var EOWNERDEAD: Errno { previousOwnerDied }
14481448
#endif
14491449

1450-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1450+
#if DARWIN
14511451
/// Interface output queue is full.
14521452
///
14531453
/// The corresponding C error is `EQFULL`.

Sources/System/FileDescriptor.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ extension FileDescriptor {
185185
@available(*, unavailable, renamed: "exclusiveCreate")
186186
public static var O_EXCL: OpenOptions { exclusiveCreate }
187187

188-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
188+
#if DARWIN
189189
/// Indicates that opening the file
190190
/// atomically obtains a shared lock on the file.
191191
///
@@ -253,7 +253,7 @@ extension FileDescriptor {
253253
public static var O_DIRECTORY: OpenOptions { directory }
254254
#endif
255255

256-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
256+
#if DARWIN
257257
/// Indicates that opening the file
258258
/// opens symbolic links instead of following them.
259259
///
@@ -357,7 +357,7 @@ extension FileDescriptor {
357357

358358
// TODO: These are available on some versions of Linux with appropriate
359359
// macro defines.
360-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
360+
#if DARWIN
361361
/// Indicates that the offset should be set
362362
/// to the next hole after the specified number of bytes.
363363
///
@@ -419,7 +419,7 @@ extension FileDescriptor.SeekOrigin
419419
case .start: return "start"
420420
case .current: return "current"
421421
case .end: return "end"
422-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
422+
#if DARWIN
423423
case .nextHole: return "nextHole"
424424
case .nextData: return "nextData"
425425
#endif
@@ -438,7 +438,7 @@ extension FileDescriptor.OpenOptions
438438
/// A textual representation of the open options.
439439
@inline(never)
440440
public var description: String {
441-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
441+
#if DARWIN
442442
let descriptions: [(Element, StaticString)] = [
443443
(.nonBlocking, ".nonBlocking"),
444444
(.append, ".append"),

Sources/System/Internals/CInterop.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
See https://swift.org/LICENSE.txt for license information
88
*/
99

10-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
10+
#if DARWIN
1111
import Darwin
1212
#elseif os(Windows)
1313
import CSystem

Sources/System/Internals/Constants.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// they can be used anywhere without imports and without confusion to
1212
// unavailable local decls.
1313

14-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
14+
#if DARWIN
1515
import Darwin
1616
#elseif os(Windows)
1717
import CSystem
@@ -26,7 +26,7 @@ import Musl
2626
#endif
2727

2828
// MARK: errno
29-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
29+
#if DARWIN
3030
@_alwaysEmitIntoClient
3131
internal var _ERRNO_NOT_USED: CInt { 0 }
3232
#endif
@@ -272,7 +272,7 @@ internal var _EHOSTUNREACH: CInt { EHOSTUNREACH }
272272
@_alwaysEmitIntoClient
273273
internal var _ENOTEMPTY: CInt { ENOTEMPTY }
274274

275-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
275+
#if DARWIN
276276
@_alwaysEmitIntoClient
277277
internal var _EPROCLIM: CInt { EPROCLIM }
278278
#endif
@@ -313,7 +313,7 @@ internal var _EREMOTE: CInt {
313313
#endif
314314
}
315315

316-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
316+
#if DARWIN
317317
@_alwaysEmitIntoClient
318318
internal var _EBADRPC: CInt { EBADRPC }
319319

@@ -336,7 +336,7 @@ internal var _ENOLCK: CInt { ENOLCK }
336336
@_alwaysEmitIntoClient
337337
internal var _ENOSYS: CInt { ENOSYS }
338338

339-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
339+
#if DARWIN
340340
@_alwaysEmitIntoClient
341341
internal var _EFTYPE: CInt { EFTYPE }
342342

@@ -358,7 +358,7 @@ internal var _EDEVERR: CInt { EDEVERR }
358358
internal var _EOVERFLOW: CInt { EOVERFLOW }
359359
#endif
360360

361-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
361+
#if DARWIN
362362
@_alwaysEmitIntoClient
363363
internal var _EBADEXEC: CInt { EBADEXEC }
364364

@@ -386,7 +386,7 @@ internal var _ENOMSG: CInt { ENOMSG }
386386
@_alwaysEmitIntoClient
387387
internal var _EILSEQ: CInt { EILSEQ }
388388

389-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
389+
#if DARWIN
390390
@_alwaysEmitIntoClient
391391
internal var _ENOATTR: CInt { ENOATTR }
392392
#endif
@@ -424,7 +424,7 @@ internal var _ETIME: CInt { ETIME }
424424
@_alwaysEmitIntoClient
425425
internal var _EOPNOTSUPP: CInt { EOPNOTSUPP }
426426

427-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
427+
#if DARWIN
428428
@_alwaysEmitIntoClient
429429
internal var _ENOPOLICY: CInt { ENOPOLICY }
430430
#endif
@@ -437,7 +437,7 @@ internal var _ENOTRECOVERABLE: CInt { ENOTRECOVERABLE }
437437
internal var _EOWNERDEAD: CInt { EOWNERDEAD }
438438
#endif
439439

440-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
440+
#if DARWIN
441441
@_alwaysEmitIntoClient
442442
internal var _EQFULL: CInt { EQFULL }
443443

@@ -472,7 +472,7 @@ internal var _O_NONBLOCK: CInt { O_NONBLOCK }
472472
@_alwaysEmitIntoClient
473473
internal var _O_APPEND: CInt { O_APPEND }
474474

475-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
475+
#if DARWIN
476476
@_alwaysEmitIntoClient
477477
internal var _O_SHLOCK: CInt { O_SHLOCK }
478478

@@ -498,7 +498,7 @@ internal var _O_TRUNC: CInt { O_TRUNC }
498498
@_alwaysEmitIntoClient
499499
internal var _O_EXCL: CInt { O_EXCL }
500500

501-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
501+
#if DARWIN
502502
@_alwaysEmitIntoClient
503503
internal var _O_EVTONLY: CInt { O_EVTONLY }
504504
#endif
@@ -512,7 +512,7 @@ internal var _O_NOCTTY: CInt { O_NOCTTY }
512512
internal var _O_DIRECTORY: CInt { O_DIRECTORY }
513513
#endif
514514

515-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
515+
#if DARWIN
516516
@_alwaysEmitIntoClient
517517
internal var _O_SYMLINK: CInt { O_SYMLINK }
518518
#endif
@@ -531,7 +531,7 @@ internal var _SEEK_CUR: CInt { SEEK_CUR }
531531
@_alwaysEmitIntoClient
532532
internal var _SEEK_END: CInt { SEEK_END }
533533

534-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
534+
#if DARWIN
535535
@_alwaysEmitIntoClient
536536
internal var _SEEK_HOLE: CInt { SEEK_HOLE }
537537

Sources/System/Internals/Exports.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
// TODO: Should CSystem just include all the header files we need?
1414

15-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
15+
#if DARWIN
1616
import Darwin
1717
#elseif os(Windows)
1818
import CSystem
@@ -31,7 +31,7 @@ internal typealias _COffT = off_t
3131

3232
// MARK: syscalls and variables
3333

34-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
34+
#if DARWIN
3535
internal var system_errno: CInt {
3636
get { Darwin.errno }
3737
set { Darwin.errno = newValue }

Sources/System/Internals/Syscalls.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
See https://swift.org/LICENSE.txt for license information
88
*/
99

10-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
10+
#if DARWIN
1111
import Darwin
1212
#elseif canImport(Glibc)
1313
import Glibc

Sources/System/MachPort.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
See https://swift.org/LICENSE.txt for license information
88
*/
99

10-
#if swift(>=5.9) && (os(macOS) || os(iOS) || os(watchOS) || os(tvOS))
10+
#if swift(>=5.9) && DARWIN
1111

1212
import Darwin.Mach
1313

Tests/SystemTests/ErrnoTest.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ final class ErrnoTest: XCTestCase {
106106
XCTAssert(EHOSTUNREACH == Errno.noRouteToHost.rawValue)
107107
XCTAssert(ENOTEMPTY == Errno.directoryNotEmpty.rawValue)
108108

109-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
109+
#if DARWIN
110110
XCTAssert(EPROCLIM == Errno.tooManyProcesses.rawValue)
111111
#endif
112112

@@ -120,7 +120,7 @@ final class ErrnoTest: XCTestCase {
120120
XCTAssert(ESTALE == Errno.staleNFSFileHandle.rawValue)
121121
#endif
122122

123-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
123+
#if DARWIN
124124
XCTAssert(EBADRPC == Errno.rpcUnsuccessful.rawValue)
125125
XCTAssert(ERPCMISMATCH == Errno.rpcVersionMismatch.rawValue)
126126
XCTAssert(EPROGUNAVAIL == Errno.rpcProgramUnavailable.rawValue)
@@ -131,7 +131,7 @@ final class ErrnoTest: XCTestCase {
131131
XCTAssert(ENOLCK == Errno.noLocks.rawValue)
132132
XCTAssert(ENOSYS == Errno.noFunction.rawValue)
133133

134-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
134+
#if DARWIN
135135
XCTAssert(EFTYPE == Errno.badFileTypeOrFormat.rawValue)
136136
XCTAssert(EAUTH == Errno.authenticationError.rawValue)
137137
XCTAssert(ENEEDAUTH == Errno.needAuthenticator.rawValue)
@@ -143,7 +143,7 @@ final class ErrnoTest: XCTestCase {
143143
XCTAssert(EOVERFLOW == Errno.overflow.rawValue)
144144
#endif
145145

146-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
146+
#if DARWIN
147147
XCTAssert(EBADEXEC == Errno.badExecutable.rawValue)
148148
XCTAssert(EBADARCH == Errno.badCPUType.rawValue)
149149
XCTAssert(ESHLIBVERS == Errno.sharedLibraryVersionMismatch.rawValue)
@@ -157,7 +157,7 @@ final class ErrnoTest: XCTestCase {
157157
#endif
158158
XCTAssert(EILSEQ == Errno.illegalByteSequence.rawValue)
159159

160-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
160+
#if DARWIN
161161
XCTAssert(ENOATTR == Errno.attributeNotFound.rawValue)
162162
#endif
163163

@@ -183,7 +183,7 @@ final class ErrnoTest: XCTestCase {
183183
XCTAssert(EREMOTE == Errno.tooManyRemoteLevels.rawValue)
184184
#endif
185185

186-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
186+
#if DARWIN
187187
XCTAssert(ENOPOLICY == Errno.noSuchPolicy.rawValue)
188188
#endif
189189

@@ -192,7 +192,7 @@ final class ErrnoTest: XCTestCase {
192192
XCTAssert(EOWNERDEAD == Errno.previousOwnerDied.rawValue)
193193
#endif
194194

195-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
195+
#if DARWIN
196196
XCTAssert(EQFULL == Errno.outputQueueFull.rawValue)
197197
XCTAssert(ELAST == Errno.lastErrnoValue.rawValue)
198198
#endif

Tests/SystemTests/FileTypesTest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class FileDescriptorTest: XCTestCase {
4242
#endif
4343

4444
// BSD only
45-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
45+
#if DARWIN
4646
XCTAssertEqual(O_SHLOCK, FileDescriptor.OpenOptions.sharedLock.rawValue)
4747
XCTAssertEqual(O_EXLOCK, FileDescriptor.OpenOptions.exclusiveLock.rawValue)
4848
XCTAssertEqual(O_SYMLINK, FileDescriptor.OpenOptions.symlink.rawValue)
@@ -53,7 +53,7 @@ final class FileDescriptorTest: XCTestCase {
5353
XCTAssertEqual(SEEK_CUR, FileDescriptor.SeekOrigin.current.rawValue)
5454
XCTAssertEqual(SEEK_END, FileDescriptor.SeekOrigin.end.rawValue)
5555

56-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
56+
#if DARWIN
5757
XCTAssertEqual(SEEK_HOLE, FileDescriptor.SeekOrigin.nextHole.rawValue)
5858
XCTAssertEqual(SEEK_DATA, FileDescriptor.SeekOrigin.nextData.rawValue)
5959
#endif

0 commit comments

Comments
 (0)