cargo-zigbuild
c2rust
Our great sponsors
cargo-zigbuild | c2rust | |
---|---|---|
19 | 46 | |
1,167 | 3,667 | |
4.7% | 2.5% | |
8.6 | 9.5 | |
12 days ago | 2 days ago | |
Rust | Rust | |
MIT License | GNU General Public License v3.0 or later |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
cargo-zigbuild
-
Show HN: macOS-cross-compiler – Compile binaries for macOS on Linux
https://github.com/rust-cross/cargo-zigbuild
I’m curious what the blockers are for rustc to cross-compile like zig does natively.
- [Review] Introducing cargo-xwin: A Solution for Cross-Compiling Rust on macOS to MSVC
- Compiling Linux to Mac in CI/CD
-
Conditional compilation to avoid cross compilation
Perhaps you can try cargo-zigbuild, it uses zig-cc for cross-compilation instead of creating a container, so it should be much more lightweight on MacOS, without all the cost of virtualization and file sharing.
- Cross-compiling simple Rust code from Mac OS X to Raspberry Pi 4
-
Future of Rust, 2023 and beyond?
I have tried, however I haven't been able to get it to work reliably (e.g. building on windows + linux on WSL works, Mac is a lot more involved; tried building for windows + linux on Mac and I couldn't get it to work at all); I've had some luck using zigbuild but that too doesn't seem to work for Mac.
-
C2Rust Transpiler
Zig also takes this approach, and even exposes its C compiler (which if I recall correctly is basically Clang plus diverse sysroots and other customisation out of the box) as a separate `zig cc`.
I do a lot of work in Rust, and cross-compilation can be a pain when you have a lot of C dependencies. Fortunately https://github.com/messense/cargo-zigbuild exists. It sounds crazy, but using Zig's inbuilt C compiler to help build my Rust projects has been the smoothest option I've found.
I can't help but wonder if it would be worth it for Rust to follow D and Zig by shipping its own inbuilt C compiler, even if they still want to also support external C toolchains. It should be roughly the same effort as it was for Zig, given that they both use LLVM.
-
Short story of Rust being amazing yet again (because it compiles on different architectures effortlessly)
Wait until you start using cargo zig-build. Suddenly it becomes way better than Go's cross compiler because you can seamlessly cross-compile rust AND C (thanks to Zig compiler of course). https://github.com/messense/cargo-zigbuild
- The perfect language
-
Cross-compilation in Rust
I've personally used cargo-zigbuild and cargo-xwin to distribute a GUI app built with iced.
c2rust
-
Converting the Kernel to C++
A recent practical example of the former: the fish shell re-wrote incrementally from C++ to Rust, and is almost finished https://github.com/fish-shell/fish-shell/discussions/10123
An example of the latter: c2rust, which is a work in progress but is very impressive https://github.com/immunant/c2rust
It currently translates into unsafe Rust, but the strategy is to separate the "compile C to unsafe Rust" steps and the "compile unsafe Rust to safe Rust" steps. As I see it, as it makes the overall task simpler, allows for more user freedom, and makes the latter potentially useful even for non-transpiled code. https://immunant.com/blog/2023/03/lifting/
-
Emitting Safer Rust with C2Rust
> 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.
-
Writing an OS in Rust to run on RISC-V
This is arguably already the state of things.
Rust might get compiled down through MIR, down through LLVM IR, down to assembly or wasm... which then might be JIT or AOT (re)compiled into other bytecodes... which might perhaps be decompiled back up to C... and C might be retranslated back to horrific unsafe-spamming Rust by the likes of https://c2rust.com/. We've come full circle!
The main issue is that retranslating high level languages into other high level languages isn't something that there's actually a lot of demand for, especially commercially, especially given the N x M translation matrix going on. So a lot of the projects "stabilize" (get abandoned). And automatically translating between the idioms of those languages gets even nastier in terms of matrix bloat.
Well, you've got stuff like MSIL and JVM bytecodes which are higher level, and preserve more type information, and can be compiled to / decompiled from while still preserving more structure, but they still form competing incompatible ecosystems.
-
Will Carbon Replace C++?
That's the wrong direction. What's needed are intelligent converters which convert less-strict languages to more-strict ones.
Non-intelligent converters just make a mess. Here's c2rust.[1]
Classic C++ to modern C++, plus a compiler flag to lock out all the old unsafe stuff, would be an achievement.
- What would you rewrite in Rust?
-
Red Black Tree in Rust
Well, technically, it's not hard to build such data structures. If you are willing to liberally use raw pointers, UnsafeCell, MaybeUninit and ManuallyDrop, then you can more-or-less write C-equivalent code in unsafe Rust. (there are even transpilers from C to Rust)
-
C2Rust Transpiler
In the chart at [1], this step is represented by a magic wand.
(I wanted to give some examples, but https://c2rust.com/ seems to not be translating today.)
-
Pitchfork: Rack HTTP server for shared-nothing architecture
There are some tools specific to some transformations at least:
-
“Rust is safe” is not some kind of absolute guarantee of code safety
I expect that is because you're not particularly familiar with either LLVM or Rust, considering C can literally be transpiled to Rust.
What are some alternatives?
min-sized-rust - 🦀 How to minimize Rust binary size 📦
zig - General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
subsurface - This is the official upstream of the Subsurface divelog program
zz - 🍺🐙 ZetZ a zymbolic verifier and tranzpiler to bare metal C [Moved to: https://github.com/zetzit/zz]
librope - UTF-8 rope library for C
checkedc - Checked C is an extension to C that lets programmers write C code that is guaranteed by the compiler to be type-safe. The goal is to let people easily make their existing C code type-safe and eliminate entire classes of errors. Checked C does not address use-after-free errors. This repo has a wiki for Checked C, sample code, the specification, and test code.
rtorrent - rTorrent BitTorrent client
aws-lambda-rust-runtime - A Rust runtime for AWS Lambda
genny - Generate a shared library and bindings for many languages.
rust.aws-cdk-lambda - A CDK (v2) Construct Library for AWS Lambda in Rust
langs
json-c - https://github.com/json-c/json-c is the official code repository for json-c. See the wiki for release tarballs for download. API docs at http://json-c.github.io/json-c/