Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I need a C++ compiler to compile Rust?

Tags:

rust

This could be a very dumb question, but I'm wondering why the Rust compiler (written in Rust itself) require a C++ compiler.

I mean, a precompiled Rust compiler from the distribution should be enough, shouldn't it?

like image 392
Giacomo Tesio Avatar asked Feb 17 '15 18:02

Giacomo Tesio


People also ask

Does Rust use C compiler?

C++ has multiple compilers: for example, Clang, GCC, MinGW, Cfront, Intel C++ Compiler, Tiny C Compiler, LLVM, and more. For now, Rust's only compiler is LLVM-based, but a change is right around the corner, some language features used in high-performance code are only available with C++.

Does Rust use compiler?

Invocation. Compilation begins when a user writes a Rust source program in text and invokes the rustc compiler on it. The work that the compiler needs to perform is defined by command-line options.

Can you compile Rust with GCC?

This means that the Rust compiler, rustc, can be used with the GCC backend, the backend being the code generator which supports more CPU architectures than LLVM, the usual Rust backend compiler, though there are limitations such as requiring a patched version of GCC. The alternative is to have a complete GCC toolchain.

What is a compiler in Rust?

rustc is the compiler for the Rust programming language, provided by the project itself. Compilers take your source code and produce binary code, either as a library or executable. Most Rust programmers don't invoke rustc directly, but instead do it through Cargo.


1 Answers

It is actually a reasonable question. The answer is that currently, the rust source includes a slightly patched version of LLVM, LLVM is written in C++, and that is not distributed in binary form. So you need a C++ compiler to build that.

like image 84
rodrigo Avatar answered Oct 14 '22 05:10

rodrigo