Skip to content

Add explicit ServiceContextModule dependency to fix Xcode linker error#893

Closed
William-Laverty wants to merge 2 commits intoswift-server:mainfrom
William-Laverty:fix/add-service-context-dependency
Closed

Add explicit ServiceContextModule dependency to fix Xcode linker error#893
William-Laverty wants to merge 2 commits intoswift-server:mainfrom
William-Laverty:fix/add-service-context-dependency

Conversation

@William-Laverty
Copy link

Summary

Add swift-service-context as an explicit package dependency and ServiceContextModule as a target dependency of AsyncHTTPClient.

Problem

AsyncHTTPClient directly references ServiceContext.current (from swift-service-context) in HTTPClientRequest+Prepared.swift, and also via 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, the package 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, causing:

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

Fix

A two-line change to Package.swift:

  1. Add swift-service-context as a package dependency
  2. Add ServiceContextModule as a target dependency of AsyncHTTPClient

This is the same class of bug as #721 (missing NIOTLS).

Fixes #890.

AsyncHTTPClient references ServiceContext.current directly (compiled into
the caller from Tracer.withSpan default arguments), but only declared a
dependency on Tracing, not on ServiceContextModule. When Xcode builds SPM
packages as frameworks, transitive dependencies are not automatically
propagated to the linker, causing an undefined symbol error.

Add swift-service-context as an explicit package dependency and
ServiceContextModule as a target dependency of AsyncHTTPClient.

Fixes swift-server#890.
@fabianfett
Copy link
Member

I think this is a dupe of #891.

@fabianfett
Copy link
Member

As stated before this is a dupe of #891.

@fabianfett fabianfett closed this Feb 25, 2026
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.

Missing ServiceContextModule dependency causes linker error in Xcode projects

2 participants