Skip to content

Commit

Permalink
Re-export jni from within jnat
Browse files Browse the repository at this point in the history
Fixes some test harness build issues (works on my machine, but apparently not others?), and it's more future-proof
  • Loading branch information
shreyasm-dev committed Jul 24, 2023
1 parent 388e302 commit e361a36
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jnat"
version = "0.1.2"
version = "0.2.0"
edition = "2021"
license = "MIT"
description = "A wrapper around the jni crate"
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Create a new Cargo lib project with `cargo new --lib mylib` and add the followin
```toml
[dependencies]
jnat = [latest version]
jni = [latest version]

[lib]
crate-type = ["cdylib"]
Expand All @@ -18,10 +17,9 @@ crate-type = ["cdylib"]
Add the following to `src/lib.rs`:

```rust
use jni::{objects::JClass, JNIEnv};

use jnat::{
env::{Class, Env},
jni::{objects::JClass, JNIEnv}, // jni crate, re-exported by jnat
signature::{Signature, Type},
};

Expand Down
27 changes: 7 additions & 20 deletions integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ fn teardown() {}
fn main() {
setup();

let mut libjni: Option<String> = None;
let mut libjnat: Option<String> = None;

let paths = read_dir(Path::new("../../target/debug/deps")).expect("Failed to read directory");
Expand All @@ -66,27 +65,17 @@ fn main() {
.to_str()
.expect("Failed to convert filename to string");

if filename.ends_with("rlib") {
if filename.starts_with("libjni") {
libjni = Some(
path
.to_str()
.expect("Failed to convert path to string")
.to_string(),
);
} else if filename.starts_with("libjnat") {
libjnat = Some(
path
.to_str()
.expect("Failed to convert path to string")
.to_string(),
);
}
if filename.starts_with("libjnat") && filename.ends_with("rlib") {
libjnat = Some(
path
.to_str()
.expect("Failed to convert path to string")
.to_string(),
);
}
}
}

let libjni = libjni.expect("Failed to find libjni rlib");
let libjnat = libjnat.expect("Failed to find libjnat rlib");

for t in inventory::iter::<IntegrationTest> {
Expand All @@ -101,8 +90,6 @@ fn main() {
.arg("-L")
.arg("dependency=../../target/debug/deps")
.arg("--extern")
.arg(format!("jni={}", libjni))
.arg("--extern")
.arg(format!("jnat={}", libjnat))
.arg(format!("../tests/lib/{}.rs", t.lib))
.output()
Expand Down
6 changes: 2 additions & 4 deletions integration/tests/lib/call_static_method.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
extern crate jnat;
extern crate jni;

use jni::{objects::JClass, JNIEnv};

use jnat::{
env::{Class, Env},
env::Env,
jni::{objects::JClass, JNIEnv},
signature::{Signature, Type},
};

Expand Down
9 changes: 2 additions & 7 deletions integration/tests/lib/hello.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
extern crate jni;
extern crate jnat;

use jni::{
use jnat::jni::{
objects::{JClass, JString},
sys::jstring,
JNIEnv,
};

// use jnat::Env;

#[no_mangle]
pub extern "system" fn Java_Hello_hello(mut env: JNIEnv, _: JClass, name: JString) -> jstring {
let name: String = env.get_string(&name).expect("Failed to get name").into();

let output = env
.new_string(format!("Hello, {}!", name))
.unwrap();
let output = env.new_string(format!("Hello, {}!", name)).unwrap();

output.into_raw()
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub mod env;
pub mod signature;

pub use jni;

0 comments on commit e361a36

Please sign in to comment.