From e5a56da50e50f0aabf1778f08be679617ef328f7 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Thu, 9 May 2024 15:57:29 -0700 Subject: [PATCH 01/13] Cherry-pick changes from PR154 --- Sources/System/SystemString.swift | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Sources/System/SystemString.swift b/Sources/System/SystemString.swift index a918a929..c26d904d 100644 --- a/Sources/System/SystemString.swift +++ b/Sources/System/SystemString.swift @@ -141,31 +141,38 @@ extension SystemString: RangeReplaceableCollection { nullTerminatedStorage.reserveCapacity(1 + n) } - // TODO: Below include null terminator, is this desired? - internal func withContiguousStorageIfAvailable( _ body: (UnsafeBufferPointer) throws -> R ) rethrows -> R? { - try nullTerminatedStorage.withContiguousStorageIfAvailable(body) + // Do not include the null terminator, it is outside the Collection + try nullTerminatedStorage.withContiguousStorageIfAvailable { + try body(.init(start: $0.baseAddress, count: $0.count-1)) + } } internal mutating func withContiguousMutableStorageIfAvailable( _ body: (inout UnsafeMutableBufferPointer) throws -> R ) rethrows -> R? { defer { _invariantCheck() } - return try nullTerminatedStorage.withContiguousMutableStorageIfAvailable(body) + // Do not include the null terminator, it is outside the Collection + return try nullTerminatedStorage.withContiguousMutableStorageIfAvailable { + var buffer = UnsafeMutableBufferPointer( + start: $0.baseAddress, count: $0.count-1 + ) + return try body(&buffer) + } } } extension SystemString: Hashable, Codable {} extension SystemString { - // TODO: Below include null terminator, is this desired? + // withSystemChars includes the null terminator internal func withSystemChars( _ f: (UnsafeBufferPointer) throws -> T ) rethrows -> T { - try withContiguousStorageIfAvailable(f)! + try nullTerminatedStorage.withContiguousStorageIfAvailable(f)! } internal func withCodeUnits( From c3a7235bf7cf5e92e8286e82773c91118734cfcf Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Thu, 9 May 2024 15:32:45 -0700 Subject: [PATCH 02/13] Cherry-pick changes from PR133 Co-authored-by: Max Desiatov --- Sources/System/Internals/CInterop.swift | 9 ++++++--- Sources/System/Internals/Constants.swift | 11 +++++++++-- Sources/System/Internals/Exports.swift | 16 ++++++++++++---- Sources/System/Internals/Syscalls.swift | 4 +++- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Sources/System/Internals/CInterop.swift b/Sources/System/Internals/CInterop.swift index cb84a590..e3cb3f2b 100644 --- a/Sources/System/Internals/CInterop.swift +++ b/Sources/System/Internals/CInterop.swift @@ -16,12 +16,15 @@ public typealias CModeT = CInterop.Mode #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) import Darwin -#elseif os(Linux) || os(FreeBSD) || os(Android) -@_implementationOnly import CSystem -import Glibc #elseif os(Windows) import CSystem import ucrt +#elseif canImport(Glibc) +@_implementationOnly import CSystem +import Glibc +#elseif canImport(Musl) +@_implementationOnly import CSystem +import Musl #else #error("Unsupported Platform") #endif diff --git a/Sources/System/Internals/Constants.swift b/Sources/System/Internals/Constants.swift index 5489a550..12e42bed 100644 --- a/Sources/System/Internals/Constants.swift +++ b/Sources/System/Internals/Constants.swift @@ -13,11 +13,14 @@ #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) import Darwin -#elseif os(Linux) || os(FreeBSD) || os(Android) -import Glibc #elseif os(Windows) import CSystem import ucrt +#elseif canImport(Glibc) +import Glibc +#elseif canImport(Musl) +import CSystem +import Musl #else #error("Unsupported Platform") #endif @@ -450,9 +453,13 @@ internal var _O_WRONLY: CInt { O_WRONLY } internal var _O_RDWR: CInt { O_RDWR } #if !os(Windows) +#if canImport(Musl) +internal var _O_ACCMODE: CInt { 0x03|O_SEARCH } +#else // TODO: API? @_alwaysEmitIntoClient internal var _O_ACCMODE: CInt { O_ACCMODE } +#endif @_alwaysEmitIntoClient internal var _O_NONBLOCK: CInt { O_NONBLOCK } diff --git a/Sources/System/Internals/Exports.swift b/Sources/System/Internals/Exports.swift index 5c0a58a6..2879e134 100644 --- a/Sources/System/Internals/Exports.swift +++ b/Sources/System/Internals/Exports.swift @@ -14,12 +14,15 @@ #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) import Darwin -#elseif os(Linux) || os(FreeBSD) || os(Android) -@_implementationOnly import CSystem -import Glibc #elseif os(Windows) import CSystem import ucrt +#elseif canImport(Glibc) +@_implementationOnly import CSystem +import Glibc +#elseif canImport(Musl) +@_implementationOnly import CSystem +import Musl #else #error("Unsupported Platform") #endif @@ -45,11 +48,16 @@ internal var system_errno: CInt { _ = ucrt._set_errno(newValue) } } -#else +#elseif canImport(Glibc) internal var system_errno: CInt { get { Glibc.errno } set { Glibc.errno = newValue } } +#elseif canImport(Musl) +internal var system_errno: CInt { + get { Musl.errno } + set { Musl.errno = newValue } +} #endif // MARK: C stdlib decls diff --git a/Sources/System/Internals/Syscalls.swift b/Sources/System/Internals/Syscalls.swift index b22d6a3f..85d0e1c9 100644 --- a/Sources/System/Internals/Syscalls.swift +++ b/Sources/System/Internals/Syscalls.swift @@ -9,8 +9,10 @@ #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) import Darwin -#elseif os(Linux) || os(FreeBSD) || os(Android) +#elseif canImport(Glibc) import Glibc +#elseif canImport(Musl) +import Musl #elseif os(Windows) import ucrt #else From c7259554b5d70f2474d9495b256023a8dec50b89 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Thu, 9 May 2024 22:00:27 -0700 Subject: [PATCH 03/13] Cherry-pick changes from PR151 Co-authored-by: Hiroshi Yamauchi --- cmake/modules/SwiftSupport.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake index 82961db3..a73a4e57 100644 --- a/cmake/modules/SwiftSupport.cmake +++ b/cmake/modules/SwiftSupport.cmake @@ -17,7 +17,7 @@ See https://swift.org/LICENSE.txt for license information function(get_swift_host_arch result_var_name) if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") set("${result_var_name}" "x86_64" PARENT_SCOPE) - elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AArch64|aarch64|arm64") + elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AArch64|aarch64|arm64|ARM64") if(CMAKE_SYSTEM_NAME MATCHES Darwin) set("${result_var_name}" "arm64" PARENT_SCOPE) else() From 9620c1d30eb666e4b1d15f7c5efa8dfc0bd33b77 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Thu, 9 May 2024 22:24:04 -0700 Subject: [PATCH 04/13] Cherry-pick changes from PR148 Co-authored-by: Finagolfin --- Sources/System/Internals/Syscalls.swift | 16 +++++++++++++++ Tests/SystemTests/FileOperationsTest.swift | 24 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Sources/System/Internals/Syscalls.swift b/Sources/System/Internals/Syscalls.swift index 85d0e1c9..04d12db3 100644 --- a/Sources/System/Internals/Syscalls.swift +++ b/Sources/System/Internals/Syscalls.swift @@ -71,7 +71,15 @@ internal func system_pread( #if ENABLE_MOCKING if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) } #endif +#if os(Android) + var zero = UInt8.zero + return withUnsafeMutablePointer(to: &zero) { + // this pread has a non-nullable `buf` pointer + pread(fd, buf ?? UnsafeMutableRawPointer($0), nbyte, offset) + } +#else return pread(fd, buf, nbyte, offset) +#endif } // lseek @@ -101,7 +109,15 @@ internal func system_pwrite( #if ENABLE_MOCKING if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) } #endif +#if os(Android) + var zero = UInt8.zero + return withUnsafeMutablePointer(to: &zero) { + // this pwrite has a non-nullable `buf` pointer + pwrite(fd, buf ?? UnsafeRawPointer($0), nbyte, offset) + } +#else return pwrite(fd, buf, nbyte, offset) +#endif } internal func system_dup(_ fd: Int32) -> Int32 { diff --git a/Tests/SystemTests/FileOperationsTest.swift b/Tests/SystemTests/FileOperationsTest.swift index 419e1c97..fce119fe 100644 --- a/Tests/SystemTests/FileOperationsTest.swift +++ b/Tests/SystemTests/FileOperationsTest.swift @@ -86,6 +86,30 @@ final class FileOperationsTest: XCTestCase { for test in syscallTestCases { test.runAllTests() } } + func testWriteFromEmptyBuffer() throws { + let fd = try FileDescriptor.open(FilePath("/dev/null"), .writeOnly) + let written1 = try fd.write(toAbsoluteOffset: 0, .init(start: nil, count: 0)) + XCTAssertEqual(written1, 0) + + let pointer = UnsafeMutableRawPointer.allocate(byteCount: 8, alignment: 8) + defer { pointer.deallocate() } + let empty = UnsafeRawBufferPointer(start: pointer, count: 0) + let written2 = try fd.write(toAbsoluteOffset: 0, empty) + XCTAssertEqual(written2, 0) + } + + func testReadToEmptyBuffer() throws { + let fd = try FileDescriptor.open(FilePath("/dev/random"), .readOnly) + let read1 = try fd.read(fromAbsoluteOffset: 0, into: .init(start: nil, count: 0)) + XCTAssertEqual(read1, 0) + + let pointer = UnsafeMutableRawPointer.allocate(byteCount: 8, alignment: 8) + defer { pointer.deallocate() } + let empty = UnsafeMutableRawBufferPointer(start: pointer, count: 0) + let read2 = try fd.read(fromAbsoluteOffset: 0, into: empty) + XCTAssertEqual(read2, 0) + } + func testHelpers() { // TODO: Test writeAll, writeAll(toAbsoluteOffset), closeAfter } From 37a5bbb965369c2e1f236729db69b195867fc8f0 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Fri, 10 May 2024 15:54:56 -0700 Subject: [PATCH 05/13] Require Swift 5.8 or better --- Package.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index b081a872..60976ce2 100644 --- a/Package.swift +++ b/Package.swift @@ -1,10 +1,9 @@ -// swift-tools-version:5.2 -// The swift-tools-version declares the minimum version of Swift required to build this package. +// swift-tools-version:5.8 /* This source file is part of the Swift System open source project - Copyright (c) 2020 Apple Inc. and the Swift System project authors + Copyright (c) 2020-2024 Apple Inc. and the Swift System project authors Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information From f1f59e148f1706caac25341123af4c45c617b1cc Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Fri, 10 May 2024 15:55:04 -0700 Subject: [PATCH 06/13] Update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 36bbb6fb..3ca0750e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /*.xcodeproj xcuserdata/ .*.sw? +/.swiftpm From c456f4186e21b43e9a9f39f1a3231d5ffd44492e Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Fri, 10 May 2024 16:01:36 -0700 Subject: [PATCH 07/13] Change the package manifest to support visionOS --- Package.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 60976ce2..e902aaa4 100644 --- a/Package.swift +++ b/Package.swift @@ -11,6 +11,13 @@ import PackageDescription +let DarwinPlatforms: [Platform] +#if swift(<5.9) +DarwinPlatforms = [.macOS, .iOS, .watchOS, .tvOS] +#else +DarwinPlatforms = [.macOS, .iOS, .watchOS, .tvOS, .visionOS] +#endif + let package = Package( name: "swift-system", products: [ @@ -30,13 +37,15 @@ let package = Package( ], swiftSettings: [ .define("SYSTEM_PACKAGE"), + .define("SYSTEM_PACKAGE_DARWIN", .when(platforms: DarwinPlatforms)), .define("ENABLE_MOCKING", .when(configuration: .debug)) ]), .testTarget( name: "SystemTests", dependencies: ["SystemPackage"], swiftSettings: [ - .define("SYSTEM_PACKAGE") + .define("SYSTEM_PACKAGE"), + .define("SYSTEM_PACKAGE_DARWIN", .when(platforms: DarwinPlatforms)), ]), ] ) From 7b14e48d0dc485b114efaa4129a33cb97286cdd9 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Fri, 10 May 2024 16:09:22 -0700 Subject: [PATCH 08/13] Remove the repeated list of Darwin-based platforms Replaced with a constant defined in the package manifest. --- Sources/System/Errno.swift | 20 +++++++++--------- Sources/System/FileDescriptor.swift | 10 ++++----- Sources/System/Internals/CInterop.swift | 2 +- Sources/System/Internals/Constants.swift | 26 ++++++++++++------------ Sources/System/Internals/Exports.swift | 4 ++-- Sources/System/Internals/Syscalls.swift | 2 +- Tests/SystemTests/ErrnoTest.swift | 14 ++++++------- Tests/SystemTests/FileTypesTest.swift | 4 ++-- 8 files changed, 41 insertions(+), 41 deletions(-) diff --git a/Sources/System/Errno.swift b/Sources/System/Errno.swift index e2ebadb3..0000f501 100644 --- a/Sources/System/Errno.swift +++ b/Sources/System/Errno.swift @@ -23,7 +23,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable { @_alwaysEmitIntoClient private init(_ raw: CInt) { self.init(rawValue: raw) } -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN /// Error. Not used. @_alwaysEmitIntoClient public static var notUsed: Errno { Errno(_ERRNO_NOT_USED) } @@ -911,7 +911,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable { @available(*, unavailable, renamed: "directoryNotEmpty") public static var ENOTEMPTY: Errno { directoryNotEmpty } -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN /// Too many processes. /// /// The corresponding C error is `EPROCLIM`. @@ -968,7 +968,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable { public static var ESTALE: Errno { staleNFSFileHandle } // TODO: Add Linux's RPC equivalents -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN /// The structure of the remote procedure call (RPC) is bad. /// @@ -1060,7 +1060,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable { public static var ENOSYS: Errno { noFunction } // BSD -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN /// Inappropriate file type or format. /// /// The file was the wrong type for the operation, @@ -1075,7 +1075,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable { public static var EFTYPE: Errno { badFileTypeOrFormat } #endif -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN /// Authentication error. /// /// The authentication ticket used to mount an NFS file system was invalid. @@ -1102,7 +1102,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable { public static var ENEEDAUTH: Errno { needAuthenticator } #endif -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN /// Device power is off. /// /// The corresponding C error is `EPWROFF`. @@ -1142,7 +1142,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable { public static var EOVERFLOW: Errno { overflow } #endif -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN /// Bad executable or shared library. /// /// The executable or shared library being referenced was malformed. @@ -1246,7 +1246,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable { @available(*, unavailable, renamed: "illegalByteSequence") public static var EILSEQ: Errno { illegalByteSequence } -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN /// Attribute not found. /// /// The specified extended attribute doesn't exist. @@ -1409,7 +1409,7 @@ extension Errno { @available(*, unavailable, renamed: "tooManyRemoteLevels") public static var EREMOTE: Errno { tooManyRemoteLevels } -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN /// No such policy registered. /// /// The corresponding C error is `ENOPOLICY`. @@ -1443,7 +1443,7 @@ extension Errno { public static var EOWNERDEAD: Errno { previousOwnerDied } #endif -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN /// Interface output queue is full. /// /// The corresponding C error is `EQFULL`. diff --git a/Sources/System/FileDescriptor.swift b/Sources/System/FileDescriptor.swift index fbb7df30..5ef5ad87 100644 --- a/Sources/System/FileDescriptor.swift +++ b/Sources/System/FileDescriptor.swift @@ -182,7 +182,7 @@ extension FileDescriptor { @available(*, unavailable, renamed: "exclusiveCreate") public static var O_EXCL: OpenOptions { exclusiveCreate } -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN /// Indicates that opening the file /// atomically obtains a shared lock on the file. /// @@ -250,7 +250,7 @@ extension FileDescriptor { public static var O_DIRECTORY: OpenOptions { directory } #endif -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN /// Indicates that opening the file /// opens symbolic links instead of following them. /// @@ -353,7 +353,7 @@ extension FileDescriptor { // TODO: These are available on some versions of Linux with appropriate // macro defines. -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN /// Indicates that the offset should be set /// to the next hole after the specified number of bytes. /// @@ -415,7 +415,7 @@ extension FileDescriptor.SeekOrigin case .start: return "start" case .current: return "current" case .end: return "end" -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN case .nextHole: return "nextHole" case .nextData: return "nextData" #endif @@ -434,7 +434,7 @@ extension FileDescriptor.OpenOptions /// A textual representation of the open options. @inline(never) public var description: String { -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN let descriptions: [(Element, StaticString)] = [ (.nonBlocking, ".nonBlocking"), (.append, ".append"), diff --git a/Sources/System/Internals/CInterop.swift b/Sources/System/Internals/CInterop.swift index e3cb3f2b..13abc752 100644 --- a/Sources/System/Internals/CInterop.swift +++ b/Sources/System/Internals/CInterop.swift @@ -14,7 +14,7 @@ @available(*, deprecated, renamed: "CInterop.Mode") public typealias CModeT = CInterop.Mode -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN import Darwin #elseif os(Windows) import CSystem diff --git a/Sources/System/Internals/Constants.swift b/Sources/System/Internals/Constants.swift index 12e42bed..53e215f7 100644 --- a/Sources/System/Internals/Constants.swift +++ b/Sources/System/Internals/Constants.swift @@ -11,7 +11,7 @@ // they can be used anywhere without imports and without confusion to // unavailable local decls. -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN import Darwin #elseif os(Windows) import CSystem @@ -26,7 +26,7 @@ import Musl #endif // MARK: errno -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN @_alwaysEmitIntoClient internal var _ERRNO_NOT_USED: CInt { 0 } #endif @@ -272,7 +272,7 @@ internal var _EHOSTUNREACH: CInt { EHOSTUNREACH } @_alwaysEmitIntoClient internal var _ENOTEMPTY: CInt { ENOTEMPTY } -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN @_alwaysEmitIntoClient internal var _EPROCLIM: CInt { EPROCLIM } #endif @@ -313,7 +313,7 @@ internal var _EREMOTE: CInt { #endif } -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN @_alwaysEmitIntoClient internal var _EBADRPC: CInt { EBADRPC } @@ -336,7 +336,7 @@ internal var _ENOLCK: CInt { ENOLCK } @_alwaysEmitIntoClient internal var _ENOSYS: CInt { ENOSYS } -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN @_alwaysEmitIntoClient internal var _EFTYPE: CInt { EFTYPE } @@ -358,7 +358,7 @@ internal var _EDEVERR: CInt { EDEVERR } internal var _EOVERFLOW: CInt { EOVERFLOW } #endif -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN @_alwaysEmitIntoClient internal var _EBADEXEC: CInt { EBADEXEC } @@ -386,7 +386,7 @@ internal var _ENOMSG: CInt { ENOMSG } @_alwaysEmitIntoClient internal var _EILSEQ: CInt { EILSEQ } -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN @_alwaysEmitIntoClient internal var _ENOATTR: CInt { ENOATTR } #endif @@ -420,7 +420,7 @@ internal var _ETIME: CInt { ETIME } @_alwaysEmitIntoClient internal var _EOPNOTSUPP: CInt { EOPNOTSUPP } -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN @_alwaysEmitIntoClient internal var _ENOPOLICY: CInt { ENOPOLICY } #endif @@ -433,7 +433,7 @@ internal var _ENOTRECOVERABLE: CInt { ENOTRECOVERABLE } internal var _EOWNERDEAD: CInt { EOWNERDEAD } #endif -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN @_alwaysEmitIntoClient internal var _EQFULL: CInt { EQFULL } @@ -468,7 +468,7 @@ internal var _O_NONBLOCK: CInt { O_NONBLOCK } @_alwaysEmitIntoClient internal var _O_APPEND: CInt { O_APPEND } -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN @_alwaysEmitIntoClient internal var _O_SHLOCK: CInt { O_SHLOCK } @@ -494,7 +494,7 @@ internal var _O_TRUNC: CInt { O_TRUNC } @_alwaysEmitIntoClient internal var _O_EXCL: CInt { O_EXCL } -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN @_alwaysEmitIntoClient internal var _O_EVTONLY: CInt { O_EVTONLY } #endif @@ -508,7 +508,7 @@ internal var _O_NOCTTY: CInt { O_NOCTTY } internal var _O_DIRECTORY: CInt { O_DIRECTORY } #endif -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN @_alwaysEmitIntoClient internal var _O_SYMLINK: CInt { O_SYMLINK } #endif @@ -527,7 +527,7 @@ internal var _SEEK_CUR: CInt { SEEK_CUR } @_alwaysEmitIntoClient internal var _SEEK_END: CInt { SEEK_END } -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN @_alwaysEmitIntoClient internal var _SEEK_HOLE: CInt { SEEK_HOLE } diff --git a/Sources/System/Internals/Exports.swift b/Sources/System/Internals/Exports.swift index 2879e134..5b08725c 100644 --- a/Sources/System/Internals/Exports.swift +++ b/Sources/System/Internals/Exports.swift @@ -12,7 +12,7 @@ // TODO: Should CSystem just include all the header files we need? -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN import Darwin #elseif os(Windows) import CSystem @@ -31,7 +31,7 @@ internal typealias _COffT = off_t // MARK: syscalls and variables -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN internal var system_errno: CInt { get { Darwin.errno } set { Darwin.errno = newValue } diff --git a/Sources/System/Internals/Syscalls.swift b/Sources/System/Internals/Syscalls.swift index 04d12db3..555f63b4 100644 --- a/Sources/System/Internals/Syscalls.swift +++ b/Sources/System/Internals/Syscalls.swift @@ -7,7 +7,7 @@ See https://swift.org/LICENSE.txt for license information */ -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN import Darwin #elseif canImport(Glibc) import Glibc diff --git a/Tests/SystemTests/ErrnoTest.swift b/Tests/SystemTests/ErrnoTest.swift index 4bbe88f6..96e7df32 100644 --- a/Tests/SystemTests/ErrnoTest.swift +++ b/Tests/SystemTests/ErrnoTest.swift @@ -84,7 +84,7 @@ final class ErrnoTest: XCTestCase { XCTAssert(EHOSTUNREACH == Errno.noRouteToHost.rawValue) XCTAssert(ENOTEMPTY == Errno.directoryNotEmpty.rawValue) -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN XCTAssert(EPROCLIM == Errno.tooManyProcesses.rawValue) #endif @@ -92,7 +92,7 @@ final class ErrnoTest: XCTestCase { XCTAssert(EDQUOT == Errno.diskQuotaExceeded.rawValue) XCTAssert(ESTALE == Errno.staleNFSFileHandle.rawValue) -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN XCTAssert(EBADRPC == Errno.rpcUnsuccessful.rawValue) XCTAssert(ERPCMISMATCH == Errno.rpcVersionMismatch.rawValue) XCTAssert(EPROGUNAVAIL == Errno.rpcProgramUnavailable.rawValue) @@ -103,7 +103,7 @@ final class ErrnoTest: XCTestCase { XCTAssert(ENOLCK == Errno.noLocks.rawValue) XCTAssert(ENOSYS == Errno.noFunction.rawValue) -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN XCTAssert(EFTYPE == Errno.badFileTypeOrFormat.rawValue) XCTAssert(EAUTH == Errno.authenticationError.rawValue) XCTAssert(ENEEDAUTH == Errno.needAuthenticator.rawValue) @@ -113,7 +113,7 @@ final class ErrnoTest: XCTestCase { XCTAssert(EOVERFLOW == Errno.overflow.rawValue) -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN XCTAssert(EBADEXEC == Errno.badExecutable.rawValue) XCTAssert(EBADARCH == Errno.badCPUType.rawValue) XCTAssert(ESHLIBVERS == Errno.sharedLibraryVersionMismatch.rawValue) @@ -125,7 +125,7 @@ final class ErrnoTest: XCTestCase { XCTAssert(ENOMSG == Errno.noMessage.rawValue) XCTAssert(EILSEQ == Errno.illegalByteSequence.rawValue) -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN XCTAssert(ENOATTR == Errno.attributeNotFound.rawValue) #endif @@ -144,14 +144,14 @@ final class ErrnoTest: XCTestCase { XCTAssert(ETOOMANYREFS == Errno.tooManyReferences.rawValue) XCTAssert(EREMOTE == Errno.tooManyRemoteLevels.rawValue) -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN XCTAssert(ENOPOLICY == Errno.noSuchPolicy.rawValue) #endif XCTAssert(ENOTRECOVERABLE == Errno.notRecoverable.rawValue) XCTAssert(EOWNERDEAD == Errno.previousOwnerDied.rawValue) -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN XCTAssert(EQFULL == Errno.outputQueueFull.rawValue) XCTAssert(ELAST == Errno.lastErrnoValue.rawValue) #endif diff --git a/Tests/SystemTests/FileTypesTest.swift b/Tests/SystemTests/FileTypesTest.swift index b8cf4969..8498cf5a 100644 --- a/Tests/SystemTests/FileTypesTest.swift +++ b/Tests/SystemTests/FileTypesTest.swift @@ -38,7 +38,7 @@ final class FileDescriptorTest: XCTestCase { XCTAssertEqual(O_CLOEXEC, FileDescriptor.OpenOptions.closeOnExec.rawValue) // BSD only -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN XCTAssertEqual(O_SHLOCK, FileDescriptor.OpenOptions.sharedLock.rawValue) XCTAssertEqual(O_EXLOCK, FileDescriptor.OpenOptions.exclusiveLock.rawValue) XCTAssertEqual(O_SYMLINK, FileDescriptor.OpenOptions.symlink.rawValue) @@ -49,7 +49,7 @@ final class FileDescriptorTest: XCTestCase { XCTAssertEqual(SEEK_CUR, FileDescriptor.SeekOrigin.current.rawValue) XCTAssertEqual(SEEK_END, FileDescriptor.SeekOrigin.end.rawValue) -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if SYSTEM_PACKAGE_DARWIN XCTAssertEqual(SEEK_HOLE, FileDescriptor.SeekOrigin.nextHole.rawValue) XCTAssertEqual(SEEK_DATA, FileDescriptor.SeekOrigin.nextData.rawValue) #endif From 0368ce547bf0193955fe538eea624233e7815cd1 Mon Sep 17 00:00:00 2001 From: Mishal Shah Date: Fri, 10 May 2024 16:18:08 -0700 Subject: [PATCH 09/13] Add support for Swift CI on release/1.3.0 --- .swiftci/5_10_ubuntu2204 | 5 +++++ .swiftci/5_7_ubuntu2204 | 5 +++++ .swiftci/5_8_ubuntu2204 | 5 +++++ .swiftci/5_9_ubuntu2204 | 5 +++++ .swiftci/nightly_6_0_macos | 5 +++++ .swiftci/nightly_6_0_ubuntu2204 | 5 +++++ .swiftci/nightly_main_macos | 5 +++++ .swiftci/nightly_main_ubuntu2204 | 5 +++++ .swiftci/nightly_main_windows | 7 +++++++ 9 files changed, 47 insertions(+) create mode 100644 .swiftci/5_10_ubuntu2204 create mode 100644 .swiftci/5_7_ubuntu2204 create mode 100644 .swiftci/5_8_ubuntu2204 create mode 100644 .swiftci/5_9_ubuntu2204 create mode 100644 .swiftci/nightly_6_0_macos create mode 100644 .swiftci/nightly_6_0_ubuntu2204 create mode 100644 .swiftci/nightly_main_macos create mode 100644 .swiftci/nightly_main_ubuntu2204 create mode 100644 .swiftci/nightly_main_windows diff --git a/.swiftci/5_10_ubuntu2204 b/.swiftci/5_10_ubuntu2204 new file mode 100644 index 00000000..05546359 --- /dev/null +++ b/.swiftci/5_10_ubuntu2204 @@ -0,0 +1,5 @@ +LinuxSwiftPackageJob { + swift_version_tag = "5.10-jammy" + repo = "swift-system" + branch = "release/1.3.0" +} diff --git a/.swiftci/5_7_ubuntu2204 b/.swiftci/5_7_ubuntu2204 new file mode 100644 index 00000000..b1568a38 --- /dev/null +++ b/.swiftci/5_7_ubuntu2204 @@ -0,0 +1,5 @@ +LinuxSwiftPackageJob { + swift_version_tag = "5.7-jammy" + repo = "swift-system" + branch = "release/1.3.0" +} diff --git a/.swiftci/5_8_ubuntu2204 b/.swiftci/5_8_ubuntu2204 new file mode 100644 index 00000000..141a58ee --- /dev/null +++ b/.swiftci/5_8_ubuntu2204 @@ -0,0 +1,5 @@ +LinuxSwiftPackageJob { + swift_version_tag = "5.8-jammy" + repo = "swift-system" + branch = "release/1.3.0" +} diff --git a/.swiftci/5_9_ubuntu2204 b/.swiftci/5_9_ubuntu2204 new file mode 100644 index 00000000..e834c959 --- /dev/null +++ b/.swiftci/5_9_ubuntu2204 @@ -0,0 +1,5 @@ +LinuxSwiftPackageJob { + swift_version_tag = "5.9-jammy" + repo = "swift-system" + branch = "release/1.3.0" +} diff --git a/.swiftci/nightly_6_0_macos b/.swiftci/nightly_6_0_macos new file mode 100644 index 00000000..62683c2b --- /dev/null +++ b/.swiftci/nightly_6_0_macos @@ -0,0 +1,5 @@ +macOSSwiftPackageJob { + swift_version = "6.0" + repo = "swift-system" + branch = "release/1.3.0" +} diff --git a/.swiftci/nightly_6_0_ubuntu2204 b/.swiftci/nightly_6_0_ubuntu2204 new file mode 100644 index 00000000..431f07cb --- /dev/null +++ b/.swiftci/nightly_6_0_ubuntu2204 @@ -0,0 +1,5 @@ +LinuxSwiftPackageJob { + nightly_docker_tag = "nightly-6.0-jammy" + repo = "swift-system" + branch = "release/1.3.0" +} diff --git a/.swiftci/nightly_main_macos b/.swiftci/nightly_main_macos new file mode 100644 index 00000000..7b3dcd78 --- /dev/null +++ b/.swiftci/nightly_main_macos @@ -0,0 +1,5 @@ +macOSSwiftPackageJob { + swift_version = "main" + repo = "swift-system" + branch = "release/1.3.0" +} diff --git a/.swiftci/nightly_main_ubuntu2204 b/.swiftci/nightly_main_ubuntu2204 new file mode 100644 index 00000000..58c94d57 --- /dev/null +++ b/.swiftci/nightly_main_ubuntu2204 @@ -0,0 +1,5 @@ +LinuxSwiftPackageJob { + nightly_docker_tag = "nightly-jammy" + repo = "swift-system" + branch = "release/1.3.0" +} diff --git a/.swiftci/nightly_main_windows b/.swiftci/nightly_main_windows new file mode 100644 index 00000000..e2d3bf26 --- /dev/null +++ b/.swiftci/nightly_main_windows @@ -0,0 +1,7 @@ +WindowsSwiftPackageWithDockerImageJob { + docker_image = "swiftlang/swift:nightly-windowsservercore-1809" + repo = "swift-system" + branch = "release/1.3.0" + sub_dir = "swift-system" + label = "windows-server-2019" +} From 52f603c6b38d924d63a950aacb6d630979f4b258 Mon Sep 17 00:00:00 2001 From: Mishal Shah Date: Fri, 10 May 2024 16:31:13 -0700 Subject: [PATCH 10/13] [CI] Remove support for Swift 5.7 --- .swiftci/5_7_ubuntu2204 | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .swiftci/5_7_ubuntu2204 diff --git a/.swiftci/5_7_ubuntu2204 b/.swiftci/5_7_ubuntu2204 deleted file mode 100644 index b1568a38..00000000 --- a/.swiftci/5_7_ubuntu2204 +++ /dev/null @@ -1,5 +0,0 @@ -LinuxSwiftPackageJob { - swift_version_tag = "5.7-jammy" - repo = "swift-system" - branch = "release/1.3.0" -} From 0cf079efeaf1889534f0366546a7fe2116d7918d Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Fri, 10 May 2024 17:05:37 -0700 Subject: [PATCH 11/13] Add CODEOWNERS --- .github/CODEOWNERS | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..70e4f6ca --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,13 @@ +# Lines starting with '#' are comments. +# Each line is a case-sensitive file pattern followed by one or more owners. +# Order is important. The last matching pattern has the most precedence. +# More information: https://docs.github.com/en/articles/about-code-owners +# +# Please mirror the repository's file hierarchy in case-sensitive lexicographic +# order. + +# Default owners +* @glessard @lorentey @milseman + +# Swift CI configuration files +.swiftci/ @shahmishal From 7d45e0dd46dc505cff02b9a44e24243d2b4354a3 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Sun, 12 May 2024 11:40:14 -0700 Subject: [PATCH 12/13] Update README.md to refer to 1.3.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 11e57eb2..4c74e3bf 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ To use the `SystemPackage` library in a SwiftPM project, add the following line to the dependencies in your `Package.swift` file: ```swift -.package(url: "https://github.com/apple/swift-system", from: "1.0.0"), +.package(url: "https://github.com/apple/swift-system", from: "1.3.0"), ``` Finally, include `"SystemPackage"` as a dependency for your executable target: @@ -37,7 +37,7 @@ Finally, include `"SystemPackage"` as a dependency for your executable target: let package = Package( // name, platforms, products, etc. dependencies: [ - .package(url: "https://github.com/apple/swift-system", from: "1.0.0"), + .package(url: "https://github.com/apple/swift-system", from: "1.3.0"), // other dependencies ], targets: [ From b7dc8e8e41b30079ec09602e44088295599645bd Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 15 May 2024 14:30:14 -0700 Subject: [PATCH 13/13] [CMake] Restore to working order on Apple platforms --- Sources/System/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/System/CMakeLists.txt b/Sources/System/CMakeLists.txt index 43958d31..4335200c 100644 --- a/Sources/System/CMakeLists.txt +++ b/Sources/System/CMakeLists.txt @@ -37,6 +37,10 @@ target_sources(SystemPackage PRIVATE target_link_libraries(SystemPackage PUBLIC CSystem) +set(SWIFT_SYSTEM_APPLE_PLATFORMS "Darwin" "iOS" "watchOS" "tvOS" "visionOS") +if(CMAKE_SYSTEM_NAME IN_LIST SWIFT_SYSTEM_APPLE_PLATFORMS) + target_compile_definitions(SystemPackage PRIVATE SYSTEM_PACKAGE_DARWIN) +endif() _install_target(SystemPackage) set_property(GLOBAL APPEND PROPERTY SWIFT_SYSTEM_EXPORTS SystemPackage)