Skip to content

Commit

Permalink
Add kotlin multiplatform bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeross committed Apr 30, 2024
1 parent 7add324 commit b33c0c0
Show file tree
Hide file tree
Showing 15 changed files with 707 additions and 2 deletions.
111 changes: 110 additions & 1 deletion lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lib/ls-sdk-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ crate-type = ["staticlib", "cdylib", "lib"]
anyhow = { workspace = true }
breez-liquid-sdk = { path = "../ls-sdk-core" }
uniffi = { workspace = true, features = [ "bindgen-tests", "cli" ] }
# Bindgen used by KMP, version has to match the one supported by KMP
uniffi_bindgen = "0.25.2"
uniffi-kotlin-multiplatform = { git = "https://gitlab.com/trixnity/uniffi-kotlin-multiplatform-bindings", rev = "55d51f3abf9819b32bd81756053dcfc10f8d5522" }
camino = "1.1.1"
thiserror = { workspace = true }

[build-dependencies]
Expand Down
54 changes: 54 additions & 0 deletions lib/ls-sdk-bindings/bindings-kotlin-multiplatform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Created by https://www.toptal.com/developers/gitignore/api/android
# Edit at https://www.toptal.com/developers/gitignore?templates=android

### Android ###
# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Log/OS Files
*.log

# Android Studio generated files and folders
captures/
.externalNativeBuild/
.cxx/
*.apk
output.json

# IntelliJ
*.iml
.idea/
misc.xml
deploymentTargetDropDown.xml
render.experimental.xml

# Keystore files
*.jks
*.keystore

# Google Services (e.g. APIs or Firebase)
google-services.json

# Android Profiling
*.hprof

### Android Patch ###
gen-external-apklibs

# Replacement of .externalNativeBuild directories introduced
# with Android Studio 3.5.

# End of https://www.toptal.com/developers/gitignore/api/android

breez-liquid-sdk-kmp/src/androiddMain/jniLibs/
breez-liquid-sdk-kmp/src/jvmMain/jniLibs/

breez-liquid-sdk-kmp/src/commonMain/kotlin/breez_liquid_sdk
breez-liquid-sdk-kmp/src/jvmMain/kotlin/breez_liquid_sdk
breez-liquid-sdk-kmp/src/androidMain/kotlin/breez_liquid_sdk
breez-liquid-sdk-kmp/src/nativeMain/kotlin/breez_liquid_sdk
breez-liquid-sdk-kmp/src/nativeInterop/cinterop/headers/breez_liquid_sdk
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
plugins {
kotlin("multiplatform")
id("com.android.library")
id("maven-publish")
}

apply(plugin = "kotlinx-atomicfu")

kotlin {
// Enable the default target hierarchy
applyDefaultHierarchyTemplate()

androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.majorVersion
}
}

publishLibraryVariants("release")
}

jvm {
compilations.all {
kotlinOptions.jvmTarget = JavaVersion.VERSION_17.majorVersion
}
}

listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
val platform = when (it.targetName) {
"iosSimulatorArm64" -> "ios_simulator_arm64"
"iosArm64" -> "ios_arm64"
"iosX64" -> "ios_x64"
else -> error("Unsupported target $name")
}

it.compilations["main"].cinterops {
create("breezCInterop") {
defFile(project.file("src/nativeInterop/cinterop/breez.def"))
includeDirs(project.file("src/nativeInterop/cinterop/headers/breez_liquid_sdk"), project.file("src/libs/$platform"))
}
}
}

sourceSets {
all {
languageSettings.apply {
optIn("kotlinx.cinterop.ExperimentalForeignApi")
}
}

val commonMain by getting {
dependencies {
implementation("com.squareup.okio:okio:3.6.0")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.5.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
}
}

val jvmMain by getting {
dependsOn(commonMain)
dependencies {
implementation("net.java.dev.jna:jna:5.13.0")
}
}

val androidMain by getting {
dependsOn(commonMain)
dependencies {
implementation("net.java.dev.jna:jna:5.13.0@aar")
implementation("org.jetbrains.kotlinx:atomicfu:0.23.1")
}
}
}
}

android {
namespace = "technology.breez"
compileSdk = 33

defaultConfig {
minSdk = 21
consumerProguardFiles("consumer-rules.pro")
}

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

val libraryVersion: String by project

group = "technology.breez"
version = libraryVersion

publishing {
repositories {
maven {
name = "breezReposilite"
url = uri("https://mvn.breez.technology/releases")
credentials(PasswordCredentials::class)
authentication {
create<BasicAuthentication>("basic")
}
}
}

publications {
this.forEach {
(it as MavenPublication).apply {
pom {
name.set("breez-liquid-sdk-kmp")
description.set("The Breez Liquid SDK enables mobile developers to integrate Liquid swaps into their apps with a very shallow learning curve.")
url.set("https://breez.technology")
licenses {
license {
name.set("MIT")
url.set("https://github.com/breez/breez-liquid-sdk/blob/main/LICENSE")
}
}
scm {
connection.set("scm:git:github.com/breez/breez-liquid-sdk.git")
developerConnection.set("scm:git:ssh://github.com/breez/breez-liquid-sdk.git")
url.set("https://github.com/breez/breez-liquid-sdk")
}
}
}
}
}
}
Loading

0 comments on commit b33c0c0

Please sign in to comment.