Add koltin multiplatform client SDK with codegen, gradle plugin and templates#4738
Open
FromWau wants to merge 194 commits intoclockworklabs:masterfrom
Open
Add koltin multiplatform client SDK with codegen, gradle plugin and templates#4738FromWau wants to merge 194 commits intoclockworklabs:masterfrom
FromWau wants to merge 194 commits intoclockworklabs:masterfrom
Conversation
kotlin: cleanup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Changes
Adds a Kotlin Multiplatform client SDK for SpacetimeDB with full code generation support, gradle plugin to auto generate bindings, templates, docs, (ai agent) skills and smoketests.
Note: There is an existing PR for a Kotlin SDK (#4472 by @AndroidPoet). We developed independently. That PR provides a SDK without codegen, using raw byte data. So users have to manually encode/decode BSATN bytes and use string-based reducer names. This PR includes: Rust codegen generating typed table handles, reducers, and procedures, a Gradle plugin that auto-generates bindings on build, two project templates, and smoketests.
Rust cli:
Codegen (Rust):
SDK runtime:
Gradle plugin:
Templates:
Example chat between android and desktop (jvm) using
compose-kttemplate:Jvm


Android
Benchmark:
Added Keynote-1 benchmark client (templates/keynote-2/spacetimedb-kotlin-client/): TPS benchmark matching the Rust client methodology.
Benchmark was run on: i7-12700H, 8GB Ram using 10 connections, 10s, alpha=1.5, confirmed reads
API and ABI breaking changes
CI now requires JDK 21+ installed in the smoketests job. The
spacetimedb-new-runner-2runner needs JDK 21+ available or the Kotlin tasks will fail.No API or ABI breaking changes otherwise.
Expected complexity level and risk
2
The SDK and codegen are self-contained. The only touchpoints with existing code are:
No changes to existing SDK behavior or server-side code.
Testing
Note: sdk and templates are tested against Android and JVM (Linux). I do not have an iOS device so i could not test against native.
cargo test -p spacetimedb-codegen(snapshot tests pass)cargo test -p spacetimedb-smoketests --test integration kotlin(unit tests, build validation, server integration)cargo test -p spacetimedb-smoketests --test integration test_all_templates(basic-kt and compose-kt)sdks/kotlin/./gradlew :spacetimedb-sdk:jvmTestsdks/kotlin/./gradlew :codegen-tests:test(generated bindings compile)cargo fmt+clippyreport no warningsspacetimedb-cli init --template basic-ktcreates a working projectspacetimedb-cli init --template compose-ktcreates a working projectStep-by-step: Testing the compose-kt template locally
Prerequisites: JDK 21+, Rust toolchain, For Android testing: Android emulator or device with adb
1. Clone and build
git clone https://github.com/FromWau/SpacetimeDB.git /tmp/spacetimedb-kotlin cd /tmp/spacetimedb-kotlin git checkout feat/kotlin-sdk cargo build --release -p spacetimedb-cli -p spacetimedb-standalone2. Generate the project from template
/tmp/spacetimedb-kotlin/target/release/spacetimedb-cli init \ --template compose-kt \ --project-path /tmp/compose-kt-test/ \ --non-interactive \ compose-kt-test3. Patch local SDK paths (needed because SDK is not yet published to Maven Central)
In
/tmp/compose-kt-test/settings.gradle.kts, uncomment and set the twoincludeBuildlines:pluginManagement { repositories { /* ... */ } // Need to include the Gradle plugin locally because it's not yet published to Maven Central includeBuild("/tmp/spacetimedb-kotlin/sdks/kotlin/spacetimedb-gradle-plugin") } // Need to include the SDK locally because it's not yet published to Maven Central includeBuild("/tmp/spacetimedb-kotlin/sdks/kotlin")In
/tmp/compose-kt-test/sharedClient/build.gradle.kts, add aspacetimedbblock beforekotlin:4. Start the server (in a separate terminal)
5. Publish the module
6. Run the desktop client
cd /tmp/compose-kt-test ./gradlew :desktopApp:run7. Run the Android client (requires emulator or device with
adb)cd /tmp/compose-kt-test ./gradlew :androidApp:installDebugNext steps
This PR needs the SDK and Gradle plugin published to Maven Central before merging. Right now templates and user projects require manually setting local SDK paths and plugin includes to work. Once published, they just pull dependencies from Maven/Gradle like normal. I'd publish under
com.clockworklabs.spacetimedb-sdkandcom.clockworklabs.spacetimedb-plugin. Would need access to thecom.clockworklabsMaven namespace or a new one. If that works for you, I'll add a Kotlin publish workflow to CI.