Rustc-1.32.0

Introduction to Rust

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

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 (either to fix problems, or to allow a new version of firefox to build).

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.

These crates will then remain in various forms (cache, directories of extracted source), in ~/.cargo for ever more. It is common for large rust packages to use multiple versions of some crates. If you purge the files before updating this package, very few crates will need to be updated by the packages in this book which use it (and they will be downloaded as required). But if you retain an older version as a fallback option and then use it (when not building in /usr), it is likely that it will then have to re-download some crates. For a full download (i.e. starting with an empty or missing ~/.cargo) downloading the external cargo files for this version only takes a minute or so on a fast network.

[Note]

Note

Although BLFS usually installs in /usr, when you later upgrade to a newer version of rust the old libraries in /usr/lib/rustlib will remain, with various hashes in their names, but will not be usable and will waste space. The editors recommend placing the files in the /opt directory. In particular, if you have reason to rebuild with a modified configuration (e.g. using the shipped LLVM after building with shared LLVM, but perhaps also the reverse situation) it it possible for the install to leave a broken cargo program. In such a situation, either remove the existing installation first, or use a different prefix such as /opt/rustc-1.32.0-build2.

If you prefer, you can of course change the prefix to /usr and omit the ldconfig and the actions to add rustc to the PATH.

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 Python 2, 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.

Unlike with previous versions, the build times of this version when repeated on the same machine seem reasonably consistent.

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.4 platform.

Package Information

  • Download (HTTP): https://static.rust-lang.org/dist/rustc-1.32.0-src.tar.gz

  • Download MD5 sum: 366f049777e00d0d6f15d25895485efb

  • Download size: 152 MB

  • Estimated disk space required: 6.2 GB (475 MB installed) including 295MB of ~/.cargo files for the user building this. Add 1.5GB if installing the documentation (an extra 314MB is installed), and 2.0GB if running the tests

  • Estimated build time: 34 SBU (add 3 SBU if installing the documentation and 15 SBU for tests, both with 4 processors)

Rust Dependencies

Required

cURL-7.64.0, CMake-3.13.4, and libssh2-1.8.0

Optional

GDB-8.2.1 (used by the testsuite if it is present) and Python-2.7.15 (if gdb is present, it must have been built with Python 2 support to prevent some tests failing. Furthermore, another test fails if Python 2 is not present)

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

Installation of Rust

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

mkdir /opt/rustc-1.32.0             &&
ln -svfin rustc-1.32.0 /opt/rustc
[Note]

Note

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

Create a suitable config.toml file which will configure the build. Unlike with previous releases, where even quite old system versions of LLVMworked well, this version ships with a development version and using the current LLVM-7.0.1 release is known to result in breakage in some circumstances.

cat << EOF > config.toml
# see config.toml.example for more possible options
[llvm]

# use ninja
ninja = true

targets = "X86"
# When compiling LLVM, the experimental targets (WebAssembly
# and RISCV) are built by default - omit them
experimental-targets = ""

[build]
# omit HTML docs to save time and space (comment this to build them)
docs = false

# install cargo as well as rust
extended = true

[install]
# Adjust the prefix for the desired destination
#prefix = "/usr"
prefix = "/opt/rustc-1.32.0"

# docdir is used even if the full awesome docs are not installed
docdir = "share/doc/rustc-1.32.0"

[rust]
channel = "stable"
rpath = false

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

# get a trace if there is an Internal Compiler Exception
backtrace-on-ice = true

EOF

Now install Rust by running the following commands:

export RUSTFLAGS="$RUSTFLAGS -C link-args=-lffi" &&
python3 ./x.py build --exclude src/tools/miri
[Note]

Note

The testsuite will generate some messages in the system log for traps on invalid opcodes, and for segmentation faults. In themselves these are nothing to worry about, just a way for the test to be terminated. But if the output from the testsuite reports tests which FAIL with segmentation faults (signal 11) then there may be a problem.

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.

The instructions above do not build ARM compilers, so the testsuite will fail and the tests will be reported to end in error, with a backtrace of the last failing test. On a good run, 3 tests which need Thumb (ARM) compilers will fail, all in ui/issues for issues 37131, 49851 and 50993. Occasionally a fourth test, run-make-fulldeps/sysroot-crates-are-unstable fails. If gdb has been installed, in some circumstances three tests in debuginfo also fail. As with all large testsuites, other tests might fail on some machines - if the number of failures is in the single digits, check the log for 'FAILED' and review lines above that. Any mention of SIGSEGV or signal 11 in a failing test is a cause for concern.

Therefore, you should determine the number of tests, failures, etc. The total number of tests which were considered is found by running:

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

That should report 15795 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 quite 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

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

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.

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.

--exclude src/tools/miri: For a long time, the miri crate (an interpreter for the Midlevel Intermediate Representation) has failed to build on releases. It is optional, but the failure messages can persuade people that the whole build failed.

--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 python3 ./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.

Configuring Rust

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.

As the root user, update the /etc/ld.so.conf file and the dynamic linker's run-time cache file:

cat >> /etc/ld.so.conf << EOF
# Begin rustc addition

/opt/rustc/lib

# End rustc addition
EOF

ldconfig

As the root user, create the /etc/profile.d/rustc.sh file:

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

Immediately after installation, update the current PATH for your current shell as a normal user:

source /etc/profile.d/rustc.sh

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.32.0, 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 2019-02-15 13:01:29 -0800