Skip to content

feat: Add Swift WebAssembly compilation support to swift-distributed-tracing #174

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 4 commits into
base: main
Choose a base branch
from

Conversation

scottmarchant
Copy link

@scottmarchant scottmarchant commented Jun 23, 2025

Summary

This PR adds support for compiling swift-distributed-tracing to wasm using the Swift SDK for WebAssembly.

This PR is part of a larger effort by a company called PassiveLogic to enable broad support for Swift WebAssembly compilation.

Details

There are three changes required to enable wasm compilation for swift-distributed-tracing.

  • Removed unused import Dispatch imports. The Swift SDK for WebAssembly doesn't currently include GCD. Luckily, all usage of GCD was unused.
  • Added some missing wasi-libc and pthread imports
  • Add shim to allow wrapped access to CLOCK_REALTIME struct from WASILibc. This is a critical piece of distributed tracing to acquire timestamps that needed some manual shim code to map to the matching API in WASI.

Testing done

  • Cleaned up swiftformat lint on modified lines of change.
  • Verified unit tests still pass with these changes
  • Verified swift build completes without errors
  • Verified no new compiler warnings are added with these changes
  • Verified swift build --swift-sdk wasm32-unknown-wasi completes without errors
  • Verified swift build --swift-sdk wasm32-unknown-wasip1-threads completes without errors
  • Verified a third-party executable can build this library as part of a larger wasm executable using the command swift package --swift-sdk wasm32-unknown-wasip1-threads js --use-cdn

Impact Risk

Realistically, this change should not cause any impact or risk. Outside of wasm targets, the changes in this PR are additive.

@MaxDesiatov
Copy link
Member

@FranzBusch @ktoso would either of you have a moment to review?

@MaxDesiatov
Copy link
Member

@scottmarchant could you update PR description to refer to official swift.org Swift SDKs for Wasm instead of SwiftWasm? Thanks!

@scottmarchant scottmarchant changed the title feat: Add swift wasm compilation support to swift-distributed-tracing feat: Add Swift WebAssembly compilation support to swift-distributed-tracing Jul 28, 2025
@scottmarchant
Copy link
Author

scottmarchant commented Jul 28, 2025

@scottmarchant could you update PR description to refer to official swift.org Swift SDKs for Wasm instead of SwiftWasm? Thanks!

@MaxDesiatov Done. I updated my other existing PR's as well.

@scottmarchant scottmarchant force-pushed the feat/swift-wasm-support branch from 62ca5b1 to bfdfbad Compare July 28, 2025 19:43
@scottmarchant
Copy link
Author

Note, latest push was just rebasing these changes onto the latest tip of main.

@FranzBusch FranzBusch enabled auto-merge (squash) July 29, 2025 07:00
@FranzBusch FranzBusch added the 🔨 semver/patch No public API change. label Jul 29, 2025
@@ -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])),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We seem to be getting an error on this line on 5.10

error: Target Tracing imports another target (_CWASI) in the package without declaring it a dependency.

Is this a bug in the package manager on 5.10? Can you take a look and if it is a bug we can just disable the strict dependency check on just 5.10

#else
#error("Unsupported runtime")
#endif

#if canImport(_CWASI)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if canImport(_CWASI)
#if os(WASI)

@MaxDesiatov
Copy link
Member

@scottmarchant would you mind addressing formatting job failures per the build log? https://github.com/apple/swift-distributed-tracing/actions/runs/16578688393/job/46920017078?pr=174

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants