Skip to content

Conversation

@madsodgaard
Copy link
Contributor

@madsodgaard madsodgaard commented Oct 28, 2025

Adds support for extracting async methods from Swift.

We use an upcall from Swift to Java to complete a CompletableFuture

Additional changes:

  • Bump to Swift 6.2
  • Rename SwiftKitSwift to SwiftRuntimeFunctions
  • Add SwiftJavaRuntimeSupport for runtime files needed by JExtract

Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking very good, thanks!

@madsodgaard madsodgaard requested a review from ktoso October 30, 2025 15:55
if swiftFunctionResultType.isVoid {
printer.print("environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, [jvalue(l: nil)])")
} else {
printer.printBraceBlock("withVaList([SwiftJavaRuntimeSupport._JNIBoxedConversions.box(\(inner), in: environment)])") { printer in
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Android, I'm getting this compilation error:

withVaList([SwiftJavaRuntimeSupport._JNIBoxedConversions.box(resultBits$.getJNIValue(in: environment), in: environment)]) {
    |                                                                  `- error: cannot convert value of type 'jobject' (aka 'UnsafeMutableRawPointer') to expected element type 'any CVarArg'

This appears to originate from this code, though it compiles fine on Darwin. I'm not certain if this is an issue with my local Android sdk or not so just wanted to flag it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0xZaph thanks for reporting this! seems like the issue is that the Android JNI imports jobjects as UnsafeRawMutablePointer, but that does not conform to CVarArg. And the "normal" JNI, imports it as OpaquePointer, which does.

I'll move away from withVaList, which also should fix swiftlang/swift-android-examples#15

@ktoso ktoso merged commit 8560a5b into swiftlang:main Oct 31, 2025
69 of 78 checks passed
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.

3 participants