buttplugio / buttplug-rs-ffi

FFI from buttplug-rs to Java and other languages
Other
88 stars 22 forks source link

Java FFI #63

Closed kitlith closed 3 years ago

kitlith commented 3 years ago

This is completely untested, but it compiles.

unfortunately JNR is poorly documented, but at least we should rarely have to touch this part?

I'm not likely to finish this FFI layer, but at least it's a potential starting point for other people to jump off.

CLAassistant commented 3 years ago

CLA assistant check
All committers have signed the CLA.

kitlith commented 3 years ago

this has been rebased on top of the dev branch, c# ffi failures have nothing to do with me.

kitlith commented 3 years ago

Marked as ready for review, since it's actually started working now.

I still need to add javadocs and similar, as well as set something up with gradle to pull the natives binaries from somewhere, but that latter bit is not just me.

kitlith commented 3 years ago

This is pretty cool. Sorry for the one-off comments/questions. I recently did a project similar to this so I figure I'd do an unsolicited code review. I won't be offended if you ignore my comments.

Your comments are very appreciated, Java is not really my strong suit, and it's nice to get advice from someone else who has done something similar.

One thing that's unclear with this project is how you intend to distribute it and if you intend for the rust toolchain to be required to use this java library. I'm not sure how to add the rust source as a dependency to the gradle stuff (for non android java).

So, I haven't found a good integration between gradle, java, and rust that isn't for android, so I've kinda given up on integrating them directly. Instead, my plan is that once we have builds for multiple platforms of the core library running on CI, we can setup the java library to depend on the artifacts of when running in CI, and otherwise depend on the latest(?) github release (i.e. just download the binaries and be done with it.)

But if you want to add the cdylibs to the java jar, I wrote a post for my day job recently. Given that you've got an FFI crate, you should just ignore all the flapigen stuff and see the gradle build or loading the runtime library.

I did consider actually writing JNI glue in rust like you've done here, but decided not to because I couldn't find a good integration (as i mentioned before) and didn't really want to write my own or hack my own together, especially when having to deal with multiple platforms. So I settled on JNR to handle the C FFI, and then switched to JNA when callbacks weren't working properly (???), and I'm happy with JNA because it handles the loading stuff for me.

kitlith commented 3 years ago

@simlay latest commit more or less handles what i was referring to RE: distributing the cffi objects.

still TODO: in a CI environment, we probably want to use CI artifacts instead of releases.