From 80e1e94459673fdd081ab8325950033b143520ab 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 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/Testing/Events/Clock.swift b/Sources/Testing/Events/Clock.swift index 794f4df8b..43c4364fc 100644 --- a/Sources/Testing/Events/Clock.swift +++ b/Sources/Testing/Events/Clock.swift @@ -41,7 +41,13 @@ extension Test { /// The wall-clock time corresponding to this instant. fileprivate(set) var wall: TimeValue = { var wall = timespec() +#if os(Android) + // Android headers recommend `clock_gettime` over `timespec_get` which + // is available with API Level 29+ for `TIME_UTC`. + clock_gettime(CLOCK_REALTIME, &wall) +#else timespec_get(&wall, TIME_UTC) +#endif return TimeValue(wall) }() #endif