What does HackerNews think of c2rust?

Migrate C code to Rust

Language: Rust

#28 in Rust
> The date at the bottom of the article is 2022-06-13. Has there been further progress?

The article links to their github repo:

https://github.com/immunant/c2rust

There's commits in the last hour, so at least some signal of life.

c2rust https://github.com/immunant/c2rust :

> C2Rust helps you migrate C99-compliant code to Rust. The translator (or transpiler), c2rust transpile, produces unsafe Rust code that closely mirrors the input C code. The primary goal of the translator is to preserve functionality; test suites should continue to pass after translation.

crust https://github.com/NishanthSpShetty/crust :

> C/C++ to Rust transpiler

"CRustS: A Transpiler from Unsafe C to Safer Rust" (2022) https://scholar.google.com/scholar?q=related:WIDYx_PvgNoJ:sc...

rust-bindgen https://github.com/rust-lang/rust-bindgen/ :

Automatically generates Rust FFI bindings to C (and some C++) libraries

nushell/nushell looks like it has cool features and is written in rust.

awesome-rust > Applications > System Tools https://github.com/rust-unofficial/awesome-rust#system-tools

awesome-rust > Libraries > Command-line https://github.com/rust-unofficial/awesome-rust#command-line

rust-shell-script/rust_cmd_lib https://github.com/rust-shell-script/rust_cmd_lib :

> Common rust command-line macros and utilities, to write shell-script like tasks in a clean, natural and rusty way

Maybe you could try using c2rust [1] that transpile C to Rust, then try to port it back and forth. It would be much better if you can use Rust though.

[1]: https://github.com/immunant/c2rust

https://github.com/immunant/c2rust:

> We rely on Emscripten's Relooper algorithm to translate arbitrary C control flows.

Article on why Relooper isn't good enough and the superior Stackifier algorithm, which they probably should be using instead:

https://medium.com/leaningtech/solving-the-structured-contro...

It's better to convert existing C code to Rust semi-automatically with C2Rust[1] framework rather than wasting time converting to this instead.

[1] https://github.com/immunant/c2rust/

There's a translator for C99 to (unsafe) Rust: https://github.com/immunant/c2rust

So probably you can give me any C program and I'll be able to give you an equivalent Rust program. It'll probably perform about the same, too.

Could the effort be bootstrapped by using a C to Rust translator, like https://github.com/immunant/c2rust, preserving the existing semantics prior to updating the code to remove the "unsafe" tags.
We heavily investigated zstd and met with the brilliant inventor, Yann, who provided amazing insights into the design and rationale behind zstd and why it is so fast and such an amazing technology. I also recompiled zstd into rust using https://github.com/immunant/c2rust and tried using various webasm mechanisms to run it (I didn't get webasm quite fast enough, and teaching c2rust to make it safe would be quite a slog).

But the main reason we settled on Brotli was the second order context modeling, which makes a substantial difference in the final size of files stored on Dropbox (several percent on average as I recall, with some files getting much, much smaller). And for the storage of files, especially cold files, every percent improvement imparts a cost savings.

Also, widespread in-browser support of Brotli makes it possible for us to serve the dropbox files directly to browsers in the future (especially since they are concatenatable). Zstd browser support isn't at the same level today.

Immunant folks wrote a blog post [1] about automating conversion of Linux kernel drivers from C to Rust by using their tool c2rust[2].

[1] https://immunant.com/blog/2020/06/kernel_modules/

[2] https://github.com/immunant/c2rust

I think something that translates to the proper native language is a better goal. Something like c2rust[1] but for Java. There is some PoC[2][3] that can convert basic Java constructs to Rust. It can be taken as a base and improved.

[1] https://github.com/immunant/c2rust

[2] https://users.rust-lang.org/t/java-to-rust-converter-for-ted...

[3] https://github.com/aschoerk/converter-page

They need objc2swift, something like c2rust[1], to speed up the legacy code upgrade. Transpiler and code refactoring tool, all while preserving the ability to run tests. Or, on the other side, c2rust should get an Objective C support as an input.

[1] https://github.com/immunant/c2rust

