mirror of
https://github.com/tribufu/tribufu-java
synced 2026-05-06 14:57:27 +00:00
Add Rust Library
This commit is contained in:
parent
362bb7f973
commit
1e18dd4cb2
4 changed files with 66 additions and 0 deletions
2
.cargo/config.toml
Normal file
2
.cargo/config.toml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
[build]
|
||||||
|
target-dir = "Binaries"
|
||||||
18
Cargo.toml
Normal file
18
Cargo.toml
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
[package]
|
||||||
|
name = "TribuFu-jvm"
|
||||||
|
version = "0.0.1"
|
||||||
|
description = "Jvm bindings to TribuFu SDK"
|
||||||
|
repository = "https://github.com/TribuFu/SDK"
|
||||||
|
authors = ["TribuFu <contact@tribufu.com>"]
|
||||||
|
license = "Apache-2.0"
|
||||||
|
edition = "2018"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name="TribuFu_jvm"
|
||||||
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
path = "Source/lib.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
TribuFu_sys = { path = "../DevKit.Rs/Native", package = "TribuFu-sys" }
|
||||||
|
jni = "0.19.0"
|
||||||
43
Source/lib.rs
Normal file
43
Source/lib.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
// Copyright (c) TribuFu. All Rights Reserved
|
||||||
|
|
||||||
|
//! Jvm bindings to TribuFu SDK.
|
||||||
|
|
||||||
|
#![allow(non_snake_case)]
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
#![allow(unused_imports)]
|
||||||
|
|
||||||
|
#[cfg(not(any(
|
||||||
|
target_os = "windows",
|
||||||
|
target_os = "macos",
|
||||||
|
target_os = "linux",
|
||||||
|
target_os = "android",
|
||||||
|
target_os = "ios",
|
||||||
|
target_arch = "wasm32",
|
||||||
|
)))]
|
||||||
|
compile_error!("INVALID_TARGET_PLATFORM");
|
||||||
|
|
||||||
|
use jni::objects::{JClass, JString};
|
||||||
|
use jni::sys::jstring;
|
||||||
|
use jni::JNIEnv;
|
||||||
|
use std::ffi::{CStr, CString};
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
// This is the class that owns our static method. It's not going to be used,
|
||||||
|
// but still must be present to match the expected signature of a static
|
||||||
|
// native method.
|
||||||
|
pub extern "system" fn Java_tribufu_TribuFu_Hello(
|
||||||
|
env: JNIEnv,
|
||||||
|
_: JClass,
|
||||||
|
j_input: JString,
|
||||||
|
) -> jstring {
|
||||||
|
// First, we have to get the string out of Java. Check out the `strings`
|
||||||
|
// module for more info on how this works.
|
||||||
|
let input = CString::from(unsafe { CStr::from_ptr(env.get_string(j_input).unwrap().as_ptr()) });
|
||||||
|
|
||||||
|
// Then we have to create a new Java string to return. Again, more info
|
||||||
|
// in the `strings` module.
|
||||||
|
let res = env.new_string(input.to_str().unwrap()).unwrap();
|
||||||
|
|
||||||
|
// Finally, extract the raw pointer to return.
|
||||||
|
return res.into_inner();
|
||||||
|
}
|
||||||
3
build.rs
Normal file
3
build.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
// Copyright (c) TribuFu. All Rights Reserved
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue