Skip to content

Commit 049ff5d

Browse files
committed
Testing: use clock_gettime on Android
Android recommends `clock_gettime` over `timespec_get` which is available at Level 29 and newer. This is needed to build swift-testing for Android.
1 parent 61d4df9 commit 049ff5d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Sources/Testing/Events/Clock.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ extension Test {
4040
#if !SWT_NO_UTC_CLOCK
4141
/// The wall-clock time corresponding to this instant.
4242
fileprivate(set) var wall: TimeValue = {
43-
var wall = timespec()
44-
timespec_get(&wall, TIME_UTC)
45-
return TimeValue(wall)
43+
var time = timespec()
44+
// Android headers recommend `clock_gettime` over `timespec_get` which
45+
// is available with API Level 29+ for `TIME_UTC`.
46+
#if os(Android)
47+
clock_gettime(CLOCK_REALTIME, &time)
48+
#else
49+
timespec_get(&time, TIME_UTC)
50+
#endif
51+
return TimeValue(time)
4652
}()
4753
#endif
4854

0 commit comments

Comments
 (0)