4 ms·
Not saying it isn’t neat, but WHY? Seems like the kind of thing that happens before a language is natively supported by a compiler.
by BobbyTables2 11mo ago
Not saying it isn’t neat, but WHY?
Seems like the kind of thing that happens before a language is natively supported by a compiler.
- viraptor 11mo agoIf only the article started with an explanation...
- thrance 11mo agoThere's literally a section named "Why?" in the article.
- procaryote 11mo agoThey want to use rust but can't, because they need C compatibility, e.g. because they're providing a library or wants to support platforms that rust don't. It's at least a less bad idea than I expected originally – I've mainly seen people try to use transpilers to sneakily start using the language they prefer as part of a larger code base, with all the obvious problems. It's still not great as you now have an additional translation step to deal with. You will at some point need to look for bugs in the generated C layer, which will really suck. Users of the C library can't read your source to understand what it does internally without an extra step to figure out what rust code the thing they use corresponds to, etc. If you want to provide a C library, write C. If rust isn't an option because it doesn't work for your customers who use C, don't use rust.
- zozbot234 11mo agoYou can write a C-compatible binary library in Rust (see the cdylib target) and cbindgen can then generate proper C header files for any C-ABI interfaces exposed in Rust code. A full Rust-to-C compiler should only be needed for targets that have some C compiler available but are just not supported by the current Rust toolchain.
- flohofwoe 11mo agoIf you have an existing build system for your C project, you sure as hell don't want to bring another compiler toolchain (like Rust) into the mix.
- zozbot234 11mo agoYou'd need the Rust compiler toolchain anyway, just to do the Rust-to-C conversion step instead of compiling to a binary library? What would be the point? The C ABI is quite compatible across toolchains.
- flohofwoe 11mo ago> You'd need the Rust compiler toolchain anyway, just to do the Rust-to-C conversion step instead of compiling to a binary library? The Rust-to-C conversion would be done by the Rust library author (or more likely, some automated CI process) to create a C source code distribution of the Rust library.
- drwu 11mo agoRust compiler can be easily bootstrapped.