Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate Kotlin bindings into its own module #344

Draft
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Draft
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
18 changes: 18 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,27 @@ steps:
./gradlew detektMain detektTest
agents:
queue: android
- label: ":kotlin: Publish `rs.wordpress.api:bindings`"
key: "publish-wp-api-kotlin-bindings"
plugins: [$CI_TOOLKIT]
command: |
echo "--- :rust: Installing Rust"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -v -y

source "$$HOME/.cargo/env"

echo "--- :package: Installing Rust Toolchains"
make setup-rust

echo "--- :kotlin: Publishing `rs.wordpress.api:bindings`"
.buildkite/publish-wp-api-kotlin-bindings.sh
agents:
queue: android
- label: ":kotlin: Publish `rs.wordpress.api:kotlin`"
key: "publish-wp-api-kotlin"
plugins: [$CI_TOOLKIT]
depends_on:
- "publish-wp-api-kotlin-bindings"
command: |
echo "--- :rust: Installing Rust"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -v -y
Expand Down
11 changes: 11 additions & 0 deletions .buildkite/publish-wp-api-kotlin-bindings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -euo pipefail

cd ./native/kotlin
./gradlew \
:api:bindings:prepareToPublishToS3 $(prepare_to_publish_to_s3_params) \
:api:bindings:publish

# Add meta-data for the published version so we can use it in subsequent steps
buildkite-agent meta-data set "PUBLISHED_WP_API_BINDINGS_VERSION" < ./api/bindings/build/published-version.txt
4 changes: 4 additions & 0 deletions .buildkite/publish-wp-api-kotlin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

set -euo pipefail

# Retrieve data from previous steps
PUBLISHED_WP_API_BINDINGS_VERSION=$(buildkite-agent meta-data get "PUBLISHED_WP_API_BINDINGS_VERSION")

cd ./native/kotlin
./gradlew \
-PwpApiBindingsVersion="$PUBLISHED_WP_API_BINDINGS_VERSION" \
:api:kotlin:prepareToPublishToS3 $(prepare_to_publish_to_s3_params) \
:api:kotlin:publish

Expand Down
78 changes: 78 additions & 0 deletions native/kotlin/api/bindings/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
plugins {
alias(libs.plugins.rustAndroid)
alias(libs.plugins.kotlinJvm)
alias(libs.plugins.publishToS3)
id("java-library")
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

dependencies {
implementation(libs.jna)
implementation(libs.kotlinx.coroutines.core)
}

sourceSets {
main {
java {
srcDir("${layout.buildDirectory.get()}/generated/source/uniffi/java/uniffi")
}
}
}

val generateUniFFIBindingsTask = tasks.register<Exec>("generateUniFFIBindings") {
val cargoProjectRoot = rootProject.ext.get("cargoProjectRoot")
val uniffiGeneratedPath = "${layout.buildDirectory.get()}/generated/source/uniffi/java"
val nativeLibraryPath = rootProject.ext.get("nativeLibraryPath")!!
val rustModuleName = rootProject.ext.get("rustModuleName")

dependsOn(rootProject.tasks.named("cargoBuildLibraryRelease"))
workingDir(project.rootDir)
commandLine(
"cargo",
"run",
"--release",
"--bin",
"wp_uniffi_bindgen",
"generate",
"--library",
nativeLibraryPath,
"--out-dir",
uniffiGeneratedPath,
"--language",
"kotlin"
)
outputs.dir(uniffiGeneratedPath)
// Re-generate if the interface definition changes.
inputs.file(nativeLibraryPath)
// Re-generate if our uniffi-bindgen tooling changes.
inputs.dir("$cargoProjectRoot/wp_uniffi_bindgen/")
// Re-generate if our uniffi-bindgen version changes.
inputs.file("$cargoProjectRoot/Cargo.lock")
// Re-generate if the module source code changes
inputs.dir("$cargoProjectRoot/$rustModuleName/")
}

tasks.named("compileKotlin").configure {
dependsOn(generateUniFFIBindingsTask)
}

project.afterEvaluate {
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])

groupId = "rs.wordpress.api"
artifactId = "bindings"
// version is set by "publish-to-s3" plugin
}
}
}
}
51 changes: 7 additions & 44 deletions native/kotlin/api/kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
plugins {
alias(libs.plugins.rustAndroid)
alias(libs.plugins.kotlinJvm)
alias(libs.plugins.kotlinSerialization)
alias(libs.plugins.publishToS3)
Expand Down Expand Up @@ -70,53 +69,17 @@ dependencies {
implementation(libs.okhttp)
implementation(libs.jna)
implementation(libs.kotlinx.coroutines.core)
}

sourceSets {
main {
java {
srcDir("${layout.buildDirectory.get()}/generated/source/uniffi/java/uniffi")
if (project.hasProperty("wpApiBindingsVersion")) {
api("rs.wordpress.api:bindings:${project.properties["wpApiBindingsVersion"]}") {
exclude(group = "net.java.dev.jna")
}
} else {
api(project(":api:bindings")) {
exclude(group = "net.java.dev.jna")
}
}
}

val generateUniFFIBindingsTask = tasks.register<Exec>("generateUniFFIBindings") {
val cargoProjectRoot = rootProject.ext.get("cargoProjectRoot")
val uniffiGeneratedPath = "${layout.buildDirectory.get()}/generated/source/uniffi/java"
val nativeLibraryPath = rootProject.ext.get("nativeLibraryPath")!!
val rustModuleName = rootProject.ext.get("rustModuleName")

dependsOn(rootProject.tasks.named("cargoBuildLibraryRelease"))
workingDir(project.rootDir)
commandLine(
"cargo",
"run",
"--release",
"--bin",
"wp_uniffi_bindgen",
"generate",
"--library",
nativeLibraryPath,
"--out-dir",
uniffiGeneratedPath,
"--language",
"kotlin"
)
outputs.dir(uniffiGeneratedPath)
// Re-generate if the interface definition changes.
inputs.file(nativeLibraryPath)
// Re-generate if our uniffi-bindgen tooling changes.
inputs.dir("$cargoProjectRoot/wp_uniffi_bindgen/")
// Re-generate if our uniffi-bindgen version changes.
inputs.file("$cargoProjectRoot/Cargo.lock")
// Re-generate if the module source code changes
inputs.dir("$cargoProjectRoot/$rustModuleName/")
}


tasks.named("compileKotlin").configure {
dependsOn(generateUniFFIBindingsTask)
}
tasks.named("processIntegrationTestResources").configure {
dependsOn(rootProject.tasks.named("copyDesktopJniLibs"))
dependsOn(rootProject.tasks.named("copyTestCredentials"))
Expand Down
2 changes: 1 addition & 1 deletion native/kotlin/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jna = "5.15.0"
junit = "4.13.2"
koin = "4.0.0"
kotlin = "1.9.24"
kotlinx-coroutines = "1.9.0"
kotlinx-coroutines = "1.8.1"
kotlinx-serialization-json = "1.6.3"
landscapist = "2.4.0"
lifecycle = "2.8.6"
Expand Down
1 change: 1 addition & 0 deletions native/kotlin/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencyResolutionManagement {
}
}

include(":api:bindings")
include(":api:kotlin")
include(":api:android")
include(":example:composeApp")