Introducing rustc compiler

This topic provides information and links to relevant resources to understand the use of rustc compiler.

The rustc compiler for the Rust programming language takes your source code and generates binary code, either as executable or a library. rustc is not invoked directly at times though. Instead, it is done through Cargo. Cargo acts as the Rust package manager. It downloads the Rust package's dependencies, compiles your packages, generates distributable packages, and uploads them to the Rust community's package registry, crates.io.

To compile single file Rust program, run the following:
rustc <rust-source-file>
To create a new project with cargo, run the following:
cargo new <project-name>

Basic usage of rustc

The following example describes the use of rustc for a hello world program in a hello.rs file:
fn main() {
    println!("Hello, world!");
}
Use rustc to turn this source code into an executable:
$ rustc hello.rs
$ ./hello

Notes for crates

For the following crates, use the minimal version (or later) with AIX support added:
Table 1. Crates and their corresponding versions
Crate Version
libc 0.2.154
filetime 0.2.21
libloading 0.7.4
socket2 0.5.1
time 0.3
chrono 0.4.23
num_threads 0.1.6
rustix 0.37.1
tokio 1.28.0
fs_at 0.1.7
num_cpus 1.16.0
nix 0.27.0
iana_time_zone 0.1.58
mio 0.8.9
os_info 3.8.0
Note:

mio needs an additional option, --cfg mio_unsupported_force_poll_poll.

libc supports AIX from 0.2.142. However, to keep data types consistent with the current Rust release, use libc 0.2.154 or higher.

Cargo follows semantic versioning (that is, backward matching). For example, if filetime-0.2.17 is provided, Cargo can work well even if your project uses a version of filetime which is lower than 0.2.17.

Known limitations

Following are the known limitations:
  • Only 64-bit mode is supported.

  • Link Time Optimization (LTO) is not supported.

Related reference