Skip to content

Commit caacd7c

Browse files
committed
Update Kotlin wrapper to use wp_mobile crate
1 parent 42d4db1 commit caacd7c

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

native/kotlin/api/android/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ dependencies {
8484
}
8585

8686
val cargoProjectRoot = rootProject.ext.get("cargoProjectRoot")!!
87-
val moduleName = "wp_api"
87+
val moduleName = rootProject.ext.get("rustPrimaryModule").toString()
8888
cargo {
8989
cargoCommand = rootProject.ext.get("cargoBinaryPath").toString()
9090
rustcCommand = rootProject.ext.get("rustcBinaryPath").toString()

native/kotlin/api/kotlin/build.gradle.kts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,14 @@ sourceSets {
8484
}
8585
}
8686

87+
// UniFFI supports generating bindings for multiple crates from a single library file.
88+
// When wp_mobile is built, it includes wp_api as a dependency, so libwp_mobile contains
89+
// metadata for both crates. We generate bindings for each crate from the single library.
8790
val generateUniFFIBindingsTask = tasks.register<Exec>("generateUniFFIBindings") {
8891
val cargoProjectRoot = rootProject.ext.get("cargoProjectRoot")
8992
val uniffiGeneratedPath = "${layout.buildDirectory.get()}/generated/source/uniffi/java"
9093
val nativeLibraryPath = rootProject.ext.get("nativeLibraryPath")!!
91-
val rustModuleName = rootProject.ext.get("rustModuleName")
94+
val rustPrimaryModule = rootProject.ext.get("rustPrimaryModule")
9295

9396
dependsOn(rootProject.tasks.named("cargoBuildLibraryRelease"))
9497
workingDir(project.rootDir)
@@ -114,8 +117,6 @@ val generateUniFFIBindingsTask = tasks.register<Exec>("generateUniFFIBindings")
114117
inputs.dir("$cargoProjectRoot/wp_uniffi_bindgen/")
115118
// Re-generate if our uniffi-bindgen version changes.
116119
inputs.file("$cargoProjectRoot/Cargo.lock")
117-
// Re-generate if the module source code changes
118-
inputs.dir("$cargoProjectRoot/$rustModuleName/")
119120
}
120121

121122
tasks.named("compileKotlin").configure {

native/kotlin/api/kotlin/src/integrationTest/kotlin/UsersEndpointTest.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ import uniffi.wp_api.SparseUserFieldWithEditContext
66
import uniffi.wp_api.UserListParams
77
import uniffi.wp_api.WpApiParamUsersHasPublishedPosts
88
import uniffi.wp_api.WpErrorCode
9+
import uniffi.wp_mobile.wpMobileCrateWorks
910
import kotlin.test.assertEquals
1011
import kotlin.test.assertNull
1112

1213
class UsersEndpointTest {
1314
private val client = defaultApiClient()
1415

16+
@Test
17+
fun testThatWpMobileCrateWorks() = runTest {
18+
assertEquals("foo is bar", wpMobileCrateWorks("bar"))
19+
}
20+
1521
@Test
1622
fun testUserListRequest() = runTest {
1723
val userList = client.request { requestBuilder ->

native/kotlin/build.gradle.kts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ allprojects {
3232
// Exclude generated bindings
3333
exclude("**/wp_api.kt")
3434
exclude("**/wp_localization.kt")
35+
exclude("**/wp_mobile.kt")
3536
}
3637

3738
tasks.withType<io.gitlab.arturbosch.detekt.DetektCreateBaselineTask>().configureEach {
@@ -40,6 +41,7 @@ allprojects {
4041
// Exclude generated bindings
4142
exclude("**/wp_api.kt")
4243
exclude("**/wp_localization.kt")
44+
exclude("**/wp_mobile.kt")
4345
}
4446

4547
dependencies {
@@ -52,28 +54,28 @@ val rustcBinaryPath = resolveBinary("rustc")
5254
val cargoProjectRoot = "${project.rootDir}/../.."
5355
val jniLibsPath = "${layout.buildDirectory.get()}/jniLibs/"
5456
val generatedTestResourcesPath = "${layout.buildDirectory.get()}/generatedTestResources/"
55-
val rustModuleName = "wp_api"
57+
val rustPrimaryModule = "wp_mobile"
5658
val nativeLibraryPath =
57-
"$cargoProjectRoot/target/release/lib${rustModuleName}${getNativeLibraryExtension()}"
59+
"$cargoProjectRoot/target/release/lib${rustPrimaryModule}${getNativeLibraryExtension()}"
5860

5961
rootProject.ext.set("cargoBinaryPath", cargoBinaryPath)
6062
rootProject.ext.set("rustcBinaryPath", rustcBinaryPath)
6163
rootProject.ext.set("cargoProjectRoot", cargoProjectRoot)
6264
rootProject.ext.set("jniLibsPath", jniLibsPath)
6365
rootProject.ext.set("generatedTestResourcesPath", generatedTestResourcesPath)
6466
rootProject.ext.set("nativeLibraryPath", nativeLibraryPath)
65-
rootProject.ext.set("rustModuleName", rustModuleName)
67+
rootProject.ext.set("rustPrimaryModule", rustPrimaryModule)
6668

6769
setupJniAndBindings()
6870

6971
// Separated as a function to have everything in a scope and keep it contained
7072
fun setupJniAndBindings() {
7173
val nativeLibraryPath =
72-
"$cargoProjectRoot/target/release/lib${rustModuleName}${getNativeLibraryExtension()}"
74+
"$cargoProjectRoot/target/release/lib${rustPrimaryModule}${getNativeLibraryExtension()}"
7375

7476
val cargoBuildLibraryReleaseTask = tasks.register<Exec>("cargoBuildLibraryRelease") {
7577
workingDir(rootProject.ext.get("cargoProjectRoot")!!)
76-
commandLine(cargoBinaryPath, "build", "--package", rustModuleName, "--release")
78+
commandLine(cargoBinaryPath, "build", "--package", rustPrimaryModule, "--release")
7779
// No inputs.dir added, because we want to always re-run this task and let Cargo handle caching
7880
}
7981

0 commit comments

Comments
 (0)