Overview
The C-Interop feature of the Kreate Gradle plugin provides a fully automated pipeline for bridging Kotlin/Native multiplatform projects with native Rust libraries. When enabled, Kreate orchestrates every step — from initializing a Rust project via Cargo, adding dependencies, compiling for multiple native targets, generating C headers with cbindgen, producing Kotlin/Native .def files, and wiring the resulting static libraries into your Kotlin Multiplatform build — all without manual setup.
Pipeline Overview
The C-Interop pipeline consists of six ordered Gradle tasks that run automatically before any Kotlin/Native compilation:
Step | Task | Description |
|---|---|---|
1 |
| Creates a new Rust library project with |
2 |
| Adds |
3 |
| Appends |
4 |
| Generates a |
5 |
| Runs |
6 |
| Writes the Kotlin/Native |
After step 6 completes, all CInteropProcess tasks automatically depend on kreate-c-interop-definitions, so your normal build or assemble invocation drives the entire chain.
Native Language Selection
Since Kreate 1.3.0, C-Interop supports C and C++ as first-class native languages alongside Rust. The language option selects the underlying pipeline:
| Toolchain | Pipeline summary |
|---|---|---|
| Cargo + cbindgen | (default) Initializes a Cargo project and generates headers with |
| CMake | Scaffolds a CMake C project and builds a static library bridged via a C header |
| CMake | Scaffolds a CMake C++ project and builds a static library bridged via a C header |
For C and CPP, the pipeline is reduced to three tasks:
Step | Task | Description |
|---|---|---|
1 |
| Scaffolds a CMake project with |
2 |
| Runs |
3 |
| Writes the Kotlin/Native |
The C/C++ flow requires CMake 3.20 or later and a C/C++ compiler instead of the Rust toolchain. The public API is declared in a hand-written header include/<projectName>.h (using an extern "C" boundary for C++), which Kotlin/Native consumes directly.
Enabling C-Interop
C-Interop is disabled by default. Enable it inside your module's build.gradle.kts within the kreate extension block:
Once enabled, all six pipeline tasks are registered automatically and execute in order before the first CInteropProcess task runs.
Next Steps
Configuration Reference: DSL reference and all available options
Gradle Tasks: Details on the individual pipeline tasks
Examples: Practical examples and usage patterns
Troubleshooting: Common issues and solutions
Generated Project Layout
After the pipeline runs, the following structure is created inside your Gradle module:
C-Interop Package Name
By default, the Kotlin package under which the native symbols are exposed is derived from the Gradle project group and the (lowercased) project name:
Override it with packageNameOverride:
Cargo Command Resolution
On macOS, Kreate looks for cargo at ~/.cargo/bin/cargo (the default rustup install path). On all other platforms, it simply invokes cargo from the system PATH.