Rust Compilation Process
Rust is a compiled language that implements the convenient features of high-level languages at a lower level. It has the same high performance as the lower-level C language and the same security and usability as the higher-level Python language.
rustc is the compiler for the Rust programming language and uses LLVM as the backend to generate machine code. Figure 1 shows the process from the Rust source code to an executable program.
Essentially, rustc is an LLVM compilation frontend. It compiles code into LLVM IR, and the subsequent compilation and linking procedures are executed by LLVM.
Therefore, programs developed in Rust have good portability and can be used to compile applications and libraries that can run on other platforms on the current platform.
The compilation process is as follows:
- rustc performs syntax analysis and parsing on the Rust source code, and converts the source code into a high-level intermediate representation (HIR) file.
- Perform static type check to generate a machine intermediate representation (MIR) file, and further complete LLVM IR conversion and IR optimization to generate an LLVM IR file.
- Use the LLVM for backend compilation and linking and generate the machine code (executable program) for the corresponding platform.
Rust language porting mainly involves source code files containing SSE instructions and inline assembly. Common Rust source code files can be ported by recompiling them on the Kunpeng platform.
