Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I convert an entire folder of C/C++ files to Rust? #8

Open
mczarnek opened this issue Feb 7, 2020 · 7 comments
Open

Can I convert an entire folder of C/C++ files to Rust? #8

mczarnek opened this issue Feb 7, 2020 · 7 comments

Comments

@mczarnek
Copy link

mczarnek commented Feb 7, 2020

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!!

@NishanthSpShetty
Copy link
Owner

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.

@ijustlovemath
Copy link

ijustlovemath commented Apr 30, 2020

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

@tooolbox
Copy link

tooolbox commented Jun 7, 2020

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

@ijustlovemath
Copy link

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

@tooolbox
Copy link

tooolbox commented Jun 7, 2020

Thanks, but that one seems to only support c, not cpp.

@ijustlovemath
Copy link

It uses the libclang backend, so it should support both C and C++ flawlessly. Give it a try!

@theoparis
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants