Compare commits

..
8 Commits
Author SHA1 Message Date
tomer doron 5703dc2b4d update cmake setup so that the library can be used by SwiftPM cmake build (#73)
Update cmake setup so that the library can be used by SwiftPM cmake build

Motivation: integrate with SwiftPM

changes:
* rename the top level project to SwiftSystem instead of swift-system to align with other projects
* rename System to SystemPackage to align with SwifPM setup
* update architectures to include arm64
* Update cmake/modules/SwiftSystemConfig.cmake.in
* Update cmake/modules/SwiftSupport.cmake
2021-11-30 10:50:50 -07:00
Alex Martini 2fa26782e1 Merge pull request #69 from amartini51/docs/develop
Minor fixes in documentation comments
2021-11-09 10:11:05 -08:00
Alex Martini 0c291a65c2 Fix typo.
Fixes <rdar://problem/84559893>.
2021-11-08 19:43:49 -08:00
Alex Martini 0ac080ea56 Add missing period at end of abstract. 2021-11-08 19:43:30 -08:00
Alex Martini d2c4e4507a Fix spacing and indentation. 2021-11-08 19:43:30 -08:00
Alex Martini 78847afcd4 Remove stray word. 2021-11-08 19:43:30 -08:00
George Lyon 689390f50f Implement FileDescriptor.Pipe() (#58)
Adds support for pipe(2)
2021-09-27 16:02:52 -06:00
Michael Ilseman ce8b491073 Update README for 1.0 2021-09-01 09:26:18 -06:00
11 changed files with 118 additions and 34 deletions

No files matched your search

+2 -7
View File
@@ -8,7 +8,7 @@ See https://swift.org/LICENSE.txt for license information
#]]
cmake_minimum_required(VERSION 3.16.0)
project(swift-system
project(SwiftSystem
LANGUAGES C Swift)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
@@ -21,9 +21,4 @@ set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
include(SwiftSupport)
add_subdirectory(Sources)
get_property(SWIFT_SYSTEM_EXPORTS GLOBAL PROPERTY SWIFT_SYSTEM_EXPORTS)
export(TARGETS ${SWIFT_SYSTEM_EXPORTS}
NAMESPACE SwiftSystem::
FILE swift-system-config.cmake
EXPORT_LINK_INTERFACE_LIBRARIES)
add_subdirectory(cmake/modules)
+8 -11
View File
@@ -28,16 +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: "0.0.1"),
```
Because `SystemPackage` is under active development,
source-stability is only guaranteed within minor versions (e.g. between `0.0.3` and `0.0.4`).
If you don't want potentially source-breaking package updates,
use this dependency specification instead:
```swift
.package(url: "https://github.com/apple/swift-system", .upToNextMinor(from: "0.0.1")),
.package(url: "https://github.com/apple/swift-system", from: "1.0.0"),
```
Finally, include `"SystemPackage"` as a dependency for your executable target:
@@ -46,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: "0.0.1"),
.package(url: "https://github.com/apple/swift-system", from: "1.0.0"),
// other dependencies
],
targets: [
@@ -58,6 +49,12 @@ let package = Package(
)
```
## Source Stability
The Swift System package is source stable. The version numbers follow [Semantic Versioning][semver] -- source breaking changes to public API can only land in a new major version.
[semver]: https://semver.org
## Contributing
Before contributing, please read [CONTRIBUTING.md](CONTRIBUTING.md).
+8 -6
View File
@@ -7,7 +7,7 @@ Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
#]]
add_library(System
add_library(SystemPackage
Errno.swift
FileDescriptor.swift
FileHelpers.swift
@@ -17,7 +17,9 @@ add_library(System
SystemString.swift
Util.swift
UtilConsumers.swift)
target_sources(System PRIVATE
set_target_properties(SystemPackage PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
target_sources(SystemPackage PRIVATE
FilePath/FilePath.swift
FilePath/FilePathComponents.swift
FilePath/FilePathComponentView.swift
@@ -25,16 +27,16 @@ target_sources(System PRIVATE
FilePath/FilePathString.swift
FilePath/FilePathSyntax.swift
FilePath/FilePathWindows.swift)
target_sources(System PRIVATE
target_sources(SystemPackage PRIVATE
Internals/CInterop.swift
Internals/Constants.swift
Internals/Exports.swift
Internals/Mocking.swift
Internals/Syscalls.swift
Internals/WindowsSyscallAdapters.swift)
target_link_libraries(System PRIVATE
target_link_libraries(SystemPackage PRIVATE
CSystem)
_install_target(System)
set_property(GLOBAL APPEND PROPERTY SWIFT_SYSTEM_EXPORTS System)
_install_target(SystemPackage)
set_property(GLOBAL APPEND PROPERTY SWIFT_SYSTEM_EXPORTS SystemPackage)
+23
View File
@@ -370,4 +370,27 @@ extension FileDescriptor {
public func dup2() throws -> FileDescriptor {
fatalError("Not implemented")
}
#if !os(Windows)
/// Create a pipe, a unidirectional data channel which can be used for interprocess communication.
///
/// - Returns: The pair of file descriptors.
///
/// The corresponding C function is `pipe`.
@_alwaysEmitIntoClient
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
public static func pipe() throws -> (readEnd: FileDescriptor, writeEnd: FileDescriptor) {
try _pipe().get()
}
@usableFromInline
internal static func _pipe() -> Result<(readEnd: FileDescriptor, writeEnd: FileDescriptor), Errno> {
var fds: (Int32, Int32) = (-1, -1)
return withUnsafeMutablePointer(to: &fds) { pointer in
valueOrErrno(retryOnInterrupt: false) {
system_pipe(UnsafeMutableRawPointer(pointer).assumingMemoryBound(to: Int32.self))
}
}.map { _ in (.init(rawValue: fds.0), .init(rawValue: fds.1)) }
}
#endif
}
+2 -2
View File
@@ -16,7 +16,7 @@
/// encoding.
///
/// On construction, `FilePath` will normalize separators by removing
/// reduncant intermediary separators and stripping any trailing separators.
/// redundant intermediary separators and stripping any trailing separators.
/// On Windows, `FilePath` will also normalize forward slashes `/` into
/// backslashes `\`, as preferred by the platform.
///
@@ -29,7 +29,7 @@
/// try fd.closeAfter { try fd.writeAll(message.utf8) }
///
/// File paths conform to the
/// and <doc://com.apple.documentation/documentation/swift/equatable>
/// <doc://com.apple.documentation/documentation/swift/equatable>
/// and <doc://com.apple.documentation/documentation/swift/hashable> protocols
/// by performing the protocols' operations on their raw byte contents.
/// This conformance allows file paths to be used,
+7 -6
View File
@@ -442,7 +442,7 @@ extension FilePath {
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
extension FilePath {
/// If `prefix` is a prefix of `self`, removes it and returns `true`.
/// Otherwise returns `false`.
/// Otherwise returns `false`.
///
/// Example:
///
@@ -503,10 +503,11 @@ extension FilePath {
/// A leading separator is spurious if `self` is non-empty.
///
/// Example:
/// var path: FilePath = ""
/// path.append("/var/www/website") // "/var/www/website"
/// path.append("static/assets") // "/var/www/website/static/assets"
/// path.append("/main.css") // "/var/www/website/static/assets/main.css"
///
/// var path: FilePath = ""
/// path.append("/var/www/website") // "/var/www/website"
/// path.append("static/assets") // "/var/www/website/static/assets"
/// path.append("/main.css") // "/var/www/website/static/assets/main.css"
///
// TODO(Windows docs): example with roots, should we rephrase this "spurious
// roots"?
@@ -576,7 +577,7 @@ extension FilePath {
_append(unchecked: other._storage[...])
}
/// Non-mutating version of `push()`
/// Non-mutating version of `push()`.
///
// TODO(Windows docs): examples and docs with roots
public __consuming func pushing(_ other: __owned FilePath) -> FilePath {
+8
View File
@@ -115,3 +115,11 @@ internal func system_dup2(_ fd: Int32, _ fd2: Int32) -> Int32 {
#endif
return dup2(fd, fd2)
}
#if !os(Windows)
internal func system_pipe(_ fds: UnsafeMutablePointer<Int32>) -> CInt {
#if ENABLE_MOCKING
if mockingEnabled { return _mock(fds) }
#endif
return pipe(fds)
}
#endif
@@ -89,6 +89,27 @@ final class FileOperationsTest: XCTestCase {
func testHelpers() {
// TODO: Test writeAll, writeAll(toAbsoluteOffset), closeAfter
}
#if !os(Windows)
func testAdHocPipe() throws {
// Ad-hoc test testing `Pipe` functionality.
// We cannot test `Pipe` using `MockTestCase` because it calls `pipe` with a pointer to an array local to the `Pipe`, the address of which we do not know prior to invoking `Pipe`.
let pipe = try FileDescriptor.pipe()
try pipe.readEnd.closeAfter {
try pipe.writeEnd.closeAfter {
var abc = "abc"
try abc.withUTF8 {
_ = try pipe.writeEnd.write(UnsafeRawBufferPointer($0))
}
let readLen = 3
let readBytes = try Array<UInt8>(unsafeUninitializedCapacity: readLen) { buf, count in
count = try pipe.readEnd.read(into: UnsafeMutableRawBufferPointer(buf))
}
XCTAssertEqual(readBytes, Array(abc.utf8))
}
}
}
#endif
func testAdHocOpen() {
// Ad-hoc test touching a file system.
+19
View File
@@ -0,0 +1,19 @@
#[[
This source file is part of the Swift System open source Project
Copyright (c) 2021 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
#]]
set(SWIFT_SYSTEM_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/SwiftSystemExports.cmake)
configure_file(SwiftSystemConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/SwiftSystemConfig.cmake)
get_property(SWIFT_SYSTEM_EXPORTS GLOBAL PROPERTY SWIFT_SYSTEM_EXPORTS)
export(TARGETS ${SWIFT_SYSTEM_EXPORTS}
NAMESPACE SwiftSystem::
FILE ${SWIFT_SYSTEM_EXPORTS_FILE}
EXPORT_LINK_INTERFACE_LIBRARIES)
+8 -2
View File
@@ -17,8 +17,12 @@ 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}" STREQUAL "aarch64")
set("${result_var_name}" "aarch64" PARENT_SCOPE)
elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AArch64|aarch64|arm64")
if(CMAKE_SYSTEM_NAME MATCHES Darwin)
set("${result_var_name}" "arm64" PARENT_SCOPE)
else()
set("${result_var_name}" "aarch64" PARENT_SCOPE)
endif()
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
set("${result_var_name}" "powerpc64" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
@@ -31,6 +35,8 @@ function(get_swift_host_arch result_var_name)
set("${result_var_name}" "armv7" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a")
set("${result_var_name}" "armv7" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64")
set("${result_var_name}" "amd64" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
set("${result_var_name}" "x86_64" PARENT_SCOPE)
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
+12
View File
@@ -0,0 +1,12 @@
#[[
This source file is part of the Swift System open source Project
Copyright (c) 2021 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
#]]
if(NOT TARGET SystemPackage)
include(@SWIFT_SYSTEM_EXPORTS_FILE@)
endif()