Skip to content

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

Merged
FranzBusch merged 9 commits into
apple:mainfrom
PassiveLogic:feat/swift-wasm-support
Aug 8, 2025
Merged

feat: Add Swift WebAssembly compilation support to swift-distributed-tracing#174
FranzBusch merged 9 commits into
apple:mainfrom
PassiveLogic:feat/swift-wasm-support

Conversation

@scottmarchant

@scottmarchant scottmarchant commented Jun 23, 2025

Copy link
Copy Markdown
Contributor

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.

Comment thread Sources/Tracing/TracingTime.swift
@MaxDesiatov

Copy link
Copy Markdown
Member

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

Comment thread Sources/_CWASI/_CWASI.c
@MaxDesiatov

Copy link
Copy Markdown
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

scottmarchant commented Jul 28, 2025

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
Contributor 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
Comment thread Package.swift
dependencies: [
.product(name: "ServiceContextModule", package: "swift-service-context"),
.target(name: "Instrumentation"),
.target(name: "_CWASI", condition: .when(platforms: [.wasi])),

Copy link
Copy Markdown
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@FranzBusch Indeed it does look like that is a bug. I tracked it down to FB14859516 metnioned in https://forums.swift.org/t/do-swiftpm-conditional-target-dependencies-work/74047.

I removed the dependency check for swift versions before Swift 6. See 386e324

Comment thread Sources/Tracing/TracingTime.swift Outdated
@MaxDesiatov

Copy link
Copy Markdown
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

auto-merge was automatically disabled August 5, 2025 17:33

Head branch was pushed to by a user without write access

@scottmarchant

Copy link
Copy Markdown
Contributor Author

@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

Done.

@MaxDesiatov

Copy link
Copy Markdown
Member

@ktoso would you have a moment to review and kick off CI? Thanks!

@FranzBusch
FranzBusch enabled auto-merge (squash) August 6, 2025 10:39
@FranzBusch

Copy link
Copy Markdown
Member

Can you fix the YAML lint and update against the latest main branch. Thanks again for working on this!

auto-merge was automatically disabled August 6, 2025 16:24

Head branch was pushed to by a user without write access

@scottmarchant

Copy link
Copy Markdown
Contributor Author

Can you fix the YAML lint and update against the latest main branch. Thanks again for working on this!

@FranzBusch Done. And thank you for the active reviews here! Hugely appreciated!

@FranzBusch
FranzBusch enabled auto-merge (squash) August 7, 2025 08:45
@MaxDesiatov

Copy link
Copy Markdown
Member

This needs a merge with main due to repo settings requirement.

@scottmarchant

Copy link
Copy Markdown
Contributor Author

@FranzBusch I believe this branch has the latest main merged into it and is ready for merge now once the workflow runs.

@FranzBusch
FranzBusch merged commit d1ba77e into apple:main Aug 8, 2025
34 checks passed
FranzBusch pushed a commit that referenced this pull request Oct 29, 2025
…uilds (#175)

# Change summary

Added swift wasm as a CI target, to help prevent future breakages to
swift wasm builds in DataLoader

# Details

- Adds wasm build to `pull_request` and `main`, by adding references to
new wasm build workflow from swiftlang.

# Notes

- This PR is [part of a larger
effort](PassiveLogic/swift-web-examples#1) by
PassiveLogic to add wasm support to many popular repositories.

# PR Dependencies

The following PR's must be merged before this PR can be merged:

- #174

# Testing done

Verified in separate fork that new workflow functions correctly:

https://github.com/PassiveLogic/swift-distributed-tracing/actions/runs/18858201101/job/53810934909?pr=2
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