immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
3.95k stars 234 forks source link

Lack of support for simple projects or the cc crate #1033

Closed kornelski closed 10 months ago

kornelski commented 11 months ago

I find the the requirement to use compile_commands.json incredibly annoying, because it never fits the types of projects I want to convert to Rust, and also requires use of clunky 3rd party non-Rust dependencies and non-Rust build systems.

It so happens that all C code that I dare to port to Rust is small — only a handful of .c files, sometimes literally just a single .c file or a header-only dependency. And for such trivial code I use the cc crate, not something complicated like meson.

If a project is too hard to build with the cc crate, I consider it also too big and complex to convert to Rust. So I'm frustrated that c2rust only supports the types of projects I don't want to convert. When I want to convert literally a single .c file that has zero dependencies and compiles with gcc *.c without issues, I have to jump through so many hoops. I need to re-learn how to use cmake, and I need to deal with series of issues in installing the right version of python, and installing its dependencies, and venvs and whatever else it requires. All of that to pass a single file path to c2rust.

Please, support c2rust *.c.

fish4terrisa-MSDSM commented 11 months ago

Have ever tried bear to generate the compile_commands.json on your project? Maybe you can just use bear -- clang ${PUT_YOUR_ARGS_HERE} ? or you may write a Makefile and run bear -- make instead?

thedataking commented 11 months ago

@kornelski can you let us know whether bear would solve your issue?

If not, I suppose we could make c2rust transpile work in single file mode without a compile_commands.json.

kornelski commented 11 months ago

I'd be happy if it transpiled file(s) directly specified on the command line, without the JSON build indirection. Like bindgen, for example.