This repository has been archived by the owner on Oct 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Siyun Wu
committed
Nov 27, 2021
1 parent
7f0c9e2
commit 84e9ba0
Showing
16 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' // required for aar generation to link to from AnkiDroid | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.1" | ||
ndkVersion "22.1.7171670" // Used by GitHub actions - avoids an install step on some machines | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
defaultConfig { | ||
minSdkVersion 21 | ||
targetSdkVersion 30 | ||
versionCode 1 | ||
versionName VERSION_NAME | ||
|
||
consumerProguardFiles "consumer-rules.pro" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
// Consider upgrade to DSL: https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block | ||
apply plugin: "org.mozilla.rust-android-gradle.rust-android" | ||
|
||
cargo { | ||
module = "../rslib-bridge" | ||
libname = "rsdroid" | ||
targets = ["x86", "arm", "arm64"] | ||
profile = 'release' | ||
prebuiltToolchains = true | ||
apiLevel = 21 | ||
verbose = true | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: "libs", include: ["*.jar", '*.so']) | ||
implementation 'androidx.appcompat:appcompat:1.3.1' | ||
implementation "androidx.core:core-ktx:+" | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.31" | ||
} | ||
|
||
preBuild.dependsOn "cargoBuild" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VERSION_NAME=0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.linkedin.android.rsdroid"> | ||
|
||
|
||
</manifest> |
20 changes: 20 additions & 0 deletions
20
rsdroid/src/main/java/com/linkedin/android/rsdroid/RustCore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.linkedin.android.rsdroid; | ||
|
||
class RustCore { | ||
|
||
external fun greeting(): String | ||
external fun callback(cb : Callback) | ||
init { | ||
System.loadLibrary("rsdroid") | ||
} | ||
|
||
companion object { | ||
val instance: RustCore = RustCore() | ||
} | ||
|
||
|
||
interface Callback { | ||
fun onSuccess() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Cargo.lock | ||
target/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# cargo-features = ["strip"] | ||
|
||
[package] | ||
name = "rsdroid" | ||
version = "0.1.0" | ||
authors = ["David Allison <[email protected]>"] | ||
edition = "2018" | ||
|
||
[lib] | ||
crate_type = ["dylib"] | ||
|
||
[dependencies] | ||
jni = { version = "0.17.0", default-features = false } | ||
# picked bundled - TODO: Is this correct? | ||
rusqlite = { version = "0.23.1", features = ["trace", "functions", "collation", "bundled"] } | ||
|
||
[features] | ||
no-android = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
backend_proto.rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#[macro_use] | ||
extern crate jni; | ||
use jni::JNIEnv; | ||
use jni::objects::{JClass, JString, JObject}; | ||
use jni::sys::{jbyteArray, jint, jlong, jobjectArray, jarray, jstring}; | ||
use std::ffi::CString; | ||
|
||
#[no_mangle] | ||
pub unsafe extern fn Java_com_linkedin_android_rsdroid_RustCore_greeting(env: JNIEnv, _: JClass) -> jstring { | ||
let world_ptr = CString::new("Hello world from Rust world").unwrap(); | ||
let output = env.new_string(world_ptr.to_str().unwrap()).expect("Couldn't create java string!"); | ||
output.into_inner() | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern fn Java_com_linkedin_android_rsdroid_RustCore_callback( | ||
env: JNIEnv, | ||
_class: JClass, | ||
callback: JObject, | ||
) { | ||
env.call_method(callback, "onSuccess", "()V", &[]) | ||
.unwrap(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ dependencyResolutionManagement { | |
} | ||
} | ||
rootProject.name = "KotinRustProto" | ||
include ':rsdroid' | ||
include ':app' |