-
Notifications
You must be signed in to change notification settings - Fork 143
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.currentAnd 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.