Dushistov / flapigen-rs

Tool for connecting programs or libraries written in Rust with other languages
BSD 3-Clause "New" or "Revised" License
774 stars 59 forks source link

Project produces only compile errors #454

Open Kofituo opened 9 months ago

Kofituo commented 9 months ago

Hi there, I wanted to try out this project but I'm faced with multiple errors Here's my java_glue.rs.in file

use crate::*;
use jni_sys::*;
foreign_class!(
    class RustLog {
        fn RustLog::initialise_logging(); alias initialiseLogging;
    }
);

lib.rs

mod java_glue;

pub use crate::java_glue::*;

use android_logger::Config;
use log::{Level, LevelFilter};

pub struct RustLog;

impl RustLog {
    //set up logging
    pub fn initialise_logging() {
        #[cfg(target_os = "android")]
        android_logger::init_once(
            Config::default()
                .with_max_level(LevelFilter::Trace)
                .with_tag("Rust"),
        );
        log_panics::init();
        log::error!("Logging initialised from Rust");

    }
}

java_glue.rs file

include!(concat!(env!("OUT_DIR"), "/java_glue.rs"));

Here's the error


error[E0609]: no field `DetachCurrentThread` on type `JNIInvokeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:132:43
    |
132 |                 (**self.callback.java_vm).DetachCurrentThread.unwrap()(self.callback.java_vm)
    |                                           ^^^^^^^^^^^^^^^^^^^ unknown field
    |
help: some of the expressions' fields have a field of the same name
    |
132 |                 (**self.callback.java_vm).reserved.DetachCurrentThread.unwrap()(self.callback.java_vm)
    |                                           +++++++++
132 |                 (**self.callback.java_vm).v1_1.DetachCurrentThread.unwrap()(self.callback.java_vm)
    |                                           +++++
132 |                 (**self.callback.java_vm).v1_2.DetachCurrentThread.unwrap()(self.callback.java_vm)
    |                                           +++++
132 |                 (**self.callback.java_vm).v1_4.DetachCurrentThread.unwrap()(self.callback.java_vm)
    |                                           +++++

error[E0609]: no field `GetJavaVM` on type `JNINativeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:144:36
    |
144 |         let ret = unsafe { (**env).GetJavaVM.unwrap()(env, &mut java_vm) };
    |                                    ^^^^^^^^^ unknown field
    |
    = note: available fields are: `v1_1`, `v1_2`, `v1_4`, `v1_6`, `v9` ... and 2 others

error[E0609]: no field `NewGlobalRef` on type `JNINativeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:146:43
    |
146 |         let global_obj = unsafe { (**env).NewGlobalRef.unwrap()(env, obj) };
    |                                           ^^^^^^^^^^^^ unknown field
    |
help: some of the expressions' fields have a field of the same name
    |
146 |         let global_obj = unsafe { (**env).reserved.NewGlobalRef.unwrap()(env, obj) };
    |                                           +++++++++
146 |         let global_obj = unsafe { (**env).v19.NewGlobalRef.unwrap()(env, obj) };
    |                                           ++++
146 |         let global_obj = unsafe { (**env).v1_1.NewGlobalRef.unwrap()(env, obj) };
    |                                           +++++
146 |         let global_obj = unsafe { (**env).v1_2.NewGlobalRef.unwrap()(env, obj) };
    |                                           +++++
      and 3 other candidates

error[E0609]: no field `GetEnv` on type `JNIInvokeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:158:30
    |
