c2rust icon indicating copy to clipboard operation
c2rust copied to clipboard

Allow `c2rust transpile` to accept a single C file without a `compile_commands.json`

Open rinon opened this issue 6 years ago • 3 comments

We already support adding compiler flags to a transpiler run, so we can do without compile_commands.json if we're doing a one-off translation of a single file.

rinon avatar Apr 19 '19 21:04 rinon

That would be great. I assumed c2rust command would behave like cc or bindgen and was utterly confused by the errors it reported.

intercept-build command requires Python, which is a major pain.

An example 1-file commands.json in the repo would be very useful, so that I could fudge it to refer to whatever file I need. When migrating projects the first thing I do is moving to build.rs and Rust's cc crate to build my C code, which ironically makes intercept-build unusable. When migrating C projects I always want to migrate them file by file, not the whole thing at once.

kornelski avatar Sep 15 '22 09:09 kornelski

intercept-build command requires Python, which is a major pain.

bear is written in C++ now; you could try that. That's usually what I use.

An example 1-file commands.json in the repo would be very useful, so that I could fudge it to refer to whatever file I need. When migrating projects the first thing I do is moving to build.rs and Rust's cc crate to build my C code, which ironically makes c2rust unusable. When migrating C projects I always want to migrate them file by file, not the whole thing at once.

c2rust allows you to transpile the whole project at once since the semantics should be identical, and then refactor to safe Rust file by file, or whatever granularity you want. That way you don't have to deal with mixing C and Rust at any point, just C-like unsafe and C ABI Rust and idiomatic Rust.

kkysen avatar Sep 15 '22 09:09 kkysen

@kkysen I think this is a very reasonable request. Happy to brainstorm with you or review a PR that lifts the requirement to provide compile_commands.json. We need to make sure that we do not attempt to emit Rust unless all included files were found.

thedataking avatar Sep 15 '22 23:09 thedataking