Skip to content

JNI: expose C-compatible types and calls to C++ consumers - #25

Open
NakaokaRei wants to merge 1 commit into
swiftlang:mainfrom
NakaokaRei:fix/jni-cxx-interoperability
Open

NakaokaRei wants to merge 1 commit into
swiftlang:mainfrom
NakaokaRei:fix/jni-cxx-interoperability

Conversation

@NakaokaRei

Copy link
Copy Markdown

Problem

C++-enabled Swift consumers import different JNI types from Android's jni.h than a runtime compiled in C mode. Accessing imported function-table fields or constructing an object-valued jvalue in the consumer can also expose those C++ types, causing type mismatches.

This extracts the low-level helpers from swiftlang/swift-java#927 into JNI Core, following the review feedback.

Solution

  • Add JNITypes aliases and an object-value factory defined in the runtime's C import context.
  • Expose typed JNI function-table accessors through JNIEnvironment.swiftInterface so consumers preserve those signatures without casts.
  • Add a C++-enabled consumer test target that calls Java String.concat, passing an object argument through jvalue and converting the returned reference.

Testing

  • Core tests on macOS, including the C++ consumer test.
  • Android ARM64 cross-build of the C++ consumer test target.
  • Integration with the companion swift-java changes: 840 package tests; JavaKit normal/C++ modes (17 tests each); JNI sample normal/C++ modes (273 tests each); Android ARM64 JNI sample build with C++ enabled.

Integration checks used a local dependency override. The companion changes in swift-java will consume these helpers after they are available upstream.

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.

1 participant