Skip to content

feat: Add alef-backend-kotlin-mpp crate for Kotlin Multiplatform (community contribution welcome) #82

Description

@Goldziher

Goal

Carve out Kotlin Multiplatform (KMP) emission from the JVM-focused alef-backend-kotlin crate into a standalone alef-backend-kotlin-mpp crate, parallel to the newly-introduced alef-backend-kotlin-android crate (v0.16.0).

Background

alef-backend-kotlin historically dispatched between three Kotlin flavors via two overlapping axes — KotlinConfig.mode = "jvm"|"kmp"|"android" and KotlinTarget::{Jvm,Native,Multiplatform}. v0.16.0 cleaned this up for Android by:

  • Adding Language::KotlinAndroid as a first-class slug ("kotlin_android").
  • Moving Android emission into the dedicated alef-backend-kotlin-android crate.
  • Removing the in-band mode = "android" path from alef-backend-kotlin.

KMP deserves the same treatment but was deferred until concrete demand surfaced.

Approach

  1. New crate: crates/alef-backend-kotlin-mpp/ carved from the current alef-backend-kotlin/src/gen_mpp.rs module. Self-contained — emits build.gradle.kts (multiplatform plugin), settings.gradle.kts with proper pluginManagement, commonMain/jvmMain/androidNativeArm64Main/linuxX64Main/macosArm64Main source sets, .def files for cinterop where applicable.
  2. New Language::KotlinMpp variant in alef-core::config::extras::Language (slug "kotlin_mpp").
  3. Remove old paths: drop KotlinTarget::Multiplatform enum variant from alef-backend-kotlin and the mode = "kmp" branch in gen_bindings/mod.rs (deprecate-and-bail!, same pattern as mode = "android").
  4. Snapshot tests: insta-based, covering each emitted file for a representative API surface (struct, enum, error, sync fn, async fn, streaming fn).
  5. Publish lane: add to .github/workflows/publish.yaml cargo publish ordering (after alef-backend-java since the JVM side imports the Java facade — same pattern as alef-backend-kotlin-android). Wire crates.io trusted publisher.

Reference implementation

  • crates/alef-backend-kotlin-android/ (v0.16.0) — closest template; same crate-carve-out pattern, same alef-backend-java re-emission for the JVM source set.
  • crates/alef-backend-kotlin/src/gen_mpp.rs — existing emission to port.
  • crates/alef-scaffold/src/languages/kotlin.rs::scaffold_kotlin_multiplatform — existing scaffold artifacts to consolidate into the new crate.

Suggested scope

  1. Stage A: New crate skeleton + Language::KotlinMpp plumbing in alef-core (extras.rs, languages.rs, output.rs).
  2. Stage B: Port gen_mpp.rs emission into the new crate; ensure settings.gradle.kts ships with pluginManagement { repositories { google(); mavenCentral(); gradlePluginPortal() } } so KMP-Android targets resolve.
  3. Stage C: Snapshot tests; delete scaffold scaffold_kotlin_multiplatform after parity.
  4. Stage D: Hard-error fallback in alef-backend-kotlin/src/gen_bindings/mod.rs for mode = "kmp" and KotlinTarget::Multiplatform.
  5. Stage E: Update .github/workflows/publish.yaml and CHANGELOG; bump alef minor version.

Effort estimate

M (~2–4 days). The trickiest piece is the KMP gradle scaffolding — getting the targets list (jvm(), androidNativeArm64(), linuxX64(), macosArm64()) right and ensuring cinterop .def files match the cbindgen header surface.

Status

Deferred pending concrete user demand. The current single-Kotlin-flavor-per-workspace constraint is fine for kreuzberg (Android-only). Open this issue for community contribution and as a tracking point if a consumer requests KMP.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions