Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a tool for generating C headers from Rust modules? [closed]

Tags:

rust

If you write a Rust library and you want to call it from C, you have to mark all the export functions with extern C and make sure everything uses the C ABI. But then you also have to write a header file by hand to include in your C code, and manually ensure that it is consistent with the Rust definitions, or Bad Things will happen. This seems both dangerous and tedious.

Is there a tool for generating C headers from Rust code? I've seen bindings that go the other way, for using C from Rust, and that's actually a harder problem!

like image 605
Michael Day Avatar asked Oct 30 '14 03:10

Michael Day


3 Answers

A more recent way to do this is https://github.com/eqrion/cbindgen/, which seems to be actively maintained at the time of writing. The accepted answer from @hcs links to a GitHub issue that says that this should be tackled by an external tool.

like image 196
Hameer Abbasi Avatar answered Nov 14 '22 09:11

Hameer Abbasi


It looks like this is a requested feature for Rust, but I haven't found any implementations.


UPDATE:

As @HameerAbbasi notes below, cbindgen is the preferred tool for doing this now.

like image 26
hcs Avatar answered Nov 14 '22 09:11

hcs


It needs to be used so that I can iron out the kinks, but yes.

like image 37
Sean1708 Avatar answered Nov 14 '22 08:11

Sean1708