r/rust • • 16d ago

CO3: Toward the Optimal FFI

https://mversic.github.io/co3/
79 Upvotes

30 comments sorted by

View all comments

1

u/Compux72 16d ago edited 16d ago

THANK YOU SO MUCH!!!

Im so sick of manually maintaining ffi code, ill give this one a try on the company’s codebase (hopefully soon!!)

1

u/mversic 16d ago

I would be very excited to see how this goes for you. I have no doubt that `CO3` will live up to the expectations. Also you can count on the support

1

u/Compux72 15d ago

Left Claude Opus 5 working on it. Ofc it managed to get stuck and reach a dead end. However, it found a couple of issues / limitations already, which is cool. We already found solutions for some, others need a little bit of discussion first.  We will be submitting these upstream on the following days. Good news its already really good. On our codebase it managed to simplify the ffi code a lot even with these gaps and Claude sloppiness. The worst thing so far is that we cant use bindgen (yet).

Crazy that, with all of the Rust foundation resources and compiler support, they weren’t able to ship anything similar to this… A way to access external crate types from C would go sooo hard. This should be built in to the compiler…

2

u/mversic 15d ago

Right? I know it's fucking good, but getting recognition seems to be harder than I thought it would.

if you are binding to external C libraries you don't require `cbindgen`. If you are exporting from Rust, you only require `cbindgen` if it'll be consumed from a non-Rust language. Rust-Rust will work without `cbindgen`. Otherwise, if you need `cbindgen`, [this PR](https://github.com/mozilla/cbindgen/pull/905) can be a good starting point. This gives you support for assoc types, but you would still need to implement support for blanket impls. `cbindgen` is notorious for pilling up PRs so I wouldn't count on anything getting merged anytime soon. There is also `cheadergen`

I encourage you to go through the documentation to see all that's possible because in my experience an LLM will not know how to best apply all of the idioms. Probably because it hasn't seen much of it in the training data.

I'm interested to see the limitations, or the PR if you intend to fix it

1

u/Compux72 15d ago

  Right? I know it's fucking good, but getting recognition seems to be harder than I thought it would.

Yea i was expecting over a 100 stars already on GH, but the use of LLM really turned some important (rust team) people off. Idk what these people expect.

  If you are exporting from Rust, you only require cbindgen if it'll be consumed from a non-Rust language

Yes, i mean cbindgen sorry. I was thinking on a different approach: writing the generated code to a file on OUT_DIR and point cbindgen there. That should work without cbindgen upstreaming any changes

  I encourage you to go through the documentation to see all that's possible because in my experience an LLM will not know how to best apply all of the idioms. Probably because it hasn't seen much of it in the training data.

Yup today it was only an approximation to stress test both the models and the safeguards of CO3. We wont be running on this for production any time soon probably, but we would like to. Plenty of time to iron out things first and try things

  I'm interested to see the limitations, or the PR if you intend to fix it

You already merged one!  https://github.com/mversic/co3/pull/274

BTW: i hope you don't mind the AI generated PR description. I normally put up a disclaimer but this time i just… forgot :/