Skip to content

Samples: Swift 6 language mode JNI sample used from Kotlin - #9

Closed
piercifani wants to merge 1 commit into
mainfrom
jni/00-kotlin-sample
Closed

piercifani wants to merge 1 commit into
mainfrom
jni/00-kotlin-sample

Conversation

@piercifani

Copy link
Copy Markdown

Stack 1/8 · base: main · next: #1

What

A new sample, Samples/SwiftJavaExtractJNIKotlinSampleApp. Its jextract (JNI mode) bindings are used from Kotlin, and its Swift modules build in Swift 6 language mode. Every later PR in this stack adds its own Swift fixture and Kotlin test here, so each PR shows the Kotlin code it enables.

  • Two Swift modules: KotlinSampleModels and KotlinSampleLibrary. Types (and later protocols) cross the module boundary.
  • One Kotlin test file per feature under src/test/kotlin/com/example/kotlin/, using kotlin.test and kotlinx-coroutines (await() on the generated futures).
  • memoryManagementMode: allowGlobalAutomatic, so the Kotlin reads without arenas where jextract allows it.
  • Added to the CI sample matrices (Linux and macOS) through ci-validate.sh, like the other samples.

Kotlin in this PR

BaselineTest.kt covers what works on main today: a struct (properties, equals/hashCode), a throwing function, an async function awaited as a coroutine, an enum with a payload, and a type from the other module.

Why

The JNI sample builds in Swift 5 mode and is used from Java. Skip Fuse apps are Swift 6 and their Android code is Kotlin. Several fixes in this stack only show up in Swift 6 mode (Sendable, actor isolation), and Kotlin differs from Java in ways that matter for the API: lambdas as functional interfaces, getters as properties, platform types, coroutines.

Testing

./gradlew :Samples:SwiftJavaExtractJNIKotlinSampleApp:test passes on main (5 tests).

🤖 Generated with Claude Code

A jextract (JNI mode) sample whose Swift modules build in Swift 6 language
mode and whose bindings are exercised from Kotlin tests: one test file per
feature under src/test/kotlin. KotlinSampleModels is a separate module, so
types (and later protocols) cross module boundaries.

The baseline covers what works today: a struct, a throwing function, an async
function awaited as a coroutine, an enum with a payload, and a type from
another module. Added to the CI sample matrix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cla-bot cla-bot Bot added the cla-signed label Nov 3, 2026
@piercifani

Copy link
Copy Markdown
Author

Folded into #1: GitHub won't change the base of the first PR in an existing stack, so the Kotlin sample's base commit ships as the first commit of #1 instead of its own PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant