Skip to content

Commit

Permalink
Try using cargo-ndk plugin; add serde derive feature (how did this wo…
Browse files Browse the repository at this point in the history
…rk before??)
  • Loading branch information
ianthetechie committed Nov 5, 2023
1 parent 9248106 commit 6fe94fa
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
working-directory: android

- name: Install cargo-ndk
run: cargo install cargo-ndk

- name: Build with Gradle
run: ./gradlew build
working-directory: android
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,8 @@ xcuserdata/
# Swift Package Manager
.build/

# Mac OS Ignores
.DS_Store
# macOS Ignores
.DS_Store

# Android (cargo-ndk outputs; they end up in the Android source tree)
*.so
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ plugins {
id 'com.android.application' version '8.1.2' apply false
id 'com.android.library' version '8.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
id 'org.mozilla.rust-android-gradle.rust-android' version '0.9.3' apply false
id 'com.github.willir.rust.cargo-ndk-android' version '0.3.4' apply false
}
22 changes: 6 additions & 16 deletions android/core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'org.mozilla.rust-android-gradle.rust-android'
id 'com.github.willir.rust.cargo-ndk-android'
}

// TODO: Publishing?
Expand Down Expand Up @@ -55,22 +55,20 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

cargo {
module = "../../common" // Directory containing Cargo.toml
libname = "ferrostar" // [package] name from Cargo.toml
targets = ["arm", "arm64", "x86", "x86_64", "darwin-aarch64"] // See https://github.com/mozilla/rust-android-gradle for a longer list of options
// TODO: Set profile to release for release builds!
cargoNdk {
module = "../common" // Directory containing Cargo.toml
librariesNames = ["libferrostar.so"]
verbose = true
}

android.libraryVariants.all { variant ->
def generateBindings = tasks.register("generate${variant.name.capitalize()}UniFFIBindings", Exec) {
workingDir '../../common'
commandLine 'cargo', 'run', '-p', 'uniffi-bindgen', 'generate', '--library', 'target/aarch64-linux-android/release/libferrostar.so', '--language', 'kotlin', '--out-dir', "${buildDir}/generated/source/uniffi/${variant.name}/java"

dependsOn 'cargoBuild'
dependsOn "buildCargoNdk${variant.name.capitalize()}"
}

variant.javaCompileProvider.get().dependsOn('cargoBuild')
variant.javaCompileProvider.get().dependsOn(generateBindings)

// Some stuff here is broken, since Android Tests don't run after running gradle build,
Expand All @@ -92,12 +90,4 @@ android.libraryVariants.all { variant ->
// idea.module.generatedSourceDirs += file("${buildDir}/generated/source/uniffi/${variant.name}/java/uniffi")

sourceSet.java.srcDir 'src/main/java'
}

// Fixes a bug(?) with certain AGP versions that results in UnsatisfiedLinkErrors in some conditions.
// See https://github.com/mozilla/rust-android-gradle/issues/118#issuecomment-1778332125

tasks.matching { it.name.matches(/merge.*JniLibFolders/) }.configureEach {
it.inputs.dir(new File(buildDir, "rustJniLibs/android"))
it.dependsOn("cargoBuild")
}
2 changes: 1 addition & 1 deletion common/ferrostar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ edition = "2021"
[dependencies]
geo = "0.26.0"
polyline = "0.10.0"
serde = "1.0.162"
serde = { version = "1.0.162", features = ["derive"] }
serde_json = "1.0.96"
thiserror = "1.0.40"
uniffi.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions common/ferrostar/src/routing_adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub trait RouteRequestGenerator: Send + Sync + Debug {
pub trait RouteResponseParser: Send + Sync + Debug {
/// Parses a raw response from the routing backend into a route.
///
/// As we need to assume some sort of type, a sequence of octets is a reasonable interchange
/// format for all known responses so far (JSON, PBF, etc.).
/// We use a sequence of octets as a common interchange format.
/// as this works for all currently conceivable formats (JSON, PBF, etc.).
fn parse_response(&self, response: Vec<u8>) -> Result<Vec<Route>, RoutingResponseParseError>;
}

Expand Down

0 comments on commit 6fe94fa

Please sign in to comment.