From 2098a8a1ef0f79757449e85d1ff7fc69ab3a12d4 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 21 Aug 2024 07:37:53 -0700 Subject: [PATCH] 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. --- Sources/Testing/Events/Clock.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Sources/Testing/Events/Clock.swift b/Sources/Testing/Events/Clock.swift index 794f4df8b..b28966cd7 100644 --- a/Sources/Testing/Events/Clock.swift +++ b/Sources/Testing/Events/Clock.swift @@ -40,9 +40,15 @@ extension Test { #if !SWT_NO_UTC_CLOCK /// The wall-clock time corresponding to this instant. fileprivate(set) var wall: TimeValue = { - var wall = timespec() - timespec_get(&wall, TIME_UTC) - return TimeValue(wall) + var time = timespec() + // Android headers recommend `clock_gettime` over `timespec_get` which + // is available with API Level 29+ for `TIME_UTC`. +#if os(Android) + clock_gettime(CLOCK_REALTIME, &time) +#else + timespec_get(&time, TIME_UTC) +#endif + return TimeValue(time) }() #endif