Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ public struct Greeter {
public func greeting() -> String {
return "Hello from Swift, \(subject)!"
}

// Swift Concurrency: async code pulls in the concurrency runtime, whose
// global executor lives on libdispatch. This exists so the example is a
// link-time regression test for the `-ldispatch -lBlocksRuntime` linkopts
// in the generated Android toolchain — without them, linking any `async`
// Swift fails with `undefined symbol: dispatch_main` (and friends).
public func greetingAsync() async -> String {
return greeting()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import Greeter
// symbol name that `NativeBridge.greetingFromSwift()` binds to.
@_cdecl("Java_com_example_swiftjni_NativeBridge_greetingFromSwift")
public func greetingFromSwift(_ env: UnsafeMutablePointer<JNIEnv?>, _ clazz: jclass) -> jstring? {
// Exercise Swift Concurrency so the example links (and runs) the async
// runtime — see Greeter.greetingAsync().
Task {
_ = await Greeter(subject: "Android").greetingAsync()
}
let message = Greeter(subject: "Android").greeting()
return message.withCString { cString in
env.pointee!.pointee.NewStringUTF(env, cString)
Expand Down
8 changes: 8 additions & 0 deletions swift/internal/extensions/swift_sdks.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@ def _swift_android_sdk_impl(repository_ctx):
"-L{}/android".format(resource_dir),
"-llog",
"-lswiftCore",
# Swift Concurrency's global executor lives on libdispatch,
# but the dependency comes from C++ objects inside
# libswift_Concurrency.a, so it is never autolinked. Link it
# (and its BlocksRuntime) explicitly from the same SDK
# directory; lld only extracts referenced members, so this is
# free for binaries that don't use concurrency.
"-ldispatch",
"-lBlocksRuntime",
"-Wl,-export-dynamic",
"-Wl,--exclude-libs,ALL",
# TODO: Remove once https://github.com/bazelbuild/rules_android_ndk/commit/efc0c191796477c540e87e0f6bb5d88d6a58cc1f is in a release
Expand Down
Loading