Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/apple/swift-system
Low-level system calls and types for Swift
https://github.com/apple/swift-system
file-descriptor file-path posix
Last synced: 28 days ago
JSON representation
Low-level system calls and types for Swift
- Host: GitHub
- URL: https://github.com/apple/swift-system
- Owner: apple
- License: apache-2.0
- Created: 2020-09-25T00:14:13.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-09-19T22:31:34.000Z (about 2 months ago)
- Last Synced: 2024-09-27T23:33:13.257Z (about 1 month ago)
- Topics: file-descriptor, file-path, posix
- Language: Swift
- Homepage:
- Size: 501 KB
- Stars: 1,178
- Watchers: 150
- Forks: 102
- Open Issues: 40
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome - apple/swift-system - Low-level system calls and types for Swift (Swift)
README
# Swift System
Swift System provides idiomatic interfaces to system calls and low-level currency types. Our vision is for System to act as the single home for low-level system interfaces for all supported Swift platforms.
## Multi-platform not Cross-platform
System is a multi-platform library, not a cross-platform one. It provides a separate set of APIs and behaviors on every supported platform, closely reflecting the underlying OS interfaces. A single import will pull in the native platform interfaces specific for the targeted OS.
Our immediate goal is to simplify building cross-platform libraries and applications such as SwiftNIO and SwiftPM. System does not eliminate the need for `#if os()` conditionals to implement cross-platform abstractions, but it does make it safer and more expressive to fill out the platform-specific parts.
## Usage
```swift
import SystemPackagelet message: String = "Hello, world!" + "\n"
let path: FilePath = "/tmp/log"
let fd = try FileDescriptor.open(
path, .writeOnly, options: [.append, .create], permissions: .ownerReadWrite)
try fd.closeAfter {
_ = try fd.writeAll(message.utf8)
}
```[API documentation](https://swiftpackageindex.com/apple/swift-system/main/documentation/SystemPackage)
## Adding `SystemPackage` as a Dependency
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.3.0"),
```Finally, include `"SystemPackage"` as a dependency for your executable target:
```swift
let package = Package(
// name, platforms, products, etc.
dependencies: [
.package(url: "https://github.com/apple/swift-system", from: "1.3.0"),
// other dependencies
],
targets: [
.target(name: "MyTarget", dependencies: [
.product(name: "SystemPackage", package: "swift-system"),
]),
// other targets
]
)
```## 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).
## LICENSE
See [LICENSE](LICENSE.txt) for license information.