158 |             (**self.java_vm).GetEnv.unwrap()(
    |                              ^^^^^^ unknown field
    |
help: some of the expressions' fields have a field of the same name
    |
158 |             (**self.java_vm).reserved.GetEnv.unwrap()(
    |                              +++++++++
158 |             (**self.java_vm).v1_2.GetEnv.unwrap()(
    |                              +++++
158 |             (**self.java_vm).v1_4.GetEnv.unwrap()(
    |                              +++++

error[E0609]: no field `AttachCurrentThread` on type `JNIInvokeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:188:30
    |
188 |             (**self.java_vm).AttachCurrentThread.unwrap()(
    |                              ^^^^^^^^^^^^^^^^^^^ unknown field
    |
help: some of the expressions' fields have a field of the same name
    |
188 |             (**self.java_vm).reserved.AttachCurrentThread.unwrap()(
    |                              +++++++++
188 |             (**self.java_vm).v1_1.AttachCurrentThread.unwrap()(
    |                              +++++
188 |             (**self.java_vm).v1_2.AttachCurrentThread.unwrap()(
    |                              +++++
188 |             (**self.java_vm).v1_4.AttachCurrentThread.unwrap()(
    |                              +++++

error[E0609]: no field `DeleteGlobalRef` on type `JNINativeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:220:30
    |
220 |             unsafe { (**env).DeleteGlobalRef.unwrap()(env, self.this) };
    |                              ^^^^^^^^^^^^^^^ unknown field
    |
help: some of the expressions' fields have a field of the same name
    |
220 |             unsafe { (**env).reserved.DeleteGlobalRef.unwrap()(env, self.this) };
    |                              +++++++++
220 |             unsafe { (**env).v19.DeleteGlobalRef.unwrap()(env, self.this) };
    |                              ++++
220 |             unsafe { (**env).v1_1.DeleteGlobalRef.unwrap()(env, self.this) };
    |                              +++++
220 |             unsafe { (**env).v1_2.DeleteGlobalRef.unwrap()(env, self.this) };
    |                              +++++
      and 3 other candidates

error[E0609]: no field `ThrowNew` on type `JNINativeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:229:32
    |
229 |     let res = unsafe { (**env).ThrowNew.unwrap()(env, ex_class, c_message.as_ptr()) };
    |                                ^^^^^^^^ unknown field
    |
help: some of the expressions' fields have a field of the same name
    |
229 |     let res = unsafe { (**env).reserved.ThrowNew.unwrap()(env, ex_class, c_message.as_ptr()) };
    |                                +++++++++
229 |     let res = unsafe { (**env).v19.ThrowNew.unwrap()(env, ex_class, c_message.as_ptr()) };
    |                                ++++
229 |     let res = unsafe { (**env).v1_1.ThrowNew.unwrap()(env, ex_class, c_message.as_ptr()) };
    |                                +++++
229 |     let res = unsafe { (**env).v1_2.ThrowNew.unwrap()(env, ex_class, c_message.as_ptr()) };
    |                                +++++
      and 3 other candidates

error[E0609]: no field `AllocObject` on type `JNINativeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:249:42
    |
249 |     let jobj: jobject = unsafe { (**env).AllocObject.unwrap()(env, jcls) };
    |                                          ^^^^^^^^^^^ unknown field
    |
help: some of the expressions' fields have a field of the same name
    |
249 |     let jobj: jobject = unsafe { (**env).reserved.AllocObject.unwrap()(env, jcls) };
    |                                          +++++++++
249 |     let jobj: jobject = unsafe { (**env).v19.AllocObject.unwrap()(env, jcls) };
    |                                          ++++
249 |     let jobj: jobject = unsafe { (**env).v1_1.AllocObject.unwrap()(env, jcls) };
    |                                          +++++
249 |     let jobj: jobject = unsafe { (**env).v1_2.AllocObject.unwrap()(env, jcls) };
    |                                          +++++
      and 3 other candidates

error[E0609]: no field `SetLongField` on type `JNINativeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:253:17
    |
253 |         (**env).SetLongField.unwrap()(env, jobj, field_id, ret);
    |                 ^^^^^^^^^^^^ unknown field
    |
help: one of the expressions' fields has a field of the same name
    |
253 |         (**env).v1_1.SetLongField.unwrap()(env, jobj, field_id, ret);
    |                 +++++

error[E0609]: no field `ExceptionCheck` on type `JNINativeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:254:20
    |
254 |         if (**env).ExceptionCheck.unwrap()(env) != 0 {
    |                    ^^^^^^^^^^^^^^ unknown field
    |
    = note: available fields are: `v1_1`, `v1_2`, `v1_4`, `v1_6`, `v9` ... and 2 others

error[E0609]: no field `GetArrayLength` on type `JNINativeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:267:35
    |
267 |     let length = unsafe { (**env).GetArrayLength.unwrap()(env, arr.inner) };
    |                                   ^^^^^^^^^^^^^^ unknown field
    |
    = note: available fields are: `v1_1`, `v1_2`, `v1_4`, `v1_6`, `v9` ... and 2 others

error[E0609]: no field `GetObjectArrayElement` on type `JNINativeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:273:31
    |
273 |             let obj = (**env).GetObjectArrayElement.unwrap()(env, arr.inner, i);
    |                               ^^^^^^^^^^^^^^^^^^^^^ unknown field
    |
    = note: available fields are: `v1_1`, `v1_2`, `v1_4`, `v1_6`, `v9` ... and 2 others

error[E0609]: no field `ExceptionCheck` on type `JNINativeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:274:24
    |
274 |             if (**env).ExceptionCheck.unwrap()(env) != 0 {
    |                        ^^^^^^^^^^^^^^ unknown field
    |
    = note: available fields are: `v1_1`, `v1_2`, `v1_4`, `v1_6`, `v9` ... and 2 others

error[E0609]: no field `GetLongField` on type `JNINativeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:277:31
    |
277 |             let ptr = (**env).GetLongField.unwrap()(env, obj, field_id);
    |                               ^^^^^^^^^^^^ unknown field
    |
help: some of the expressions' fields have a field of the same name
    |
277 |             let ptr = (**env).v19.GetLongField.unwrap()(env, obj, field_id);
    |                               ++++
277 |             let ptr = (**env).v1_1.GetLongField.unwrap()(env, obj, field_id);
    |                               +++++
277 |             let ptr = (**env).v1_2.GetLongField.unwrap()(env, obj, field_id);
    |                               +++++
277 |             let ptr = (**env).v1_4.GetLongField.unwrap()(env, obj, field_id);
    |                               +++++
      and 2 other candidates

error[E0609]: no field `DeleteLocalRef` on type `JNINativeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:279:21
    |
279 |             (**env).DeleteLocalRef.unwrap()(env, obj);
    |                     ^^^^^^^^^^^^^^ unknown field
    |
help: some of the expressions' fields have a field of the same name
    |
279 |             (**env).reserved.DeleteLocalRef.unwrap()(env, obj);
    |                     +++++++++
279 |             (**env).v19.DeleteLocalRef.unwrap()(env, obj);
    |                     ++++
279 |             (**env).v1_1.DeleteLocalRef.unwrap()(env, obj);
    |                     +++++
279 |             (**env).v1_2.DeleteLocalRef.unwrap()(env, obj);
    |                     +++++
      and 3 other candidates

error[E0609]: no field `NewObjectArray` on type `JNINativeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:296:26
    |
296 |         unsafe { (**env).NewObjectArray.unwrap()(env, arr_len, jcls, ::std::ptr::null_mut()) };
    |                          ^^^^^^^^^^^^^^ unknown field
    |
    = note: available fields are: `v1_1`, `v1_2`, `v1_4`, `v1_6`, `v9` ... and 2 others

error[E0609]: no field `AllocObject` on type `JNINativeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:301:46
    |
301 |         let jobj: jobject = unsafe { (**env).AllocObject.unwrap()(env, jcls) };
    |                                              ^^^^^^^^^^^ unknown field
    |
help: some of the expressions' fields have a field of the same name
    |
301 |         let jobj: jobject = unsafe { (**env).reserved.AllocObject.unwrap()(env, jcls) };
    |                                              +++++++++
301 |         let jobj: jobject = unsafe { (**env).v19.AllocObject.unwrap()(env, jcls) };
    |                                              ++++
301 |         let jobj: jobject = unsafe { (**env).v1_1.AllocObject.unwrap()(env, jcls) };
    |                                              +++++
301 |         let jobj: jobject = unsafe { (**env).v1_2.AllocObject.unwrap()(env, jcls) };
    |                                              +++++
      and 3 other candidates

error[E0609]: no field `SetLongField` on type `JNINativeInterface_`
   --> /Users/kofiotuo/IdeaProjects/RustApplication/rust_lib/target/aarch64-linux-android/debug/build/rust_lib-5b22bb56ef553d34/out/java_glue.rs:305:21
    |
305 |             (**env).SetLongField.unwrap()(env, jobj, field_id, r_obj);
    |                     ^^^^^^^^^^^^ unknown field
    |
help: one of the expressions' fields has a field of the same name
    |
305 |             (**env).v1_1.SetLongField.unwrap()(env, jobj, field_id, r_obj);
    |                     +++++

-- etc --
lefuturiste commented 7 months ago

I encounter the same problem. @Kofituo is this problem specific to the newer versions of the flapigen-rs lib?

lefuturiste commented 7 months ago

I encounter the same problem. @Kofituo is this problem specific to the newer versions of the flapigen-rs lib?

Okay I managed to make it work with rifgen = "0.1", flapigen = "0.6.0-pre9" , jni-sys = "0.3"

Dushistov commented 7 months ago

I think this is related to jni-sys breaking change described in #450 . The "JavaVM" was converted to union, so it becomes not compatitable with bindgen generated binding for jni.h C header file.

martinellison commented 3 months ago

You need to force jni-sys to version 0.3.0, not to the latest version, in your Cargo.toml.