-
Notifications
You must be signed in to change notification settings - Fork 290
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
have a FFI chapter? #328
Comments
It'd probably take more than a couple snippets to explain how to do FFI without shooting yourself in the foot. I originally started my little guide to help jot down the things I learned while integrating a Rust DLL into a large legacy application at work and (at the time) couldn't find any resources which explain FFI further than a trivial hello world. Off the top of my head here are a couple topics you may want to mention:
I'd be more than happy to help out on this! Just this week I had to revisit that Rust module and ended up rewriting the interface code because the way it did things was quite convoluted and didn't handle errors or cancellation well. |
Thanks! I think that we'll need to decide first if cookbook is a good place for such topic. Or if it is even possible to provide ffi related snippets without all the narrative (ie. avoid making it a loaded footgun). |
Agreed that a comprehensive creating-a-safe-wrapper-around-FFI example might be a bit long. It would be nice if we identified something that was small enough to fit though. Also exposing an API to another language vs using and wrapping a C/C++ library are probably two different cook book entries. The tasks both involve FFI but are different in all other ways. |
When discussing this with @aturon, he came up with ideas of cookbook being companion to RBE and a kind of a signpost to vetted crates ecosystem giving the sense extended standard library. So in this regard a small measure of duplication (as long as we are solving specific real life problems) would still be acceptable. |
I've done a lot of work rewriting chunks of my FFI guide. It's more of an extended tutorial than a collection of self-contained snippets, but what are your thoughts on pointing to something like that given the complexity and large number of footguns commonly associated with FFI? |
@Michael-F-Bryan as you've noted there is a above average density of footguns in ffi problem space and not really yielding to the short self-contained snippets idea. TBH we need to think more about the cookbook inclusion policy and interlinking between the resources I'd love some input on this matter! |
You raise a good point there. We don't want to start pointing to 3rd party resources (mine included!) which aren't up to the high standards we hold for the rest of the Rust project.
If you feel they're relevant then help yourself. Those examples are probably not what you want to include though because they're all examples of UB or footguns, which are then discussed in the "solutions" section. Deliberately incorrect code is probably not something you want to include in the cookbook 😜 |
Ha, serves me right! I've just visually skimmed through the last chapter without reading a single word or a code line :F |
We already have a budding build tools chapter mostly established to showcase build time crates like cc. My feeling is that we could go further with this formula and expand it to (or suplement it with) a full blown chapter dedicated to various rust ffi stories (calling rust, calling from rust, generating bindings).
My main concern is that the ffi stuff might not yeld well to the short snippet problem/solution approach of the cookbook, rather requiring a more narrative driven form (please see few nice ffi guides/tutorials below).
Otherwise it might be a relatively good topic for a standalone book as there is certainly enough material!
Sorry for the pings guys but I wanted to pick your brains on the matter! And I certainly do not want to step on anyone's toes or double the effort.
The text was updated successfully, but these errors were encountered: