Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Experiment: Safe FFI for Rust ↔ C++ #7

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Michael-F-Bryan
Copy link
Owner

@Michael-F-Bryan Michael-F-Bryan commented Jan 13, 2020

@Michael-F-Bryan
Copy link
Owner Author

@dtolnay I was thinking of doing a write-up on cxx and would be keen to get your input!

I've started wrapping the bz2 library (because that's the example the bindgen tutorial uses) but realised wrapping a C library doesn't really show off the library... Are there any relatively simple real-world C++ libraries you've been using during testing?

@Michael-F-Bryan Michael-F-Bryan changed the title Experiment: Safe FFI for Rust ↔ C++ WIP: Experiment: Safe FFI for Rust ↔ C++ Jan 13, 2020
@dtolnay
Copy link

dtolnay commented Jan 13, 2020

FFI with C++ is very different from FFI with C so I would flag that C FFI use cases shouldn't be expected to translate well, as you noticed.

The real world use cases I have been experimenting with are Proxygen's server API and Thrift's client API. https://michael-f-bryan.github.io/rust-ffi-guide/basic_request.html + https://michael-f-bryan.github.io/rust-ffi-guide/send_basic.html looks pretty close as a simplified form of the same thing.

@Michael-F-Bryan
Copy link
Owner Author

Note to self: I think I'll give up on writing bindings for libtorrent and look for something which builds more reliably (maybe llvm?)

I spent a good 2 evenings trying to get it to build reliably using build.rs and still haven't been able to link correctly 😞 The annoyance was that their default builds generate dynamic libraries, but I want static libraries because I don't want the hassle of distributing *.so... When a recompile takes 5-10 minutes using all cores (and locking up my laptop in the process) or 30+ minutes, it's kinda hard to iteratively test new cmake incantations manually then replicate them in build.rs to see if the changes work.

I was hoping I'd be able to use this to show off how annoying getting a native library to compile and link can be, and the tricks you can use while troubleshooting, but that doesn't really work when there's no happy ending... So I'm going to throw this into the too hard basket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants