Skip to content

Commit 8be9761

Browse files
committed
feat: Add KMP module
1 parent 004fac0 commit 8be9761

File tree

3 files changed

+183
-1
lines changed

3 files changed

+183
-1
lines changed

crypto-ffi/bindings/gradle/libs.versions.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ vanniktech-publish = "0.34.0"
1414
kotlin-gradle = "1.9.21"
1515
dokka = "2.0.0"
1616
detekt = "1.23.8"
17+
gobley = "0.3.7"
1718

1819
[plugins]
1920
vanniktech-publish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktech-publish" }
2021
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
2122
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
23+
gobley-cargo = { id = "dev.gobley.cargo", version.ref = "gobley" }
24+
gobley-uniffi = { id = "dev.gobley.uniffi", version.ref = "gobley" }
25+
gobley-rust = { id = "dev.gobley.rust", version.ref = "gobley" }
26+
kotlin-atomicfu = { id = "org.jetbrains.kotlin.plugin.atomicfu", version.ref = "kotlin" }
2227

2328
[libraries]
2429
coroutines-bom = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-bom", version.ref = "coroutines" }
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
import gobley.gradle.GobleyHost
2+
import gobley.gradle.cargo.dsl.*
3+
import org.gradle.api.tasks.bundling.Jar
4+
5+
plugins {
6+
kotlin("multiplatform")
7+
id("com.android.library")
8+
alias(libs.plugins.gobley.cargo)
9+
alias(libs.plugins.gobley.uniffi)
10+
id("com.vanniktech.maven.publish.base")
11+
alias(libs.plugins.kotlin.atomicfu)
12+
}
13+
14+
val dokkaHtmlJar = tasks.register<Jar>("dokkaHtmlJar") {
15+
dependsOn(tasks.dokkaGeneratePublicationHtml)
16+
from(tasks.dokkaGeneratePublicationHtml.flatMap { it.outputDirectory })
17+
archiveClassifier.set("html-docs")
18+
}
19+
20+
kotlin {
21+
jvmToolchain(17)
22+
23+
// Android target
24+
androidTarget {
25+
publishLibraryVariants("release")
26+
}
27+
28+
// JVM target
29+
jvm()
30+
31+
// iOS targets
32+
iosArm64()
33+
iosSimulatorArm64()
34+
35+
// macOS ARM64 target
36+
macosArm64()
37+
38+
sourceSets {
39+
val commonMain by getting {
40+
dependencies {
41+
implementation(libs.coroutines.core)
42+
}
43+
}
44+
45+
val commonTest by getting {
46+
dependencies {
47+
implementation(kotlin("test"))
48+
implementation(libs.coroutines.test)
49+
}
50+
}
51+
52+
val jvmMain by getting {
53+
dependencies {
54+
implementation(libs.jna)
55+
}
56+
}
57+
58+
val jvmTest by getting {
59+
dependencies {
60+
implementation(libs.assertj.core)
61+
}
62+
}
63+
64+
val androidMain by getting {
65+
dependencies {
66+
implementation("${libs.jna.get()}@aar")
67+
implementation("androidx.annotation:annotation:1.9.1")
68+
}
69+
}
70+
71+
val androidInstrumentedTest by getting {
72+
dependencies {
73+
implementation(libs.android.junit)
74+
implementation(libs.espresso)
75+
implementation(libs.assertj.core)
76+
}
77+
}
78+
79+
// Native targets share sources
80+
val nativeMain by creating {
81+
dependsOn(commonMain)
82+
}
83+
84+
val nativeTest by creating {
85+
dependsOn(commonTest)
86+
}
87+
88+
val iosArm64Main by getting {
89+
dependsOn(nativeMain)
90+
}
91+
92+
val iosArm64Test by getting {
93+
dependsOn(nativeTest)
94+
}
95+
96+
val iosSimulatorArm64Main by getting {
97+
dependsOn(nativeMain)
98+
}
99+
100+
val iosSimulatorArm64Test by getting {
101+
dependsOn(nativeTest)
102+
}
103+
104+
val macosArm64Main by getting {
105+
dependsOn(nativeMain)
106+
}
107+
108+
val macosArm64Test by getting {
109+
dependsOn(nativeTest)
110+
}
111+
}
112+
}
113+
114+
android {
115+
namespace = "com.wire.crypto"
116+
compileSdk = libs.versions.sdk.compile.get().toInt()
117+
118+
defaultConfig {
119+
minSdk = libs.versions.sdk.min.get().toInt()
120+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
121+
122+
ndk {
123+
abiFilters += setOf("arm64-v8a", "armeabi-v7a", "x86_64")
124+
}
125+
}
126+
127+
compileOptions {
128+
sourceCompatibility = JavaVersion.VERSION_17
129+
targetCompatibility = JavaVersion.VERSION_17
130+
}
131+
}
132+
133+
cargo {
134+
// Point to the crypto-ffi crate directory
135+
packageDirectory = layout.projectDirectory.dir("../..")
136+
137+
// Only build JVM native libraries for the current host platform
138+
// This disables cross-compilation for other JVM targets (e.g., Linux ARM64 on macOS)
139+
builds.jvm {
140+
embedRustLibrary = (rustTarget == GobleyHost.current.rustTarget)
141+
}
142+
}
143+
144+
// Configure iOS build tasks with the required environment
145+
afterEvaluate {
146+
tasks.matching { it.name.contains("cargoBuildIos") }.configureEach {
147+
// Set environment via the task's additionalEnvironment if available
148+
if (this is gobley.gradle.cargo.tasks.CargoBuildTask) {
149+
val target = if (name.contains("Simulator")) {
150+
"IPHONESIMULATOR_DEPLOYMENT_TARGET"
151+
} else {
152+
"IPHONEOS_DEPLOYMENT_TARGET"
153+
}
154+
additionalEnvironment.put(target, "16.0")
155+
}
156+
}
157+
}
158+
159+
uniffi {
160+
generateFromLibrary {
161+
namespace = "core_crypto_ffi"
162+
packageName = "com.wire.crypto"
163+
}
164+
}
165+
166+
mavenPublishing {
167+
publishToMavenCentral(automaticRelease = true)
168+
pomFromGradleProperties()
169+
signAllPublications()
170+
}
171+
172+
// Allows skipping signing jars published to 'MavenLocal' repository
173+
tasks.withType<Sign>().configureEach {
174+
if (System.getenv("CI") == null) {
175+
enabled = false
176+
}
177+
}

crypto-ffi/bindings/settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ pluginManagement {
77
}
88
}
99

10-
include("shared", "jvm", "android")
10+
include("shared", "jvm", "android", "kmp")

0 commit comments

Comments
 (0)