From f11dfd84f0cfe21b2aae7dd1f4c6742b81187eb8 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Sun, 9 Oct 2022 20:00:36 +0800 Subject: [PATCH] rust: chapter08: add Rustc --- chapter06/rustc.xml | 3 +- chapter08/chapter08.xml | 1 + chapter08/rustc.xml | 346 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 349 insertions(+), 1 deletion(-) create mode 100644 chapter08/rustc.xml diff --git a/chapter06/rustc.xml b/chapter06/rustc.xml index 384861de9..90f8b7a75 100644 --- a/chapter06/rustc.xml +++ b/chapter06/rustc.xml @@ -168,7 +168,8 @@ ln -sv rustc-&rustc-version; $LFS/opt/rustc - <para>Details on this package are located in TODO.</para> + <para>Details on this package are located in + <xref linkend="contents-rustc" role="."/></para> </sect2> </sect1> diff --git a/chapter08/chapter08.xml b/chapter08/chapter08.xml index 6104985cf..cae1102dd 100644 --- a/chapter08/chapter08.xml +++ b/chapter08/chapter08.xml @@ -63,6 +63,7 @@ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="ninja.xml"/> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="libffi.xml"/> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="llvm.xml"/> + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="rustc.xml"/> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="kmod.xml"/> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="libelf.xml"/> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="python.xml"/> diff --git a/chapter08/rustc.xml b/chapter08/rustc.xml new file mode 100644 index 000000000..964956edf --- /dev/null +++ b/chapter08/rustc.xml @@ -0,0 +1,346 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" + "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ + <!ENTITY % general-entities SYSTEM "../general.ent"> + %general-entities; +]> + +<sect1 id="ch-system-rustc" role="wrap"> + <?dbhtml filename="rustc.html"?> + + <sect1info condition="script"> + <productname>Rustc</productname> + <productnumber>&rustc-version;</productnumber> + <address>&rustc-url;</address> + </sect1info> + + <title>Rustc-&rustc-version; + + + Rustc + + + + + + <para>The Rust programming language is designed to be a safe, + concurrent, practical language.</para> + + <segmentedlist> + <segtitle>&buildtime;</segtitle> + <segtitle>&diskspace;</segtitle> + + <seglistitem> + <seg>&rustc-final-sbu;</seg> + <seg>&rustc-final-du;</seg> + </seglistitem> + </segmentedlist> + + </sect2> + + <sect2 role="installation"> + <title>Installation of Rustc + + We will build Rustc as a native compiler for the canonical + triplet. But the building process still refers to the host triplet + of the temporary Rustc installed in &ch-tmp-cross;. So we need to + tell Rustc how to support the LFS-specific triplet again. However this + time we don't want to hard code the LFS-specific triplet in the final + Rustc, so create a JSON file to describe the target instead of modifying + the source code: + +mkdir target +RUSTC_BOOTSTRAP=1 rustc -Z unstable-options \ + --print target-spec-json \ + > target/$(uname -m)-lfs-linux-gnu.json +sed '/is-builtin/d' -i target/$(uname -m)-lfs-linux-gnu.json + + Create a suitable config.toml file for building Rustc for the + final LFS system: + +cat > config.toml << EOF +[llvm] +link-shared = true + +[build] +docs = false +locked-deps = true +vendor = true + +# install cargo, clippy, etc. as well as rustc +extended = true + +# build the native compiler for this triplet +host = [ "$(uname -m)-unknown-linux-gnu" ] + +# use temporary Rustc as the bootstrapping compiler +cargo = "/opt/rustc/bin/cargo" +rustc = "/opt/rustc/bin/rustc" + +[install] +prefix = "/opt/rustc-&rustc-version;" +docdir = "share/doc/rustc-&rustc-version;" + +[rust] +channel = "stable" +rpath = false +codegen-tests = false + +[target.$(uname -m)-lfs-linux-gnu] +# during bootstrap the native compiler for host is rebuilt +# so we need to specify this again +llvm-config = "/usr/bin/llvm-config" + +[target.$(uname -m)-unknown-linux-gnu] +cc = "gcc" +cxx = "g++" +ar = "ar" +ranlib = "ranlib" +linker = "gcc" + +llvm-config = "/usr/bin/llvm-config" +EOF + + Compile Rustc by running: + +RUST_TARGET_PATH=$PWD/target \ +PKG_CONFIG_ALLOW_CROSS=1 \ +python3 x.py build --stage 2 + + Install the package: + +RUST_TARGET_PATH=$PWD/target \ +PKG_CONFIG_ALLOW_CROSS=1 \ +DESTDIR=$PWD/dest \ +python3 x.py install --stage 2 + +mv -v /opt/rustc-&rustc-version;{,.old} +cp -av dest/* / +ldconfig + + Perform a sanity check: + +echo 'fn main() { println!("hello"); }' > hello.rs +rustc --target=$(uname -m)-unknown-linux-gnu hello.rs +./hello + + There should be no error messages, and the output should be + hello. Once the sanity check passed, remove the + temporary Rustc installation: + +rm -rf /opt/rustc-&rustc-version;.old + + + + + Contents of Rustc + + + Installed Programs + Installed Libraries + Installed Directories + + + + cargo-clippy, cargo-fmt, cargo, clippy-driver, + rls, rust-analyzer, rust-demangler, rust-gdb, + rust-gdbgui, rust-lldb, rustc, rustdoc, and rustfmt + + + librustc-driver-<16-byte-hash>.so, + libstd-<16-byte-hash>.so, and + libtest-<16-byte-hash>.so + + + ~/.cargo, + /opt/rustc, symbolic link to + /opt/rustc-&rustc-version; + + + + + + Short Descriptions + + + + + cargo-clippy + + + provides lint checks for a cargo package + + + cargo-clippy + + + + + + cargo-fmt + + + formats all bin and lib files of the current crate using + rustfmt + + + cargo-fmt + + + + + + cargo + + + is the Package Manager for Rust + + + cargo + + + + + + clippy-driver + + + provides lint checks for Rust + + + clippy-driver + + + + + + rls + + + is the Rust Language Server. This can run in the background to + provide IDEs, editors, and other tools with information about Rust + programs + + + rls + + + + + + rust-analyzer + + + is an implementation of Language Server Protocol for the Rust + programming language. + + + rust-analyzer + + + + + + rust-demangler + + + converts a list of Rust mangled symbols into a + corresponding list of demangled symbols + + + rust-demangler + + + + + + rust-gdb + + + is a wrapper script for gdb, pulling in Python pretty-printing + modules installed in + /opt/rustc-&rustc-version;/lib/rustlib/etc + + + rust-gdb + + + + + + rust-gdbgui + + + is a wrapper script for a graphical front end to gdb that runs in a + browser + + + rust-gdbgui + + + + + + rust-lldb + + + is a wrapper script for LLDB (the LLVM debugger) + pulling in the Python pretty-printing modules + + + rust=lldb + + + + + + rustc + + + is the rust compiler + + + rustc + + + + + + rustdoc + + + generates documentation from rust source code + + + rustdoc + + + + + + rustfmt + + + formats rust code + + + rustfmt + + + + + + libstd-<16-byte-hash>.so + + + is the Rust Standard Library, the foundation of portable Rust software + + + libstd-<16-byte-hash>.so + + + + + + +