Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crypto-ffi/bindings/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ plugins {
id("com.vanniktech.maven.publish.base")
}

val jvmSources = projectDir.resolve("../jvm/src")
val sharedSources = projectDir.resolve("../shared/src/commonMain")
val jvmTestSources = projectDir.resolve("../jvm/src")

val dokkaHtmlJar = tasks.register<Jar>("dokkaHtmlJar") {
dependsOn(tasks.dokkaGeneratePublicationHtml)
Expand Down Expand Up @@ -87,12 +88,12 @@ android {
main {
kotlin {
srcDir(projectDir.resolve("src/main/uniffi"))
srcDir(jvmSources.resolve("main/kotlin"))
srcDir(sharedSources.resolve("kotlin"))
}
}
androidTest {
kotlin {
srcDir(jvmSources.resolve("test"))
srcDir(jvmTestSources.resolve("test"))
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions crypto-ffi/bindings/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ vanniktech-publish = "0.34.0"
kotlin-gradle = "1.9.21"
dokka = "2.0.0"
detekt = "1.23.8"
gobley = "0.3.7"

[plugins]
vanniktech-publish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktech-publish" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
gobley-cargo = { id = "dev.gobley.cargo", version.ref = "gobley" }
gobley-uniffi = { id = "dev.gobley.uniffi", version.ref = "gobley" }
gobley-rust = { id = "dev.gobley.rust", version.ref = "gobley" }
kotlin-atomicfu = { id = "org.jetbrains.kotlin.plugin.atomicfu", version.ref = "kotlin" }

[libraries]
coroutines-bom = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-bom", version.ref = "coroutines" }
Expand Down
4 changes: 3 additions & 1 deletion crypto-ffi/bindings/jvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ kotlin {
jvmToolchain(17)
}

val sharedSources = projectDir.resolve("../shared/src/commonMain")

dependencies {
implementation(platform(kotlin("bom")))
implementation(platform(libs.coroutines.bom))
Expand Down Expand Up @@ -61,7 +63,7 @@ tasks.named("compileKotlin") {
sourceSets {
main {
kotlin {
srcDir(projectDir.resolve("src/main/kotlin"))
srcDir(sharedSources.resolve("kotlin"))
srcDir(projectDir.resolve("src/main/uniffi"))
}
resources {
Expand Down

This file was deleted.

177 changes: 177 additions & 0 deletions crypto-ffi/bindings/kmp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import gobley.gradle.GobleyHost
import gobley.gradle.cargo.dsl.*
import org.gradle.api.tasks.bundling.Jar

plugins {
kotlin("multiplatform")
id("com.android.library")
alias(libs.plugins.gobley.cargo)
alias(libs.plugins.gobley.uniffi)
id("com.vanniktech.maven.publish.base")
alias(libs.plugins.kotlin.atomicfu)
}

val dokkaHtmlJar = tasks.register<Jar>("dokkaHtmlJar") {
dependsOn(tasks.dokkaGeneratePublicationHtml)
from(tasks.dokkaGeneratePublicationHtml.flatMap { it.outputDirectory })
archiveClassifier.set("html-docs")
}

kotlin {
jvmToolchain(17)

// Android target
androidTarget {
publishLibraryVariants("release")
}

// JVM target
jvm()

// iOS targets
iosArm64()
iosSimulatorArm64()

// macOS ARM64 target
macosArm64()

sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.coroutines.core)
}
}

val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.coroutines.test)
}
}

val jvmMain by getting {
dependencies {
implementation(libs.jna)
}
}

val jvmTest by getting {
dependencies {
implementation(libs.assertj.core)
}
}

val androidMain by getting {
dependencies {
implementation("${libs.jna.get()}@aar")
implementation("androidx.annotation:annotation:1.9.1")
}
}

val androidInstrumentedTest by getting {
dependencies {
implementation(libs.android.junit)
implementation(libs.espresso)
implementation(libs.assertj.core)
}
}

// Native targets share sources
val nativeMain by creating {
dependsOn(commonMain)
}

val nativeTest by creating {
dependsOn(commonTest)
}

val iosArm64Main by getting {
dependsOn(nativeMain)
}

val iosArm64Test by getting {
dependsOn(nativeTest)
}

val iosSimulatorArm64Main by getting {
dependsOn(nativeMain)
}

val iosSimulatorArm64Test by getting {
dependsOn(nativeTest)
}

val macosArm64Main by getting {
dependsOn(nativeMain)
}

val macosArm64Test by getting {
dependsOn(nativeTest)
}
}
}

android {
namespace = "com.wire.crypto"
compileSdk = libs.versions.sdk.compile.get().toInt()

defaultConfig {
minSdk = libs.versions.sdk.min.get().toInt()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

ndk {
abiFilters += setOf("arm64-v8a", "armeabi-v7a", "x86_64")
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}

cargo {
// Point to the crypto-ffi crate directory
packageDirectory = layout.projectDirectory.dir("../..")

// Only build JVM native libraries for the current host platform
// This disables cross-compilation for other JVM targets (e.g., Linux ARM64 on macOS)
builds.jvm {
embedRustLibrary = (rustTarget == GobleyHost.current.rustTarget)
}
}

// Configure iOS build tasks with the required environment
afterEvaluate {
tasks.matching { it.name.contains("cargoBuildIos") }.configureEach {
// Set environment via the task's additionalEnvironment if available
if (this is gobley.gradle.cargo.tasks.CargoBuildTask) {
val target = if (name.contains("Simulator")) {
"IPHONESIMULATOR_DEPLOYMENT_TARGET"
} else {
"IPHONEOS_DEPLOYMENT_TARGET"
}
additionalEnvironment.put(target, "16.0")
}
}
}

uniffi {
generateFromLibrary {
namespace = "core_crypto_ffi"
packageName = "com.wire.crypto"
}
}

mavenPublishing {
publishToMavenCentral(automaticRelease = true)
pomFromGradleProperties()
signAllPublications()
}

// Allows skipping signing jars published to 'MavenLocal' repository
tasks.withType<Sign>().configureEach {
if (System.getenv("CI") == null) {
enabled = false
}
}
2 changes: 1 addition & 1 deletion crypto-ffi/bindings/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pluginManagement {
}
}

include("jvm", "android")
include("shared", "jvm", "android", "kmp")
21 changes: 21 additions & 0 deletions crypto-ffi/bindings/shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This module holds shared Kotlin source files used by both JVM and Android modules.
// The sources are included directly by those modules rather than compiled as a separate library,
// because they depend on Uniffi-generated types that are platform-specific.

plugins {
kotlin("multiplatform")
}

kotlin {
jvmToolchain(17)

jvm()

sourceSets {
commonMain {
dependencies {
implementation(kotlin("stdlib"))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wire.crypto

internal fun String.toByteArray() = encodeToByteArray()

// this opt-in can be removed once the project updates to Kotlin 2.2 or higher
@OptIn(ExperimentalStdlibApi::class)
internal fun ByteArray.toHex(): String = toHexString()
Loading