Skip to content

Temoprary PR to test CI #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: feat/swift-wasm-support
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ jobs:
uses: apple/swift-nio/.github/workflows/macos_tests.yml@main
with:
build_scheme: swift-distributed-tracing-Package

wasm-sdk:
name: WebAssembly SDK
# TODO: Switch to this line after https://github.com/apple/swift-nio/pull/3159/ is merged
# uses: apple/swift-nio/.github/workflows/wasm_sdk.yml@main
uses: kateinoigakukun/swift-nio/.github/workflows/wasm_sdk.yml@katei/add-wasm-ci
6 changes: 6 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ jobs:
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"

wasm-sdk:
name: WebAssembly SDK
# TODO: Switch to this line after https://github.com/apple/swift-nio/pull/3159/ is merged
# uses: apple/swift-nio/.github/workflows/wasm_sdk.yml@main
uses: kateinoigakukun/swift-nio/.github/workflows/wasm_sdk.yml@katei/add-wasm-ci

benchmarks:
name: Benchmarks
Expand Down
10 changes: 10 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ let package = Package(
dependencies: [
.product(name: "ServiceContextModule", package: "swift-service-context"),
.target(name: "Instrumentation"),
.target(name: "_CWASI", condition: .when(platforms: [.wasi])),
]
),
.testTarget(
Expand All @@ -43,6 +44,15 @@ let package = Package(
.target(name: "Tracing")
]
),

// ==== --------------------------------------------------------------------------------------------------------
// MARK: Wasm Support

// Provides C shims for compiling to wasm
.target(
name: "_CWASI",
dependencies: []
),
]
)

Expand Down
5 changes: 5 additions & 0 deletions Sources/Instrumentation/Locks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ import Glibc
import Android
#elseif canImport(Musl)
import Musl
#elseif canImport(WASILibc)
import WASILibc
#if canImport(wasi_pthread)
import wasi_pthread
#endif
#else
#error("Unsupported runtime")
#endif
Expand Down
1 change: 0 additions & 1 deletion Sources/Tracing/NoOpTracer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//

import Dispatch
@_exported import Instrumentation
@_exported import ServiceContextModule

Expand Down
1 change: 0 additions & 1 deletion Sources/Tracing/Tracer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//

import Dispatch
@_exported import Instrumentation
@_exported import ServiceContextModule

Expand Down
1 change: 0 additions & 1 deletion Sources/Tracing/TracerProtocol+Legacy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//

import Dispatch
@_exported import Instrumentation
@_exported import ServiceContextModule

Expand Down
12 changes: 11 additions & 1 deletion Sources/Tracing/TracingTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ import Glibc
import Android
#elseif canImport(Musl)
import Musl
#elseif canImport(WASILibc)
import WASILibc
#else
#error("Unsupported runtime")
#endif

#if canImport(_CWASI)
import _CWASI
#endif

public protocol TracerInstant: Comparable, Hashable, Sendable {
/// Representation of this instant as the number of nanoseconds since UNIX Epoch (January 1st 1970)
var nanosecondsSinceEpoch: UInt64 { get }
Expand Down Expand Up @@ -84,7 +90,11 @@ public struct DefaultTracerClock {

public var now: Self.Instant {
var ts = timespec()
clock_gettime(CLOCK_REALTIME, &ts)
#if os(WASI)
CWASI_clock_gettime_realtime(&ts)
#else
clock_gettime(CLOCK_REALTIME, &ts)
#endif
/// We use unsafe arithmetic here because `UInt64.max` nanoseconds is more than 580 years,
/// and the odds that this code will still be running 530 years from now is very, very low,
/// so as a practical matter this will never overflow.
Expand Down
13 changes: 13 additions & 0 deletions Sources/_CWASI/_CWASI.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Distributed Tracing open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift Distributed Tracing project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift Distributed Tracing project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
27 changes: 27 additions & 0 deletions Sources/_CWASI/include/_CWASI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Distributed Tracing open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift Distributed Tracing project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift Distributed Tracing project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

#pragma once

#if __wasi__

#include <fcntl.h>
#include <time.h>

static inline void CWASI_clock_gettime_realtime(struct timespec *tv) {
// ClangImporter doesn't support `CLOCK_REALTIME` declaration in WASILibc, thus we have to define a bridge manually
clock_gettime(CLOCK_REALTIME, tv);
}

#endif // __wasi__
Loading