File tree Expand file tree Collapse file tree 4 files changed +56
-1
lines changed Expand file tree Collapse file tree 4 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ let package = Package(
35
35
dependencies: [
36
36
. product( name: " ServiceContextModule " , package : " swift-service-context " ) ,
37
37
. target( name: " Instrumentation " ) ,
38
+ . target( name: " _CWASI " , condition: . when( platforms: [ . wasi] ) ) ,
38
39
]
39
40
) ,
40
41
. testTarget(
@@ -43,6 +44,16 @@ let package = Package(
43
44
. target( name: " Tracing " )
44
45
]
45
46
) ,
47
+
48
+ // ==== --------------------------------------------------------------------------------------------------------
49
+ // MARK: Wasm Support
50
+
51
+ // Provides C shims for compiling to wasm
52
+ . target(
53
+ name: " _CWASI " ,
54
+ dependencies: [ ]
55
+ ) ,
56
+
46
57
]
47
58
)
48
59
Original file line number Diff line number Diff line change @@ -90,7 +90,11 @@ public struct DefaultTracerClock {
90
90
91
91
public var now : Self . Instant {
92
92
var ts = timespec ( )
93
- clock_gettime ( CLOCK_REALTIME, & ts)
93
+ #if os(WASI)
94
+ CWASI_clock_gettime_realtime ( & ts)
95
+ #else
96
+ clock_gettime ( CLOCK_REALTIME, & ts)
97
+ #endif
94
98
/// We use unsafe arithmetic here because `UInt64.max` nanoseconds is more than 580 years,
95
99
/// and the odds that this code will still be running 530 years from now is very, very low,
96
100
/// so as a practical matter this will never overflow.
Original file line number Diff line number Diff line change
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // This source file is part of the Swift Distributed Tracing open source project
4
+ //
5
+ // Copyright (c) 2025 Apple Inc. and the Swift Distributed Tracing project authors
6
+ // Licensed under Apache License v2.0
7
+ //
8
+ // See LICENSE.txt for license information
9
+ // See CONTRIBUTORS.txt for the list of Swift Distributed Tracing project authors
10
+ //
11
+ // SPDX-License-Identifier: Apache-2.0
12
+ //
13
+ //===----------------------------------------------------------------------===//
Original file line number Diff line number Diff line change
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // This source file is part of the Swift Distributed Tracing open source project
4
+ //
5
+ // Copyright (c) 2025 Apple Inc. and the Swift Distributed Tracing project authors
6
+ // Licensed under Apache License v2.0
7
+ //
8
+ // See LICENSE.txt for license information
9
+ // See CONTRIBUTORS.txt for the list of Swift Distributed Tracing project authors
10
+ //
11
+ // SPDX-License-Identifier: Apache-2.0
12
+ //
13
+ //===----------------------------------------------------------------------===//
14
+
15
+ #pragma once
16
+
17
+ #if __wasi__
18
+
19
+ #include <fcntl.h>
20
+ #include <time.h>
21
+
22
+ static inline void CWASI_clock_gettime_realtime (struct timespec * tv ) {
23
+ // ClangImporter doesn't support `CLOCK_REALTIME` declaration in WASILibc, thus we have to define a bridge manually
24
+ clock_gettime (CLOCK_REALTIME , tv );
25
+ }
26
+
27
+ #endif // __wasi__
You can’t perform that action at this time.
0 commit comments