Hi, I want to simplify writing Java binding for Rust. Basically I need do such thing by hands:
Input: mod my_module { pub fn foo(a: i32) -> i32 { a + 1 } }
Output:
//rust code
use my_module::foo;
#[no_mangle]
fn Java_package_name_Class_foo(_: *mut JNIEnv, _: jclass, a: jint) -> jint { foo(a) }
//java code
package package_name;
public final class Class {
public static native int foo(int a);
}
I want to automate this, and imagine such API after reading syntex docs:
java_class!(classname Class {
pub static_method my_module::foo,
});
More general:
java_class!(class Class {
constructor my_module::Foo::new,
pub method my_module::Foo::f1,
pub static_method my_module::f2,
method my_module::Foo::f3,
static_method my_module::f4,
});
How it should works:
-
I add such
java_class!calls to jni_wrapper.rs.in, then use analog of nightly pluginsregister_macroin syntex and via this hook get full names of functions/methods -
After get full names I parse whole crates with code similar to rusty-binder (it also uses syntex under the hood)
and find out signature of all functions/methods or report error if I can not find one. -
I got all what I want and can generate java code and jni_wrapper.rs with "Java_"
functions.
Questions:
Do you have any doubts in plan realization?
Is syntex support register_macro and can parse such macro?
Is any problems to get full name in syntex (for example with clang and parsing of c++
some time ago was problem to get from class Foo token full name like namespace1::namespace2::Foo)?