Giter VIP home page Giter VIP logo

flapigen-rs's People

Contributors

adamrzepka avatar arrtchiu avatar coltfred avatar dushistov avatar he-la avatar ijc avatar jasperdesutter avatar joycebabu avatar kofituo avatar mpoel avatar peterw-lwl avatar rossdimassimo avatar rubdos avatar simlay avatar skeet70 avatar stephan57160 avatar xiretza avatar yuhanliin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flapigen-rs's Issues

Support for C#

I see future combining rust_swig and .net to use it in Xamarin and other .net platforms. I want to now if there is any support for that.

Foreigner class calling into Rust-generic methods

(I am using Java, but I think this might apply to C++ as well)

Assume we have a struct with impl:

struct A;
impl A {
    fn foo<B>(b: B) {
        /* no-op */
    }
    fn bar<B>() {
        /* no-op */
    }
}

We can trivially export foo to Java if we instantiate and alias the method, but there's no way to export bar:

foreigner_class! ( class A {
    method A::foo<A>(b: A); alias fooA; //works
    method A::bar<A>(); // does not work,
});

Note that the generated code looks like

...
let mut ret: () = A::foo(a_0);
...
let mut ret: () = A::bar();

This means that, even if I "instantiate" the generic in the foreigner_class! macro invocation, I cannot export A::bar, even for concrete known types.


To conclude: is it possible and sound to use the supplied generic parameters in the foreigner_class! invocation in the generated code? If so, can it be done?

Thanks!

[u8] slices to Java?

I see that [i8] maps to a JavaByteArray, but [u8] slices don't seem implemented. Is there a way to implement this?

Optimize work with JNI

  1. Hold JNIEnv produced by AttachCurrentThread in thread local storage
  2. Cache FindClass, GetFieldId etc in thread local storage or may be in lazy_static ?

add basic c++ support

To check how architecture ready to add new langauges support,
we need something simple, like c++ basic support

c++: get ruststr -> set rust str

Simplify usage of code like this:

