Rustc-1.93.1

Introduction to Rustc

The Rust programming language is designed to be a safe, concurrent, practical language.

As with many other programming languages, Rustc (the Rust compiler) needs a binary from which to bootstrap. It will download a stage0 binary at the start of the build, so you must have an internet connection to build this package.

Note

Although GLFS usually installs in /usr, when you later upgrade to a newer version of Rustc, the old libraries in /usr/lib/rustlib will remain, with various hashes in their names, but they will not be usable and will waste space. The editors recommend placing the files in the /opt directory. In particular, if you have to rebuild with a modified configuration (e.g. using the shipped LLVM after building with the shared LLVM, perhaps to compile crates for architectures which the GLFS LLVM build does not support), it is possible for the install to leave a broken cargo program. If this occurs, you should either remove the existing installation first, or use a different prefix such as /opt/rustc-1.93.1-build2.

If you prefer, you can of course change the prefix to /usr.

The current rustbuild build system will use all processors, although it does not scale well and often falls back to just using one core while waiting for a library to compile. However it can be mostly limited to a specified number of processors by a combination of adding the switch --jobs <N> (e.g. '--jobs 4' to limit to 4 processors) on each invocation of ./x.py and using the CARGO_BUILD_JOBS=<N> environment variable.

The current version of rust's num_cpus crate now recognizes that cgroups can be used to restrict which processors it is allowed to use. If your machine lacks DRAM (typically, less than 2GB DRAM per core), that might be an alternative to taking CPUs offline.

At the moment, neither Rust or Rustc provide any guarantees of a stable ABI.

Note

Rustc defaults to building for ALL supported architectures, using a shipped copy of LLVM. In GLFS, the build is only for the x86 architecture family. If you are going to develop Rust crates, this build may not be sufficient.

The build times of this version when repeated on the same machine are often reasonably consistent, but as with all compilations using rustc, there can be some very slow outliers.

Note

An Internet connection is needed for building this package. The system certificate store may need to be set up with make-ca-1.16.1 before building this package.

Note

This may take a while to build. Feel free to do something else while this is building.

Rustc Dependencies

Required
CMake-4.2.3 and cURL-8.18.0

Recommended
LLVM-21.1.8 (built with -D LLVM_LINK_LLVM_DYLIB=ON so that Rustc can link to the system-installed LLVM instead of building its shipped version)

Note

If a recommended dependency is not installed, a shipped copy in the Rustc source tarball will be built and used.

Installation of Rustc

To install into the /opt directory, remove any existing /opt/rustc symlink and create a new directory (i.e. with a different name if trying a modified build of the same version). As the root user:

mkdir -pv /opt/rustc-1.93.1 &&
ln -svfn rustc-1.93.1 /opt/rustc

Note

If multiple versions of Rustc are installed in /opt, changing to another version only requires changing the /opt/rustc symbolic link and then running ldconfig.

Create a suitable bootstrap.toml file which will configure the build.

cat > bootstrap.toml << "EOF" &&
# See bootstrap.toml.example for more possible options,
# and see src/bootstrap/defaults/bootstrap.dist.toml for a few options
# automatically set when building from a release tarball.
# A decent number of options need to be changed.

# Tell x.py that the editors have reviewed the content of this file
# and updated it to follow the major changes of the building system.
# x.py during the build process will warn about it if this is not set.
change-id = 148795

[llvm]
# When using system-installed LLVM, prefer the shared libraries.
link-shared = true

EOF
if [ ! -f /usr/lib32/libc.so.6 ]; then
cat >> bootstrap.toml << "EOF"
# If the shipped LLVM source will be built, only enable the x86 target
# instead of all the targets supported by LLVM.
targets = "X86"

EOF
fi
cat >> bootstrap.toml << "EOF"
[build]
description = "for GLFS #cbdfa8"
EOF
if [ -f /usr/lib32/libc.so.6 ]; then
cat >> bootstrap.toml << "EOF"
target = [
  "x86_64-unknown-linux-gnu",
  "i686-unknown-linux-gnu",
]
EOF
fi &&
cat >> bootstrap.toml << "EOF" &&

# Omit the documentation to save time and space (the default is to build them).
docs = false

# Do not look for new versions of dependencies online.
locked-deps = true

# Specify which extended tools to install.
tools = ["cargo", "clippy", "rustdoc", "rustfmt", "src"]

[install]
prefix = "/opt/rustc-1.93.1"
docdir = "share/doc/rustc-1.93.1"

[rust]
channel = "stable"

# Uncomment if FileCheck has been installed.
#codegen-tests = false

# If you didn't build in NVPTX support, you can uncomment this.
#llvm-bitcode-linker = false

