Compiling a Rust file with rustc foo.rs
fails if I don't have a C++ toolchain installed. But when compiling a Go program, such a toolchain is not required. Why is that?
TL;DR: Because everyone has a C toolchain.
Slight correction: rustc does not require a C++ toolchain, it only requires a C toolchain. Notably, rustc created binaries only depend on libc
(or equivalent), not on libstdc++
(or equivalent).
As Go demonstrated, it is possible to not require a C toolchain. You only need to re-implement its functionality:
There are advantages to doing so, such as possibly faster compilation or easier cross-compiling, however there is a cost in doing the implementation, and it's easy to get things wrong.
The Rust community preferred to put more effort into the language than in the toolchain, and therefore reusing the stock toolchain was easier. Specifically, rustc will require a platform linker (ld
on Unix) and platform equivalent to libc
.
This is not a core design principle, it's just a pragmatic approach, and there are projects to cut down on these dependencies:
libc
API.Those are all work in progress, and in the meantime rustc will require a C toolchain. Furthermore, even in the foreseeable future, I would expect rustc to require a C toolchain for targets not yet covered by any Rust toolchain, just so you can use the target without waiting for some hypothetical development.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With