3 ms·
You don't necessarily need C header files. Rust is able to export symbols easily with the C ABI; if your language has the ability to take a library and call suc
by Manishearth 11y ago
You don't necessarily need C header files. Rust is able to export symbols easily with the C ABI; if your language has the ability to take a library and call such symbols (Python/Ruby do; for example), you're fine. It's only C++ where you need a header file because that's how C++ binds with any library. It's not a Rust-to-any-language issue, header files are a Rust-to-C++ issue only; really, an any-language-to-C++-or-C issue (I think such a tool exists, too).
- dbaupp 11y agoA C header is not needed at runtime, it is purely a way to easily describe the symbols in a library that exist in a (somewhat) type-safe way. It's the lingua franca for describing libraries, and tooling (such as Rust's bindgen, or Python's cffi) can consume them to do the setup/create the information necessary to call functions from other languages. This is much nicer than manually trying to transcribe the Rust (or whatever) signatures into your application. > header files are a Rust-to-C++ issue only Or... C? (And of course other languages too, as just discussed.)
- Manishearth 11y ago> It's the lingua franca for describing libraries, and tooling (such as Rust's bindgen, or Python's cffi) can consume them to do the setup/create the information necessary to call functions from other languages. Hence the "not necessarily" in my comment. The parent seemed to be painting this as extra unnecessary work; I was saying that a header file is _not_ necessary except for binding to C/C++. If you want to write a C API that will be called from many languages; you should have a header file so that bindgen tools can consume it. If you want an API that will only be called by Python .... not so necessary, you may want a header file anyway but it depends on the situation. > Or... C? Sure, goes without saying :)