# Enable the same optimizations as the official upstream build.
lto = "thin"
codegen-units = 1

EOF
if [ -f /usr/lib32/libc.so.6 ]; then
cat >> bootstrap.toml << "EOF"
[target.x86_64-unknown-linux-gnu]
cc = "/usr/bin/gcc"
cxx = "/usr/bin/g++"
ar = "/usr/bin/gcc-ar"
ranlib = "/usr/bin/gcc-ranlib"
llvm-config = "/usr/bin/llvm-config"

[target.i686-unknown-linux-gnu]
cc = "/usr/bin/gcc"
cxx = "/usr/bin/g++"
ar = "/usr/bin/gcc-ar"
ranlib = "/usr/bin/gcc-ranlib"
EOF
else
cat >> bootstrap.toml << "EOF"
[target.x86_64-unknown-linux-gnu]
llvm-config = "/usr/bin/llvm-config"

[target.i686-unknown-linux-gnu]
llvm-config = "/usr/bin/llvm-config"
EOF
fi

Note

The above commands will create bootstrap.toml differently depending on if a few checks pass/fail. This was done to avoid confusion.

Compile Rust by running the following commands:

./x.py build

Now, as the root user, install the package:

./x.py install

Still as the root user, fix the installation of the documentation, symlink a Zsh completion file into the correct location, and move a Bash completion file into the location that is recommended by the Bash completion maintainers:

rm -fv /opt/rustc-1.93.1/share/doc/rustc-1.93.1/*.old   &&
install -vDm644 README.md \
  -t /opt/rustc-1.93.1/share/doc/rustc-1.93.1/ &&
install -vdm755 /usr/share/zsh/site-functions &&
ln -sfv /opt/rustc/share/zsh/site-functions/_cargo \
        /usr/share/zsh/site-functions &&
mv -v /etc/bash_completion.d/cargo \
      /usr/share/bash-completion/completions

Command Explanations

ln -svfn rustc-1.93.1 /opt/rustc: If this is not the first use of the /opt/rustc symlink, overwrite it by force, and use the '-n' flag to avoid getting confusing results from e.g. ls -l.

targets = [...]: This builds the targets that will be necessary for 32-bit Rust projects.

tools = ["cargo", "clippy", "rustdoc", "rustfmt", "src"]: Only build the tools from the 'default' profile from the command rustup, which are recommended for most users. The other tools are unlikely to be useful unless using (old) code analyzers or editing the standard library.

channel = "stable": This ensures only stable features are used. The default is to use development features, which is not appropriate for a released version of Rustc.

[target.x86_64-unknown-linux-gnu]: The syntax of bootstrap.toml requires an llvm-config entry for each target for which system-LLVM is to be used. Change the target to [target.i686-unknown-linux-gnu] if you are building on 32-bit x86. This whole section may be omitted if you wish to build against the shipped LLVM, or do not have clang, but the resulting build will be larger and take longer.

Configuring Rustc

Configuration Information

If you installed Rustc in /opt, you need to update the following configuration files so that Rustc is correctly found by other packages and system processes.

Note

The following command depends on the files created in The Bash Shell Startup Files.

Create the /etc/profile.d/rustc.sh startup file as the root user:

cat > /etc/profile.d/rustc.sh << "EOF"
# Begin /etc/profile.d/rustc.sh

pathprepend /opt/rustc/bin           PATH

# End /etc/profile.d/rustc.sh
EOF

Now source the main profile:

source /etc/profile

Contents

Installed Programs: cargo-clippy, cargo-fmt, cargo, clippy-driver, rust-gdb, rust-gdbgui, rust-lldb, rustc, rustdoc, and rustfmt
Installed Libraries: librustc-driver-<16-byte-hash>, libstd-<16-byte-hash>
Installed Directories: ~/.cargo, /opt/rustc, symbolic link to /opt/rustc-1.93.1

Short Descriptions

cargo-clippy

performs lint checks on a cargo package

cargo-fmt

formats all bin and lib files of the current crate using rustfmt

cargo

is the Package Manager for Rust

clippy-driver

performs lint checks on Rust code

rust-gdb

is a wrapper script for gdb which pulls in Python pretty-printing modules installed in /opt/rustc-1.93.1/lib/rustlib/etc

rust-gdbgui

is a wrapper script for a graphical front end to gdb that runs in a browser

rust-lldb

is a wrapper script for LLDB (the LLVM debugger) which pulls in the Python pretty-printing modules

rustc

is the Rust compiler

rustdoc

generates documentation from Rust source code

rustfmt

formats Rust code

libstd-<16-byte-hash>

is the Rust Standard Library, the foundation of portable Rust software