rust-cookbook
rust-cookbook copied to clipboard
How to pass argc and argv to C FFI ?
Many libraries require forwarding them argc and argv from Rust, ideally, without allocating any memory.
I thought this would make for a good "cookbook" example.
Is there any blog/post on this topic?
Right now, there isn't really a chapter on Rust's FFI in the cookbook and I'm wondering whether adding this (and related) examples would overreach the goals of the current treatment of the FFI in the cookbook. I.e. I think, if we decide to pursue this goal, we should create a dedicated chapter on the FFI first.
That being said, in a previous discussion ( #328 ) people seem to have come to the conclusion that an FFI chapter in the cookbook might be an unwise idea as presenting it in the form of a small collection of snippets might ultimately prove to be of disservice to the reader. (The delightful term 'footgun' has come up many times in that discussion.)
I'd be happy to reevaluate whether the cookbook should have an FFI chapter but I also think that, if we decide to include it, we should take the warnings of #328 to heart and have a discussion on how to set it up in a reasonable, responsible way rather than including random snippets and hoping for the best.
Isn't there a Rust FFI book somewhere? That might be something worth pursuing instead.
@gnzlbg There was a chapter about FFI in the old Rust book and it's still mentioned in the new edition. So it might indeed be a good idea to add a chapter about FFI there.
No, I meant a book whose only purpose is to cover how to use Rust FFI features to interface with the rest of the world (e.g. this issue would just be a tiny part of such a book).
There's the nomicon and The unofficial Rust FFI Guide