Skip to content

Commit 5668ab9

Browse files
Copilotsteveisok
andauthored
Fix Android debug build: Add HOST_ANDROID to timespec_get fallback (#121425)
`timespec_get` is not available on the Android API levels we target, causing compilation failures in debug builds of `src/coreclr/utilcode/debug.cpp`. ### Changes - Added `HOST_ANDROID` to the existing preprocessor conditionals that select `gettimeofday` over `timespec_get` - Updated include guards for `<sys/time.h>` to include Android Android now follows the same codepath as iOS, tvOS, and macCatalyst: ```cpp #if defined(HOST_IOS) || defined(HOST_TVOS) || defined(HOST_MACCATALYST) || defined(HOST_ANDROID) // timespec_get is only available on iOS 13.0+ and not supported on Android API levels we target struct timeval tv; gettimeofday(&tv, nullptr); ts.tv_sec = tv.tv_sec; ts.tv_nsec = tv.tv_usec * 1000; #else int ret = timespec_get(&ts, TIME_UTC); #endif ``` <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > When built for Android in the debug configuration, src/coreclr/utilcode/debug.cpp fails to compile because timespec_get is not supported for the API level we target. HOST_ANDROID needs to be added to #define checks so that it will fall through the gettimeofday path. </details> <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/dotnet/runtime/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: steveisok <[email protected]>
1 parent 302a563 commit 5668ab9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/coreclr/utilcode/debug.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "ex.h"
1313
#include "corexcep.h"
1414
#include <time.h>
15-
#if defined(HOST_IOS) || defined(HOST_TVOS) || defined(HOST_MACCATALYST)
15+
#if defined(HOST_IOS) || defined(HOST_TVOS) || defined(HOST_MACCATALYST) || defined(HOST_ANDROID)
1616
#include <sys/time.h>
1717
#endif
1818

@@ -163,8 +163,8 @@ VOID LogAssert(
163163
STRESS_LOG2(LF_ASSERT, LL_ALWAYS, "ASSERT:%s:%d\n", szFile, iLine);
164164

165165
struct timespec ts;
166-
#if defined(HOST_IOS) || defined(HOST_TVOS) || defined(HOST_MACCATALYST)
167-
// timespec_get is only available on iOS 13.0+, use gettimeofday instead
166+
#if defined(HOST_IOS) || defined(HOST_TVOS) || defined(HOST_MACCATALYST) || defined(HOST_ANDROID)
167+
// timespec_get is only available on iOS 13.0+ and not supported on Android API levels we target, use gettimeofday instead
168168
struct timeval tv;
169169
gettimeofday(&tv, nullptr);
170170
ts.tv_sec = tv.tv_sec;

0 commit comments

Comments
 (0)