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.



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 30 SBU on the 4-core machine where this was tested, at the cost of an extra 60MB of disk space for the extra files.

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

Package Information

  • Download (HTTP):

  • Download MD5 sum: d8d4d30c8d0b905f978bee3fdd618db5

  • Download size: 95 MB

  • Estimated disk space required: 5.1 GB (440 MB installed) including 379MB of ~/.cargo files for the user building this and 440MB of files in the DESTDIR (add 1.2GB if running the tests)

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

Rust Dependencies


cURL-7.61.0, CMake-3.12.1, libssh2-1.8.0, Python-2.7.15



GDB-8.1.1 (used by debuginfo-gdb in 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 three 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.25.0"

channel = "stable"
rpath = false

# get reasonably clean output from the test harness
quiet-tests = true

# 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 two opcodes which are not implemented on this CPU family. These will be logged in the system log 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 and to run the tests with 'ulimit -C disabled' but this does not always prevent the system rebooting.

To run the tests issue ./ test --verbose --no-fail-fast >../rustc-testlog: as with the build, that will use all available CPUs. This runs many suites of tests (in an apparently random order), at least one will fail: compile-fail/ tries to compile for the thumbv6m-none-eabi target but the BLFS build does not cater for that, and many tests in debuginfo-gdb will fail if gdb has not been installed. A few other tests might 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 13224 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 a little 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.

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-fmt, cargo, 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.25.0, and /usr/share/zsh/site-functions/

Short Descriptions


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


is the Package Manager 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 2018-08-19 14:04:57 -0700