Introduction to Rust

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 and many cargo crates (these are actually .tar.gz source archives) at the start of the build, so you cannot compile it without an internet connection.

The current rustbuild build-system will use all available processors, although it does not scale well and often falls back to just using one core while waiting for a library to compile.

At the moment Rust does not provide any guarantees of a stable ABI.



Rustc defaults to building for ALL supported architectures, using a shipped copy of LLVM. In BLFS the build is only for the X86 architecture. If you intend to develop rust crates, this build may not be good enough for your purposes.

Repeated builds of this package on the same machine show a wide range of build times. Some of this might be due to variations in downloading the required cargo files if they are not already present, but this does not seem to adequately explain the variations.

Unusually, a DESTDIR-style method is being used to install this package. This is because running the install as root not only downloads all of the cargo files again (to /root/.cargo), it then spends a very long time recompiling. Using this method saves a lot of time, at the cost of extra disk space.

This package is known to build and work properly using an LFS-8.3 platform.

Package Information

  • Download (HTTP):

  • Download MD5 sum: 6790c24fe5e8fb5a5f7efbfbcc6fea65

  • Download size: 101 MB

  • Estimated disk space required: 6.5 GB (679 MB installed) including 270MB of ~/.cargo files for the user building this (add 1.4GB if running the tests)

  • Estimated build time: 27 SBU (add 13 SBU for tests, both with 4 processors)

Rust Dependencies


cURL-7.63.0, CMake-3.13.3, libssh2-1.8.0, and Python-2.7.15



GDB-8.2.1 (recommended if running the testsuite)

User Notes:

Installation of Rust



This package is updated on a six-weekly release cycle. Because it is such a large and slow package to build, and is at the moment only required by five packages in this book, the BLFS editors take the view that it should only be updated when that is necessary.

First create a suitable config.toml file which will configure the build :

cat << EOF > config.toml
# see config.toml.example for more possible options
targets = "X86"

# When using system llvm prefer shared libraries
link-shared = true

# install cargo as well as rust
extended = true

prefix = "/usr"
docdir = "share/doc/rustc-1.29.2"

channel = "stable"
rpath = false

# BLFS does not install the FileCheck executable from llvm,
# so disable codegen tests
codegen-tests = false

# delete this *section* if you are not using system llvm.
# NB the output of llvm-config (i.e. help options) may be
# dumped to the screen when config.toml is parsed.
llvm-config = "/usr/bin/llvm-config"


Now install Rust by running the following commands:

export RUSTFLAGS="$RUSTFLAGS -C link-args=-lffi" &&
./ build

The build will report it failed to compile miri because of multiple potential crates for `log`, but that should be followed by a message that the build completed successfully.



On AMD Ryzen processors (family 17h), the non-optimized version of libstd which is compiled at the start of the tests contains one or more opcodes which are not implemented on this CPU family. These will be logged in the systemd journal and will be followed a few minutes later by segmentation faults. Despite that, the tests continue to run, apparently normally. But the system may reboot before the tests have completed. The normal optimized libraries run without this problem.

A mitigation is to install gdb but this does not always prevent the system rebooting.

To run the tests issue ./ test --verbose --no-fail-fast | tee rustc-testlog: as with the build, that will use all available CPUs. This runs many suites of tests (in an apparently random order), several will fail in BLFS: compile-fail/ require a thumbv6m-none-eabi compiler but the BLFS build does not cater for that, ui/issue-49851/ and ui/ (both run twice) require a thumbv7em-none-eabihf compiler, and seven tests in debuginfo-gdb will fail because gdb-8.1 changed the output format. If gdb has not been installed, most of the gdb tests will fail.

If you wish to look at the numbers for the results, you can find the total number of tests which were considered by running:

grep 'running .* tests' rustc-testlog | awk '{ sum += $2 } END { print sum }'

That should report 17101 tests. Similarly, the total tests which failed can be found by running:

grep '^test result:' rustc-testlog | awk  '{ sum += $6 } END { print sum }'

And similarly for the tests which passed use $4, for those which were ignored (i.e. skipped) use $8 (and $10 for 'measured', $12 for 'filtered out' but both are probably zero). The breakdown does not match the overall total.

Still as your normal user, do a DESTDIR install:

DESTDIR=${PWD}/install ./ install &&

Now, as the root user install the files from the DESTDIR:

chown -R root:root install &&
cp -a install/* /

Command Explanations

targets = "X86": this avoids building all the available linux cross-compilers (Aarch64, MIPS, PowerPC, SystemZ, etc). Unfortunately, rust insists on installing source files for these below /usr/lib/rustlib/src.

extended = true: this installs Cargo alongside Rust.

channel = "stable": this ensures only stable features can be used, the default in config.toml is to use development features, which is not appropriate for a released version.

rpath = false: by default, rust can be run from where it was built, without being installed. That adds DT_RPATH entries to all of the ELF files, which produces very messy output from ldd, showing the libraries in the place they were built, even if they have been deleted from there after the install.

[target.x86_64-unknown-linux-gnu]: the syntax of config.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.

export RUSTFLAGS="$RUSTFLAGS -C link-args=-lffi": This adds a link to libffi to any RUSTFLAGS you may already be passing to the build. On some systems, linking fails to include libffi unless this is used. The reason why this is needed is not clear.

--verbose: this switch can sometimes provide more information about a test which fails.

--no-fail-fast: this switch ensures that the testsuite will not stop at the first error.

export LIBSSH2_SYS_USE_PKG_CONFIG=1: On some systems, cairo fails to link during the install because it cannot find libssh2. This seems to fix it, but again the reason why the problem occurs is not understood.

DESTDIR=${PWD}/install ./ install: This effects a DESTDIR-style install in the source tree,creating an install directory. Note that DESTDIR installs need an absolute path, passing 'install' will not work.

chown -R root:root install: the DESTDIR install was run by a regular user, who owns the files. For security, change their owner before doing a simple copy to install them.


Installed Programs: cargo-clippy, cargo-fmt, cargo, clippy-driver, rls, rust-gdb, rust-lldb, rustc, rustdoc, rustfmt.
Installed Libraries: Many lib*<16-byte-hash>.so libraries.
Installed Directories: ~/.cargo, /usr/lib/rustlib, /usr/share/doc/rustc-1.29.2, and /usr/share/zsh/site-functions/

Short Descriptions


provides lint checks for a cargo package.


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


is the Package Manager for Rust.


provides lint checks for Rust.


is the Rust Language Server. This can run in the background to provide IDEs, editors, and other tools with information about Rust programs.


is a wrapper script for gdb, pulling in Python pretty-printing modules installed in /usr/lib/rustlib/etc.


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


is the rust compiler.


generates documentation from rust source code.


formats rust code.


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

Last updated on 2019-01-15 20:04:36 -0600