-
Notifications
You must be signed in to change notification settings - Fork 175
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
Use platform shims for clock_gettime to support wasi-libc #781
Use platform shims for clock_gettime to support wasi-libc #781
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this really require the C shim? Why can we not just add an OS conditional?
extern const struct __clockid _CLOCK_MONOTONIC;
#define CLOCK_MONOTONIC (&_CLOCK_MONOTONIC)
extern const struct __clockid _CLOCK_REALTIME;
#define CLOCK_REALTIME (&_CLOCK_REALTIME) |
@swift-ci please test |
665353d
to
f8b423d
Compare
@swift-ci test |
// Define clock_gettime shims for each clock type so that we can use them in Swift | ||
// even if clock id macros can't be imported through ClangImporter. | ||
|
||
#if !defined(_WIN32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use TARGET_OS_WINDOWS
here to try to be consistent with our platform checks (I know some places might not, I plan to come and fix up a few but it'd be great to standardize on the target conditionals with new additions)
@@ -67,3 +67,20 @@ mach_port_t _platform_mach_task_self() { | |||
} | |||
#endif | |||
|
|||
#if !defined(_WIN32) | |||
int _platform_shims_clock_monotonic_raw_gettime(struct timespec * _Nonnull ts) { | |||
#if __wasi__ // WASI does not support CLOCK_MONOTONIC_RAW. Fall back to CLOCK_MONOTONIC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here as above, could we use TARGET_OS_WASI
?
@swift-ci test |
Just confirming - is this change still necessary for the WASI build? One thought that occurred to me - if the problem is |
This change adds platform shims for clock ids so that we can use them in Swift code because the clock id macro definitions in wasi-libc can't be imported through ClangImporter. Also wasi-libc's `timespec.tv_sec` and `timespec.tv_nsec` are not imported as `Int` but as `Int64` and `Int32` respectively, so we need to cast them to `UInt64` before doing arithmetic operations on them.
284487d
to
4e06bcd
Compare
@jmschonfeld That totally makes sense to me. Now shims are isolated to only WASI. |
@swift-ci test |
1 similar comment
@swift-ci test |
This change adds platform shims for
clock_gettime
so that we can use it in Swift code even when the clock id macros can't be imported through ClangImporter like wasi-libc's definitions.Also wasi-libc's
timespec.tv_sec
andtimespec.tv_nsec
are not imported asInt
in Swift, so we need to cast them toUInt64
before doing arithmetic operations on them.