Skip to content

Conversation

jrflat
Copy link
Contributor

@jrflat jrflat commented Aug 12, 2025

This PR adds a Swift Stat implementation for the C stat types and system calls.

See the pitch at https://forums.swift.org/t/pitch-stat-types-for-swift-system/81616
See the full proposal in #257

@jrflat
Copy link
Contributor Author

jrflat commented Aug 12, 2025

Note that the implementation uses typed throws which require Swift 6.0+, so earlier Swift versions are failing.

@@ -87,6 +87,7 @@ let swiftSettings = swiftSettingsAvailability + swiftSettingsCI + [

let cSettings: [CSetting] = [
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
.define("_GNU_SOURCE", .when(platforms: [.linux])),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vaguely remember that this may cause an issue with the glibc module if another package imports it without this define? I.e. either everyone has to import it this way or no one can (in which case, we really want the C importer to set this instead of setting it in the package). @DougGregor?

@jrflat jrflat force-pushed the stat-implementation branch from 728d616 to 266636c Compare August 26, 2025 23:31
@jrflat jrflat force-pushed the stat-implementation branch from 266636c to 2f0f045 Compare August 26, 2025 23:54
@rauhul
Copy link
Contributor

rauhul commented Aug 27, 2025

I would really like native TimeSpec and TimeVal wrappers to be provided by this API and conversions to/from duration be based on them.

These type represent the granularity the system thinks in and papering over that with Duration/UTCClock.instant is silly. The system cannot represent all of these values. Swift-system is supported to provide type-safe access to the system api not high level abstractions, thats best left to Foundation.

@jrflat
Copy link
Contributor Author

jrflat commented Aug 28, 2025

I would really like native TimeSpec and TimeVal wrappers to be provided by this API and conversions to/from duration be based on them.

The stdlib already provides initializers to convert timespec and timeval to/from Duration, so I'm not sure if it's worth it to have wrappers in these cases. I think exposing the raw timespec as we're doing here is a decent compromise to allow access to the system's granularity while later providing a more ergonomic UTCClock.Instant property.

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

Successfully merging this pull request may close these issues.

3 participants