rust-cookbook icon indicating copy to clipboard operation
rust-cookbook copied to clipboard

How to pass argc and argv to C FFI ?

Open gnzlbg opened this issue 6 years ago • 6 comments
trafficstars

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.

gnzlbg avatar Dec 10 '18 14:12 gnzlbg

Is there any blog/post on this topic?

lwshang avatar Mar 08 '19 19:03 lwshang

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.

KappaDistributive avatar Apr 16 '19 12:04 KappaDistributive

Isn't there a Rust FFI book somewhere? That might be something worth pursuing instead.

gnzlbg avatar Apr 16 '19 13:04 gnzlbg

@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.

KappaDistributive avatar Apr 16 '19 13:04 KappaDistributive

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).

gnzlbg avatar Apr 16 '19 14:04 gnzlbg

There's the nomicon and The unofficial Rust FFI Guide

AndyGauge avatar Apr 16 '19 15:04 AndyGauge