//rust
foreigner_class!(class Foo {
    self_type Foo;
   method get_str(&self) -> &str;
   method set_str(&self, _: &str);

in c++ you need convert get_str output to std::string and then pass std::string::c_str result to set_str, because of &str interpreted as char * on C side.

more convinient Class/ClassRef and foreign_code cooperation in c++ backend

With current versoin if you add code like this:

foreigner_class!(class Uuid {
    self_type Uuid;
    private constructor uuid_private_constructor() -> Uuid;
    static_method Uuid::new_v4() -> Uuid;
    method Uuid::eq(&self, _: &Uuid) -> bool;
    method Uuid::clone(&self) -> Uuid;
    foreigner_code r#"
public:
    bool operator==(const Uuid &o) const
    {
        return this->eq(o);
    }
"#;
});

you can only use Uuid == Uuid operation, not UuidRef == UuidRef.

`build.rs` as a library

rust_swig is designed to be used from cargo build scripts. Just copy an appropriate code from examples crates: general java, android/java, c++ and add rust_swig as [build-dependencies] into your Cargo.toml.

I don't really like the idea of copy-pasting 250 lines of code. Would it be interesting to, for example, have gen_for_android() inside the rust_swig library? I think it would be nice to have a (initially opinionated) "default" implementation that can simply be called.

Possibly move jni headers into a shared crate?

Hi!

I'm really liking the library so far, rust_swig has been working quite well.

There was one thing I was wondering about though, and that's the possibility of having the jni_c_header types and SwigInto / SwigFrom shared between multiple crates which use rust_swig.

Right now if I want to split up bindings into multiple crates that depend on eachother, there will be duplicated code and/or incompatibilities depending on what I'm doing.

Would it be reasonable to instead have all "shared" things into a swig or swig_types crate that would be depended upon by projects using rust_swig?

It would have to be a separate crate from the crate providing swig macros, but this is a convention that's done by many other crates, such as serde for shared serialization/deserialization types, and the serde_derive for a compiler plugin for automatically implementing those types.

If it's possible, I'd also think having jni_c_headers as part of a separate crate would reduce the complexity of the build script, and of project setup - it would remove the need for every project using rust_swig to declare a mod jni_c_headers containing the exact same boilerplate.

On the other hand, I'm also very new to using rust_swig, so there might be reasons why this isn't feasible, or not useful at all. If you have the time to elaborate, I would definitely like to hear what you think about this.

Thank you for making the project, I hope you find this useful.

class has methods, but no constructor

error: namespace rust, class XYZ: has methods but no constructor

In this case, this is what I actually want to have happen - make it so the Rust code can create a class, but not the C++ code. Is this disabled because it's impossible, or is there some way to allow this?

Fix passing objects of foreign_class by reference/value

Example of code:

foreigner_class!(class Foo {
    self_type Foo;
    constructor Foo::new(_: i32, _: &str) -> Foo;
    method Foo::f(&self, _: i32, _: i32) -> i32;  alias calcF;
});

foreigner_class!(class TestPassObjectsAsValue {
    self_type TestPassObjectsAsValue;
    constructor TestPassObjectsAsValue::default() -> TestPassObjectsAsValue;
    method TestPassObjectsAsValue::f1(&self, _: &Foo);
});

Instructions are incomplete

Hi,
First of all, thanks for writing this crate. It's quite ambitious.

I was trying to get this working with a project at work, and was running into a series of issues.

First, the instructions don't specify that you need to set up a build script. I started out using the one from the C++ tests folder.

Second, there's a lot of issues I encountered with cargo hanging when I had Sublime open (running RLS, linter, ...). This might be a separate issue.

Third, even after closing Sublime and creating the build script, and reconfiguring lib.rs to lib.rs.in, I still can't get it to build as it seems to be looking for rust_str.h

error: Can not put/generate foreign lang helpers: update of c++\rust_interface\rust_str.h failed: the system cannot find the path specified. (os error 3)

I'm not sure what the proper way is to get past this error. It looks like I might be able to just copy the file over, but that seems rather inelegant and undesirable as my local copy would eventually fall out of sync with the library copy...

Thanks!

"not yet implemented" for ToString

foreign_interface!(interface ToString {
    self_type std::string::ToString;
    toString = std::string::ToString::to_string(&self) -> String;
});
thread 'main' panicked at 'not yet implemented', C:\users\spease\.cargo\registry\src\github.com-1ecc6299db9ec823\rust_swig-0.1.3\src\cpp\mod.rs:1303:18

Am I doing something wrong, or is this legitimately not possible? Thanks.

solve caching and cargo+sccache issue

Check how to write code generation rules,
that works for such cases:

  1. Removing generated code (java or rust) -> rebuild
  2. Changing dependency of build.rs -> rebuild

other issues related to rebuild with cargo + sccache.

Support Option as value of Result?

I assumed the generation here worked for any supported value type, but checking out the code, it seems to be handled case by case. Is there a reason Option is not supported? As a workaround, I think I can use a better error type and have missing data be one error case.

error: Do not know conversation from such rust type 'Result<Option, String>' to foreign

"static" methods in interface/trait

suppose

trait Foo {
    fn bar() where Self: Sized;
}

foreign_interface! (interface FooBar {
    self_type Foo;
    bar = Foo::bar();
})

This crashes at compile time:

at macroslib/src/java_jni/mod.rs:218:

thread 'main' panicked at 'attempt to subtract with overflow', /home/rsmet/.cargo/registry/src/github.com-1ecc6299db9ec823/rust_swig-0.1.5/src/java_jni/mod.rs:215:67

I gave the code a quick look, and it seems to assume no "static" (is that the Rusty term?) trait methods.

They currently don't make too much sense to bind to Java though, since we can only pass them through Boxes (instead of genericly/impl Trait), but it might make sense in the future.

How to generate headers?

It isn't made clear how you're supposed to get headers for the classes being generated with SWIG. Thanks.

c++ callback mechanizm (foreign_interface!) doesn't handle properly input foreign classes

Should be const UuidRef &, instead of const UuidOpaque * in generated C++ code

#[test]
fn test_foreign_interface_cpp() {
        let gen_code = parse_code(
            "test_foreign_interface_cpp",
            r#"
foreigner_class!(class Uuid {
    self_type Uuid;
    private constructor uuid_private_constructor() -> Uuid;
    static_method Uuid::new_v4() -> Uuid;
});

foreign_interface!(interface RepoChangedCallback {
    self_type RepoChangedCallback;
    on_save = RepoChangedCallback::on_save(&self, uuid: &Uuid);
    on_remove = RepoChangedCallback::on_remove(&self, uuid: &Uuid);
});
"#,
            &[ForeignLang::Cpp],
        );
        let cpp_code_pair = gen_code
            .iter()
            .find(|x| x.lang == ForeignLang::Cpp)
            .unwrap();
        println!("c/c++: {}", cpp_code_pair.foreign_code);
        cpp_code_pair
            .foreign_code
            .contains("virtual void on_save(const UuidOpaque * a_0) = 0;");
        cpp_code_pair
            .foreign_code
            .contains("virtual void on_remove(const UuidOpaque * a_0) = 0;");
}

Thread-safe callbacks

I would like to implement an interface in Java that can be send to Rust in a thread safe way: I basically want to guarantee Send on the sent object Box<MyTraitInterface + Send>. Is this somehow possible?

Mind that it's late on my day and my brain is getting laggy. I have no idea whether it's somehow possible to do.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.