Files
swift-mirror/test/stdlib/static-stdlib-args-android.test-sh
Nik Tishakov b5c229b4b4 [Android] Link Dispatch with -static-stdlib (#94056)
**Problem**

On Android, `-static-stdlib` doesn't link Dispatch, which the
concurrency runtime needs. With the Swift SDK for Android 6.4.1:

- an executable that uses concurrency fails to link: `undefined symbol:
_dispatch_main_q`;
- a shared library links, but fails to load: `dlopen failed: cannot
locate symbol "_dispatch_main_q"`.

Apps that import full Foundation still work, because Foundation brings
in Dispatch. Apps that use only the stdlib or FoundationEssentials
don't.

**Cause**

`static-stdlib-args.lnk` for Android has no `-ldispatch
-lBlocksRuntime`. In `stdlib/public/runtime/CMakeLists.txt` they're
added in an `elseif` after the Android branch (from 1977a6859, which
fixed static linking on Linux), so Android never gets them.
`Runtimes/Overlay/Android` does the same.

**Change**

Add `-ldispatch -lBlocksRuntime` for Android in both builds, as on
Linux, and add `test/stdlib/static-stdlib-args-android.test-sh`, which
checks the generated file. The SDK already ships `libdispatch.a` and
`libBlocksRuntime.a` in `swift_static` for all three architectures.

**Testing**

The 6.4.1 Android SDK with its `static-stdlib-args.lnk` replaced by what
this patch generates, aarch64, Android emulator (API 36):

- executable with a `Task`: links and runs (fails to link before);
- shared library with a `Task`, stdlib only and with
FoundationEssentials: loads and runs (fails to load before).

I didn't run the lit test itself, which needs an Android build with the
static stdlib; it fails on the old file contents and passes on the new
ones.

This is the remaining problem for swiftlang/swift-package-manager#8198
(on the Android board): SwiftPM with Swift Build now applies
`--static-swift-stdlib` to dynamic libraries. With it, the APK of a
small FoundationEssentials app goes from 17.7 MB to 13.0 MB.
2026-11-09 17:08:38 +05:30

15 lines
532 B
Plaintext

// Ensure that -static-stdlib links Dispatch on Android.
//
// The concurrency runtime uses Dispatch, so the static stdlib link arguments
// must include it and the blocks runtime. Without them, an executable that
// uses concurrency fails to link, and a shared library fails to load.
// REQUIRES: OS=linux-android || OS=linux-androideabi
// REQUIRES: static_stdlib
// REQUIRES: concurrency
// RUN: %FileCheck %s < %target-static-stdlib-path/static-stdlib-args.lnk
// CHECK: -lswiftCore
// CHECK-NEXT: -ldispatch -lBlocksRuntime