File tree Expand file tree Collapse file tree 4 files changed +47
-1
lines changed
_FoundationCShims/include Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ add_library(FoundationEssentials
3030 SortComparator.swift
3131 UUID_Wrappers.swift
3232 UUID.swift
33+ WASILibc+Extensions.swift
3334 WinSDK+Extensions.swift)
3435
3536add_subdirectory (AttributedString)
Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ final class _ProcessInfo: Sendable {
131131#else
132132 var ts : timespec = timespec ( )
133133 clock_gettime ( CLOCK_MONOTONIC_RAW, & ts)
134- let time : UInt64 = UInt64 ( ts. tv_sec * 1000000000 + ts. tv_nsec)
134+ let time : UInt64 = UInt64 ( ts. tv_sec) * 1000000000 + UInt64 ( ts. tv_nsec)
135135#endif
136136 let timeString = String ( time, radix: 16 , uppercase: true )
137137 let padding = String ( repeating: " 0 " , count: 16 - timeString. count)
Original file line number Diff line number Diff line change 1+ //===----------------------------------------------------------------------===//
2+ //
3+ // This source file is part of the Swift.org open source project
4+ //
5+ // Copyright (c) 2024 Apple Inc. and the Swift project authors
6+ // Licensed under Apache License v2.0 with Runtime Library Exception
7+ //
8+ // See https://swift.org/LICENSE.txt for license information
9+ //
10+ //===----------------------------------------------------------------------===//
11+
12+ #if os(WASI)
13+
14+ import WASILibc
15+ internal import _FoundationCShims
16+
17+ // MARK: - Clock
18+
19+ internal var CLOCK_REALTIME : clockid_t {
20+ return _platform_shims_clock_realtime ( )
21+ }
22+
23+ internal var CLOCK_MONOTONIC : clockid_t {
24+ return _platform_shims_clock_monotonic ( )
25+ }
26+
27+ internal var CLOCK_MONOTONIC_RAW : clockid_t {
28+ // WASI does not have a raw monotonic clock, so we use the monotonic clock instead.
29+ return CLOCK_MONOTONIC
30+ }
31+
32+ #endif // os(WASI)
Original file line number Diff line number Diff line change @@ -68,4 +68,17 @@ typedef enum {
6868INTERNAL const char * _Nonnull _platform_shims_kOSThermalNotificationPressureLevelName (void );
6969#endif
7070
71+ #if TARGET_OS_WASI
72+ // Define clock id getter shims so that we can use them in Swift
73+ // even if clock id macros can't be imported through ClangImporter.
74+
75+ #include <time.h>
76+ static inline _Nonnull clockid_t _platform_shims_clock_monotonic (void ) {
77+ return CLOCK_MONOTONIC ;
78+ }
79+ static inline _Nonnull clockid_t _platform_shims_clock_realtime (void ) {
80+ return CLOCK_REALTIME ;
81+ }
82+ #endif
83+
7184#endif /* CSHIMS_PLATFORM_SHIMS */
You can’t perform that action at this time.
0 commit comments