crust
crust copied to clipboard
Can I convert an entire folder of C/C++ files to Rust?
I've been looking at C2Rust a lot, I love that this one can handle C++ as well!! And that's it's written in Rust itself, meaning I don't have to download 3 or 4 external softwares so that C2Rust can use LLVM to do the actual conversion, and it doesn't even work on Windows. Seems like this one might also preserve comments. Awesome!! Don't have to mention,therefore advertising, C2Rust but please stress some of these things in your ReadMe.md
Anyway, one big issue I see those is that conversion has to be done on a file by file basis. Would be really nice and seems relatively easy to modify it to allow calling converting all c or cpp (and h) files in one folder to another folder recursively going through multiple levels and recreating those subfolders in the new folder.
One other thing to point out, C2Rust will transpile header declarations from any headers that are included so that the user can link the resulting Rust code against the same set of shared libraries as the C code did. Would be a nice feature to include.
Thanks for all the hard work!! Love this project and can't wait to play with it!!
thanks for the comments @mczarnek , due to busy schedule I'm unable to address few of the issues in current implementation, but feel free to make changes and send PR.
You can do this easily on linux using find
:
find (source folder) -type f -name "*.c" -o -name "*.h" -o -name "*.cpp" -exec ./target/release/crust {} -p (your project name) -s \;
etc
Hm, the find
option doesn't seem to work...
Input file size : 6477bytes
thread 'main' panicked at 'index out of bounds: the len is 9 but the index is 9', /private/tmp/rust-20200509-70766-vc2112/rustc-1.43.1-src/src/libcore/slice/mod.rs:2842:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
TokenizingInvoking Parser ....Input file size : 4231bytes
That's a bug with the tokenizer, not with find
. You may want to try the other CPP to Rust converter: https://github.com/immunant/c2rust
Thanks, but that one seems to only support c, not cpp.
It uses the libclang backend, so it should support both C and C++ flawlessly. Give it a try!
Unfortunately c2rust doesn't support modern rust versions as I have to use a version from 2019 😢
That's a bug with the tokenizer, not with
find
. You may want to try the other CPP to Rust converter: https://github.com/immunant/c2rust