Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Roadmap #16

Open
milseman opened this issue Nov 17, 2020 · 13 comments
Open

API Roadmap #16

milseman opened this issue Nov 17, 2020 · 13 comments
Labels
enhancement New feature or request

Comments

@milseman
Copy link
Contributor

milseman commented Nov 17, 2020

This is meant to be a continuously-updated list of API candidates for System.

Criteria for Inclusion

System's primary aim is to be the place developers go to access native platform interfaces, presented in as Swifty a way as feasible. This positions System as a successor to Darwin/GlibC/SwiftWin32 and a “bedrock” upon which to enable better systems-level programming in Swift.

System is not aiming to be a cross-platform abstraction layer; there will be platform differences reflected in System's API. Of course, if a concept can be expressed the same way across platforms without harm or significant compromise to the developer's native experience on that platform, that's great. But, System's API should feel natural and native for the target platform.

System aims to provide API in 3 areas:

  1. As-Swifty-as-we-reasonably-can direct access to system calls and types

If a system interface exists, that’s strong justification for providing access to it in System as faithfully as we can.

  1. Common types for library API at the systems level

System hosts common types for systems level programming, enabling libraries built on top of System to use the same, well-crafted types in their API.

For example, many API take locations in the file system, for which FilePath provides a common expression.

  1. High-value utility functionality and abstractions, where appropriate

System provides common utilities that users of System would otherwise find themselves having to reinvent. These usually have some combination of being pervasive, having obvious desired behavior, and being difficult/onerous to implement correctly.

For example, ensuring that a file descriptor is closed under all (non-pathological) conditions can be complex in the presence of error-handling, so System provides FileDescriptor.closeAfter.

This area has a higher bar for contribution, requiring more justification and thought. What is "obvious desired behavior" and "correct" can differ amongst users of System.

Roadmap

Released

  • 0.0.1
    • syscalls: read, write, lseek, pread, pwrite, open, close
    • types: FilePath, FileDescriptor, Errno, FilePermissions
    • helpers: closeAfter, writeAll
  • 0.0.2

Merged

In Progress

Sketches

Sketches are merge-worthy, quick-but-complete presentations of systems interfaces. They help to surface unknown-unknowns and can be easily adapted into a proposal. They are not necessarily named or expressed in their final form.

Starter tasks

  • Add support for pipe

Near Term

Anything here could be added to System in the near term. Most of the functionality can be added by following existing API design patterns, though some will need new patterns.

  • sleep capabilities (e.g. usleep)
  • FilePath semantic (i.e. file-system interacting) operations
    • stat, chown, directory iteration, etc.
    • temporary files
  • pthread low-level interfaces
  • Further networking and sockets functionality
    • getaddrinfo, gethostent, etc.
  • Environment variables
    • FilePath: ~ expansion, currentWorkingDirectory
  • OSString-like abstraction
    • Null-terminated bytes on Unix, wchar or bytes on Windows (pending investigation)
  • I/O events
    • kqueue/kevent for Darwin, epoll for Linux, APC (or something similar) for Windows
  • exit handling
    • exit, atexit, etc
  • tty
    • ioctl, etc
  • Fleshing out FileDescriptor more
    • chmod, umask, etc.

Long Term (vague "blue-sky" hopes)

  • moveonly File type
  • high level Process type
  • io_uring on Linux
@allenhumphreys
Copy link

Not sure if it's on the road map, but additional FileDescriptor operations such as dup and dup2 also support for the FILE APIs? I'm not 100% sure if this aligns with this packages goals, just commenting because I was recently doing some things with these.

@milseman
Copy link
Contributor Author

@allenhumphreys you're right, I'll add those. Sorry that I didn't see your reply earlier, I sometimes miss Github notifications (still trying to figure out why).

@milseman milseman added the enhancement New feature or request label Dec 29, 2020
@milseman milseman pinned this issue Dec 29, 2020
@allenhumphreys
Copy link

Thanks @miles. For reference, here's where I used the package. It's a great example of where the API's coverage is quite low.

Really glad to see this package coming along though!

@stephentyrone stephentyrone unpinned this issue Feb 4, 2021
@milseman milseman pinned this issue Feb 15, 2021
@milseman milseman changed the title Increased API Coverage API Roadmap Feb 15, 2021
@milseman
Copy link
Contributor Author

Updated to reflect merged API that is yet-to-be-released, and added in references to Standard file descriptors, and Strongly-typed process and signal wrappers.

@milseman
Copy link
Contributor Author

Updated for dup/dup2

@GeorgeLyon
Copy link
Contributor

Just curious, does pipe fit somewhere on this roadmap?

@milseman
Copy link
Contributor Author

I had mentally lumped that under process types and calls, but it's not actually blocked on any design work there. We can add this anytime and might make a good starter task.

extension FileDescriptor {
  static func openPipe() throws -> (read: FileDescriptor, write: FileDescriptor)
}

@compnerd
Copy link
Collaborator

Pipes on Windows are somewhat interesting in that they behave differently. I think that it may be a good idea to ensure that we have a proper design to accommodate that properly.

@milseman
Copy link
Contributor Author

@compnerd, would CreatePipe be an appropriate equivalent? It seems sensible to have an additional overload on Windows that takes a buffer size and perhaps security policy (or at least a Bool for inheritability). Buffering has a default value and we can pick a default regarding inheritance for the parameter-less (or defaulted) API.

@compnerd
Copy link
Collaborator

compnerd commented Jul 11, 2021

CreatePipe can be used to create the anonymous pipe and that is better because you can control inheritability unlike with _pipe. However, some things like like non-blocking IO on pipes isn't supported for anonymous pipes and changing the pipe buffer size is undocumented.

dduan added a commit to dduan/swift-system that referenced this issue Apr 20, 2022
Add `exit` as suggested in the roadmap.

There are a few outstanding tasks with this API

- [ ] Discuss API naming on the Swift forum.
- [ ] Availablility annotation (I would like some suggestion from
  a reviewer as opposed to guessing it myself.)
- [ ] Improve the documantations if deemed necessary.

[roadmap]: apple#16
dduan added a commit to dduan/swift-system that referenced this issue Apr 20, 2022
Add `exit` as suggested in the roadmap.

There are a few outstanding tasks with this API

- [ ] Discuss API naming on the Swift forum.
- [ ] Availablility annotation (I would like some suggestion from
  a reviewer as opposed to guessing it myself.)
- [ ] Improve the documantations if deemed necessary.

[roadmap]: apple#16
@milseman
Copy link
Contributor Author

milseman commented May 6, 2022

ftruncate as FileDescriptor.resize: #82

@ffried
Copy link
Contributor

ffried commented Jul 10, 2023

@milseman Would sendfile (or maybe rather copy_file_range) be a candidate that could make it to this package? If so, I'd be happy to create a PR.

@milseman
Copy link
Contributor Author

@milseman Would sendfile (or maybe rather copy_file_range) be a candidate that could make it to this package? If so, I'd be happy to create a PR.

Yes, but I think that would be contingent on sockets, which got punted out (but hopefully we can readdress it soon)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants