swift-server / swift-server/async-http-client
Missing ServiceContextModule dependency causes linker error in Xcode projects
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 1.1k
- Forks
- 156
- PR merge metrics
- No merged PRs in 30d
Description
Description
AsyncHTTPClient directly references ServiceContext.current (from swift-service-context) in HTTPClientRequest+Prepared.swift, but only declares a dependency on Tracing (from swift-distributed-tracing), not on ServiceContextModule directly.
When Xcode builds SPM packages as frameworks, transitive dependencies are not automatically propagated to the linker. This causes:
Undefined symbols for architecture arm64:
"static ServiceContextModule.ServiceContext.current.getter", referenced from:
implicit closure #1 () -> ServiceContextModule.ServiceContext in default argument 1 of
(extension in Tracing):Tracing.Tracer.withSpan<A>(...) in AsyncHTTPClient.o
Root Cause
In Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest+Prepared.swift:
let context = ServiceContext.current
And in the default argument of Tracer.withSpan() calls — Swift compiles default arguments into the caller, so ServiceContext.current gets compiled into AsyncHTTPClient.o, creating a direct symbol reference to ServiceContextModule.
However, Package.swift only lists:
.product(name: "Tracing", package: "swift-distributed-tracing"),
It does not include:
.product(name: "ServiceContextModule", package: "swift-service-context"),
Fix
Add swift-service-context as an explicit package dependency and ServiceContextModule as a product dependency of the AsyncHTTPClient target. This is the same class of bug as #721 (missing NIOTLS).
dependencies: [
.package(url: "https://github.com/apple/swift-distributed-tracing.git", from: "1.3.0"),
+ .package(url: "https://github.com/apple/swift-service-context.git", from: "1.1.0"),
],
.target(
name: "AsyncHTTPClient",
dependencies: [
.product(name: "Tracing", package: "swift-distributed-tracing"),
+ .product(name: "ServiceContextModule", package: "swift-service-context"),
],
),
Environment
- Xcode 26.2 (macOS 26)
- async-http-client 1.31.0
- swift-distributed-tracing 1.4.0
- swift-service-context 1.3.0
- Consumed transitively via swift-xet → swift-huggingface in an Xcode project (not a Package.swift-based project)
Workaround
Manually patch the local DerivedData checkout of async-http-client/Package.swift to add the missing dependency. This must be re-applied after every xcodebuild clean or DerivedData deletion.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Package.swift and compare the AsyncHTTPClient target dependencies with the direct ServiceContext.current reference in Sources/AsyncHTTPClient/AsyncAwait/HTTPClientRequest+Prepared.swift. Add the explicitly required package and product dependencies described in the issue, then verify that an Xcode framework build no longer reports the ServiceContextModule undefined symbol.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100