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(
3535            dependencies:  [ 
3636                . product( name:  " ServiceContextModule " ,  package :  " swift-service-context " ) , 
3737                . target( name:  " Instrumentation " ) , 
38+                 . target( name:  " _CWASI " ,  condition:  . when( platforms:  [ . wasi] ) ) , 
3839            ] 
3940        ) , 
4041        . testTarget( 
@@ -43,6 +44,16 @@ let package = Package(
4344                . target( name:  " Tracing " ) 
4445            ] 
4546        ) , 
47+ 
48+         // ==== --------------------------------------------------------------------------------------------------------
49+         // MARK: Wasm Support
50+ 
51+         // Provides C shims for compiling to wasm
52+         . target( 
53+             name:  " _CWASI " , 
54+             dependencies:  [ ] 
55+         ) , 
56+ 
4657    ] 
4758) 
4859
Original file line number Diff line number Diff line change @@ -90,7 +90,11 @@ public struct DefaultTracerClock {
9090
9191    public  var  now :  Self . Instant  { 
9292        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 
9498        /// We use unsafe arithmetic here because `UInt64.max` nanoseconds is more than 580 years,
9599        /// and the odds that this code will still be running 530 years from now is very, very low,
96100        /// 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