Link libdispatch for Swift Concurrency on Android - #1830
Conversation
Swift Concurrency's global executor on Android lives on libdispatch, but
the dependency comes from C++ objects inside libswift_Concurrency.a, so
autolink extraction never sees it: any async Swift linked with the Android
Swift SDK fails with
ld.lld: error: undefined symbol: dispatch_main
ld.lld: error: undefined symbol: _dispatch_main_q
...
unless the consumer adds -ldispatch -lBlocksRuntime themselves. Add both
to the generated Android toolchain's linkopts: the archives ship in the
SDK's swift_static-<arch>/android directory that is already on -L, and lld
only extracts referenced members, so binaries that don't use concurrency
are unaffected.
|
can you add a unit test for android that shows Swift that uses these deps links? also shouldn't this be coming from the autolinking behavior instead? how does this affect binary size otherwise? |
greetingAsync + a Task in the JNI entry point make app_build_test a link-time regression test for the concurrency linkopts: without -ldispatch -lBlocksRuntime it fails with undefined dispatch symbols.
|
All three, in order: Test: added — the android example's Why autolinking doesn't cover it: this toolchain does use autolink extraction ( Binary size when unused: zero. I built the (pre-async) example APK with and without the flags — verified via Given the zero cost I don't think this needs to be feature-gated — and anyone who does want different behavior can register their own toolchain, since root-module registrations take precedence. |
|
For completeness, the cost when concurrency is used (same example, async version): the |
Follow-up to #1818. Swift Concurrency's global executor on Android lives on libdispatch, but the dependency comes from C++ objects inside
libswift_Concurrency.a, so autolink extraction never sees it. AnyasyncSwift linked with the Android Swift SDK currently fails with:unless the consumer adds
-ldispatch -lBlocksRuntimeto every binary themselves.This adds both to the generated Android toolchain's linkopts, next to the existing
-lswiftCore:swift_static-<arch>/androiddirectory, which is already on-L;lldonly extracts referenced archive members, so binaries that don't use concurrency are unaffected;static-stdlib-args.lnk, so this isn't covered by the flags that file mirrors.)Verified against a real async consumer (an
asyncSwift module behind JNI): without this change it fails with the errors above; with--override_module=rules_swiftpointed at this branch it links clean with no consumer-side flags.//examples/cross_compilation/android_app/...still builds.