Skip to content

feat: Add swift wasm 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 SwiftWasm sdk.

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

Details

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

  • Removed unused import Dispatch imports. SwiftWasm 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.

@@ -23,10 +23,16 @@ import Glibc
import Android
Copy link
Author

Choose a reason for hiding this comment

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

Note, there is a lot of existing swiftformat lint in this repository, including the existing indentation on many of these import blocks. I fixed the lint on the lines of code I'm changing in this PR. But I didn't fix it for everything else, to avoid making the diff far too large.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant