Compare commits

..
18 Commits
Author SHA1 Message Date
Karoy Lorentey f9266c8518 Merge pull request #177 from lorentey/fix-cmake
[1.3][CMake] Restore to working order on Apple platforms
2024-05-15 14:48:03 -07:00
Karoy Lorentey b7dc8e8e41 [CMake] Restore to working order on Apple platforms 2024-05-15 14:30:14 -07:00
Guillaume Lessard 7d45e0dd46 Update README.md to refer to 1.3.0 2024-05-12 11:40:14 -07:00
Guillaume Lessard ab09f04cfe Merge pull request #173 from lorentey/codeowners-1.3.0
Add CODEOWNERS
2024-05-10 17:07:55 -07:00
Karoy Lorentey 0cf079efea Add CODEOWNERS 2024-05-10 17:05:37 -07:00
Mishal Shah 52f603c6b3 [CI] Remove support for Swift 5.7 2024-05-10 16:31:46 -07:00
Guillaume Lessard de1f8bce5e Merge pull request #172 from glessard/visionOS-support-for-1.3.0
[1.3.0] visionOS support for 1.3.0
2024-05-10 16:23:53 -07:00
Mishal Shah 0368ce547b Add support for Swift CI on release/1.3.0 2024-05-10 16:18:08 -07:00
Guillaume Lessard 7b14e48d0d Remove the repeated list of Darwin-based platforms
Replaced with a constant defined in the package manifest.
2024-05-10 16:09:22 -07:00
Guillaume Lessard c456f4186e Change the package manifest to support visionOS 2024-05-10 16:02:32 -07:00
Karoy Lorentey ec395a7aa2 Merge pull request #171 from lorentey/require-5.8
[1.3.0] Require Swift 5.8
2024-05-10 15:59:40 -07:00
Karoy Lorentey f1f59e148f Update gitignore 2024-05-10 15:55:04 -07:00
Karoy Lorentey 37a5bbb965 Require Swift 5.8 or better 2024-05-10 15:54:56 -07:00
Karoy Lorentey f07d14ddb1 Merge pull request #168 from glessard/cherry-pick-pr148
Cherry-pick changes from PR148
2024-05-10 15:41:26 -07:00
Guillaume LessardandFinagolfin 9620c1d30e Cherry-pick changes from PR148
Co-authored-by: Finagolfin <finagolfin@tuta.io>
2024-05-09 22:24:04 -07:00
Guillaume LessardandHiroshi Yamauchi c7259554b5 Cherry-pick changes from PR151
Co-authored-by: Hiroshi Yamauchi <hjyamauchi@gmail.com>
2024-05-09 22:10:26 -07:00
Guillaume LessardandMax Desiatov c3a7235bf7 Cherry-pick changes from PR133
Co-authored-by: Max Desiatov <m_desiatov@apple.com>
2024-05-09 19:10:58 -07:00
Guillaume Lessard e5a56da50e Cherry-pick changes from PR154 2024-05-09 16:03:48 -07:00
24 changed files with 199 additions and 64 deletions

No files matched your search

+13
View File
@@ -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
+1
View File
@@ -4,3 +4,4 @@
/*.xcodeproj
xcuserdata/
.*.sw?
/.swiftpm
+5
View File
@@ -0,0 +1,5 @@
LinuxSwiftPackageJob {
swift_version_tag = "5.10-jammy"
repo = "swift-system"
branch = "release/1.3.0"
}
+5
View File
@@ -0,0 +1,5 @@
LinuxSwiftPackageJob {
swift_version_tag = "5.8-jammy"
repo = "swift-system"
branch = "release/1.3.0"
}
+5
View File
@@ -0,0 +1,5 @@
LinuxSwiftPackageJob {
swift_version_tag = "5.9-jammy"
repo = "swift-system"
branch = "release/1.3.0"
}
+5
View File
@@ -0,0 +1,5 @@
macOSSwiftPackageJob {
swift_version = "6.0"
repo = "swift-system"
branch = "release/1.3.0"
}
+5
View File
@@ -0,0 +1,5 @@
LinuxSwiftPackageJob {
nightly_docker_tag = "nightly-6.0-jammy"
repo = "swift-system"
branch = "release/1.3.0"
}
+5
View File
@@ -0,0 +1,5 @@
macOSSwiftPackageJob {
swift_version = "main"
repo = "swift-system"
branch = "release/1.3.0"
}
+5
View File
@@ -0,0 +1,5 @@
LinuxSwiftPackageJob {
nightly_docker_tag = "nightly-jammy"
repo = "swift-system"
branch = "release/1.3.0"
}
+7
View File
@@ -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"
}
+12 -4
View File
@@ -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
@@ -12,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: [
@@ -31,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)),
]),
]
)
+2 -2
View File
@@ -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: [
+4
View File
@@ -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)
+10 -10
View File
@@ -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`.
+5 -5
View File
@@ -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"),
+7 -4
View File
@@ -14,14 +14,17 @@
@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(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
+22 -15
View File
@@ -11,19 +11,22 @@
// 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(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
// MARK: errno
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if SYSTEM_PACKAGE_DARWIN
@_alwaysEmitIntoClient
internal var _ERRNO_NOT_USED: CInt { 0 }
#endif
@@ -269,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
@@ -310,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 }
@@ -333,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 }
@@ -355,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 }
@@ -383,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
@@ -417,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
@@ -430,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 }
@@ -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 }
@@ -461,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 }
@@ -487,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
@@ -501,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
@@ -520,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 }
+14 -6
View File
@@ -12,14 +12,17 @@
// 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(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
@@ -28,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 }
@@ -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
+20 -2
View File
@@ -7,10 +7,12 @@
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 os(Linux) || os(FreeBSD) || os(Android)
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif os(Windows)
import ucrt
#else
@@ -69,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
@@ -99,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 {
+13 -6
View File
@@ -141,31 +141,38 @@ extension SystemString: RangeReplaceableCollection {
nullTerminatedStorage.reserveCapacity(1 + n)
}
// TODO: Below include null terminator, is this desired?
internal func withContiguousStorageIfAvailable<R>(
_ body: (UnsafeBufferPointer<SystemChar>) 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<R>(
_ body: (inout UnsafeMutableBufferPointer<SystemChar>) 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<SystemChar>(
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<T>(
_ f: (UnsafeBufferPointer<SystemChar>) throws -> T
) rethrows -> T {
try withContiguousStorageIfAvailable(f)!
try nullTerminatedStorage.withContiguousStorageIfAvailable(f)!
}
internal func withCodeUnits<T>(
+7 -7
View File
@@ -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
@@ -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
}
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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()