Rewriting can be greatly automated. C2Rust[1] proves that. Just can be improved with new languages and refactoring capabilities.

[1] https://github.com/immunant/c2rust

EEE strikes again? Why not just use and contribute into the Rust itself? Why creating one more copy? They could have extended C2Rust[1][2] to support C++[3] and C# to ease their migration instead.

[1] https://c2rust.com

[2] https://github.com/immunant/c2rust

[3] https://github.com/immunant/c2rust/issues/162

There is an amazing project of converting Emacs into the more modern language - Rust (the C parts of it). It is called REmacs[1]. It is sad that the port of Emacs to Guile[2] didn't work out. And for the people who want to convert their C code to Rust, I quite recommend trying c2rust[3] transpiler and refactoring tool.

[1] https://github.com/remacs/remacs

[2] https://www.emacswiki.org/emacs/GuileEmacs

[3] https://github.com/immunant/c2rust/

Much or this can be automated with c2rust[1][2]. They recently published an overview[3] of lessons learned and future directions for Rust and C integration.

[1] https://c2rust.com

[2] https://github.com/immunant/c2rust

[3] https://immunant.com/blog/2019/11/rust2020/

There is an automated tool - c2rust[1], automating a huge chunk of the translation from C to Rust. Moreover, it has a refactoring tool[2] that is scriptable in Lua. One of the good examples of such conversion (still not finished though), while still producing the same output is a rewrite[3][4] of XeTeX engine to Rust (as part of Tectonic[5] engine). It is able to parse arXiv articles dump and generate valid PDFs still.

There is some concept[6] of converting Java to Rust, but it is far from being as useful as c2rust tool. Would be nice to integrate with c2rust somehow, if someone wants to help.

[1] https://github.com/immunant/c2rust

[2] https://c2rust.com/manual/c2rust-refactor/index.html

[3] https://github.com/tectonic-typesetting/tectonic/issues/459

[4] https://github.com/crlf0710/tectonic/tree/oxidize

[5] https://tectonic-typesetting.github.io/en-US/

[6] https://github.com/aschoerk/converter-page

It's the result of automated c2rust[1] conversion. Of course it will be cleaned up. C2rust itself provides handy refactoring tools scriptable in Lua language. A lot of the code will be removed, for example image handling can be done through image-rs crate, etc.

[1] https://github.com/immunant/c2rust

The initial step used c2rust[1] tool for automated conversion of C to Rust, and automated refactoring of the resulting Rust code. You can see the original issue[2] in Tectonic about oxidation plans. And there is a bunch of issues[3] if you want to help the project.

[1] https://github.com/immunant/c2rust

[2] https://github.com/tectonic-typesetting/tectonic/issues/459

[3] https://github.com/crlf0710/tectonic/issues

Convert the QuickJS code into Rust using c2rust[1], then reuse in rq.

[1] https://github.com/immunant/c2rust

If it will share the refactoring and cross-checking code with c2rust[1] it would be awesome. I created an issue[1] for tracking that. The next thing that is important - make it command line tool[3], instead of being a web service.

[1] https://github.com/immunant/c2rust/

[2] https://github.com/aschoerk/converter-page/issues/6

[3] https://github.com/aschoerk/converter-page/issues/5

Too scarce. Obviously missing rustfmt, clippy, and many others. See Development Tools[1] section on Awesome Rust. I would add also a C to Rust conversion tool - c2rust[2]. I hope also Java to Rust converter[3] would become comparable too.

[1] https://github.com/rust-unofficial/awesome-rust#development-...

[2] https://github.com/immunant/c2rust

[3] https://github.com/aschoerk/converter-page

There are a couple of projects that do this for Rust, depending on what your inputs and outputs are:

* https://github.com/rust-lang-nursery/rust-bindgen - Inputs are C/C++ headers, outputs are Rust type definitions and extern functions to interoperate with the type and functions in the headers

* https://github.com/immunant/c2rust - Inputs are C headers and source, outputs Rust code that is semantically equivalent to the C (modulo bugs, etc.)

* https://github.com/eqrion/cbindgen/ - Inputs are Rust source, outputs C/C++ headers that can be used to interoperate with the types and functions exposed by Rust