Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
265 changes: 31 additions & 234 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resolver = "2"
[workspace.dependencies]
# External traits in UDL is only available since https://github.com/mozilla/uniffi-rs/pull/1867
# Point to a specific commit until a new version is released
uniffi = { git = "https://github.com/mozilla/uniffi-rs.git", rev = "d380d164cfdba9e091c461baa6855f0a2294ac5b" }
uniffi = { git = "https://github.com/mozilla/uniffi-rs.git", rev = "22a9192162744b8a46997dcdcf628a7dba769570" }
# We need to match the version used in `reqwest`: https://github.com/seanmonstar/reqwest/blob/master/Cargo.toml#L84
# So that we can implement our own traits and it'll work with both reqwest types as well as http types
#
Expand Down
80 changes: 80 additions & 0 deletions native/android/common.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Adopted from https://github.com/mozilla/application-services/blob/v120.0.1/publish.gradle#L206-L226
//
// A convenience function for configuring a `uniffi-bindgen` task,
// with appropriate dependency info. This will call `uniffi-bindgen`
// for the provided `moduleName`'s `.dylib` file in order to generate Kotlin language
// bindings and include them in the source set for the project.
ext.configureUniFFIBindgen = { moduleName ->
android.libraryVariants.all { variant ->
def uniffiGeneratedPath = "$buildDir/generated/source/uniffi/${variant.name}/java"
def dylibFilePath = "${project.projectDir}/../../../target/release/lib${moduleName}.dylib"
def t = tasks.register("generate${variant.name.capitalize()}UniFFIBindings", Exec) {
workingDir project.rootDir
commandLine 'cargo', 'run', '--release', '--bin', 'uniffi_bindgen', 'generate', '--library', dylibFilePath, '--out-dir', uniffiGeneratedPath, '--language', 'kotlin'
outputs.dir uniffiGeneratedPath
// Re-generate if the interface definition changes.
inputs.file dylibFilePath
// Re-generate if our uniffi-bindgen tooling changes.
inputs.dir "${project.rootDir}/../../uniffi_bindgen/"
// Re-generate if our uniffi-bindgen version changes.
inputs.file "${project.rootDir}/../../Cargo.lock"
// Re-generate if the module source code changes
inputs.dir "${project.rootDir}/../../${moduleName}/"
}
variant.registerJavaGeneratingTask(t.get(), new File(buildDir, uniffiGeneratedPath))
def sourceSet = variant.sourceSets.find { it.name == variant.name }
sourceSet.java.srcDir new File(buildDir, "generated/source/uniffi/${variant.name}/java/uniffi")
}
}

ext.addJnaDependencies = {
dependencies {
implementation "net.java.dev.jna:jna:5.13.0@aar"
androidTestImplementation "net.java.dev.jna:jna:5.13.0@aar"
testImplementation "net.java.dev.jna:jna:5.13.0"
}
}

ext.setupCargo = { moduleName, nativeRustTarget ->
cargo {
module = "../../../$moduleName/"
libname = moduleName
profile = "release"
targets = ["arm", "arm64", "x86", "x86_64", nativeRustTarget]
targetDirectory = '../../../target'

exec { spec, toolchain ->
// https://doc.rust-lang.org/rustc/command-line-arguments.html#-g-include-debug-information
spec.environment("RUSTFLAGS", "-g")
}
}
tasks.matching { it.name.matches(/merge.*JniLibFolders/) }.configureEach {
it.inputs.dir(new File(buildDir, "rustJniLibs/android"))
it.dependsOn("cargoBuild")
}

tasks.matching { it.name.matches("test") }.configureEach {
it.dependsOn("cargoBuild")
}
}

ext.getNativeRustTarget = { resourcePrefix ->
switch (resourcePrefix) {
case 'darwin':
// For unit tests to work in Apple Silicon, we need to return 'darwin-aarch64' here
// However, that runs the cargo task as `cargoBuildDarwin-aarch64` which is not properly
// cached by cargo and requires a rebuild every time. This results in a significant
// development time loss, so for now, we are returning 'darwin' and using instrumented
// tests instead.
// return 'darwin-aarch64'
return 'darwin'
case 'darwin-aarch64':
return 'darwin-aarch64'
case 'darwin-x86-64':
return 'darwin-x86-64'
case 'linux-x86-64':
return 'linux-x86-64'
case 'win32-x86-64':
return 'win32-x86-64-gnu'
}
}
109 changes: 0 additions & 109 deletions native/android/lib/build.gradle

This file was deleted.

This file was deleted.

22 changes: 0 additions & 22 deletions native/android/lib/src/main/kotlin/wordpress/rs/Library.kt

This file was deleted.

24 changes: 0 additions & 24 deletions native/android/lib/src/test/kotlin/wordpress/rs/LibraryTest.kt

This file was deleted.

23 changes: 0 additions & 23 deletions native/android/lib/uniffi.gradle

This file was deleted.

2 changes: 1 addition & 1 deletion native/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ plugins {
}

rootProject.name = "wordpress-rs"
include("lib")
include("wp_api")
73 changes: 73 additions & 0 deletions native/android/wp_api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("org.mozilla.rust-android-gradle.rust-android")
id("com.automattic.android.publish-to-s3")
}

apply from: '../common.gradle'

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

android {
namespace = "rs.wordpress.wp_api"

compileSdk = 33

defaultConfig {
minSdk = 24

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

ndk {
debugSymbolLevel 'FULL'
}
}

sourceSets {
androidTest.jniLibs.srcDirs += "$buildDir/rustJniLibs/android"
}

packagingOptions {
doNotStrip "**/*.so"
}
}

repositories {
mavenCentral()
google()
}

dependencies {
implementation("com.squareup.okhttp3:okhttp:4.12.0")

androidTestImplementation "androidx.test:runner:1.4.0"
androidTestImplementation "androidx.test:rules:1.4.0"
androidTestImplementation "junit:junit:4.13.2"
androidTestImplementation 'org.jetbrains.kotlin:kotlin-test'

testImplementation "junit:junit:4.13.2"
}

ext.setupCargo("wp_api", ext.getNativeRustTarget(com.sun.jna.Platform.RESOURCE_PREFIX))
ext.configureUniFFIBindgen("wp_api")
ext.addJnaDependencies()

project.afterEvaluate {
publishing {
publications {
MavenPublication(MavenPublication) {
from components.release

groupId "rs.wordpress"
artifactId "wp_api"
// version is set by 'publish-to-s3' plugin
}
}
}
}

Loading