Rustc-1.29.1

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.

[Note]

Note

Rustc defaults to building for ALL supported architectures, using a shipped copy of LLVM. In BLFS the build is only for the X86 architecture. Rustc still claims to require Python2, but that is only really necessary when building some other architectures with the shipped LLVM. 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): https://static.rust-lang.org/dist/rustc-1.29.1-src.tar.gz

  • Download MD5 sum: 42bcdc69536ab7a04bfead2ddade1edd

  • Download size: 102 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

Required

cURL-7.61.1, CMake-3.12.3, libssh2-1.8.0

Recommended

Optional

GDB-8.2 (recommended if running the testsuite)

User Notes: http://wiki.linuxfromscratch.org/blfs/wiki/rust

Installation of Rust

[Note]

Note

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
[llvm]
targets = "X86"

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

[build]
# install cargo as well as rust
extended = true

[install]
prefix = "/usr"
docdir = "share/doc/rustc-1.29.1"

[rust]
channel = "stable"
rpath = false

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

[target.x86_64-unknown-linux-gnu]
# 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"

EOF

Now install Rust by running the following commands:

export RUSTFLAGS="$RUSTFLAGS -C link-args=-lffi" &&
python3 ./x.py 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.

[Caution]

Caution

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 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 python3 ./x.py 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/issue-37131.rs require a thumbv6m-none-eabi compiler but the BLFS build does not cater for that, ui/issue-49851/compiler-builtins-error.rs and ui/issue-50993.rs (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:

export LIBSSH2_SYS_USE_PKG_CONFIG=1 &&
DESTDIR=${PWD}/install python3 ./x.py install &&
unset LIBSSH2_SYS_USE_PKG_CONFIG

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 ./x.py 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.

Contents

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

Short Descriptions

cargo-clippy

provides lint checks for 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

provides lint checks for Rust.

rls

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

rust-gdb

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

rust-lldb

is a wrapper script for LLDB (the LLVM debugger) pulling 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>.so

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

Last updated on 2018-09-30 16:44:35 -0500