How to build (aka bootstrap) Rustc from GCC using Mrustc on Linux From Scratch 11.0? Clemens Lahme (clemens.lahme@techinvest.li) 2021-12-12 Home http://techinvest.li/tinux/rustc.txt Requirements - LFS and BLFS (without Rustc) 11.0, which includes cmake, python3, and is setup with the lfs user, who has sudo admin rights. - The time program as an executable (the bash builtin is _not_ sufficient), part of BLFS. - 100 GB empty disk space. - 'Enough' memory. 8 GB of memory plus 32 GB of swap space leads to a lot of swapping and an additional built time of 10 hours. 32 GB of memory for 16 threads is OK. Depending on number of threads you need more or less memory. - Ample time. After the long build of mrustc, that one is used to build rustc 1.39.0, which is then iteratively used to build all versions up to 1.52.0. That is the version used in LFS/BLFS 11.0. You can easily go till the latest current version of 1.56.1, if you have a need for that. Note however, that all intermediate versions get deleted to conserve disk space (or you would need an additional 80 GB). E.g. just building 1.41 till 1.56 took 11 hours on a Ryzen 2700X with 32 GB of memory. Process overview. - Download all needed source tar files not part of LFS/BLFS 11.0 (except the rustc ones). - Download all rustc source tar balls using a script in the patched mrustc repo. - Install GCC 9.2.0 next to the existing GCC 11.2.0, as that is what Mrustc needs. - Install an older version of cmake using GCC 9.2.0 to avoid any references to the one build with GCC 11.2.0. - Install an older version of binutils using GCC 9.2.0 for the same reason. The two last steps are maybe just because I didn't know what I was doing and my intermittent problems resulted from other issues like too little disk space, but this worked finally right now I am not going back investing another 16 hours to reduce these two steps. You might report a slimmer routine. - Put a python link to python3 into the PATH environment variable. - Build mrustc and all following rustc versions in one go. - Install rustc in the /opt hierarchy and set your PATH accordingly. Download all non rustc source tar files su - lfs umask 0022 mkdir -p /sources/rustc cd /sources/rustc # All part of BLFS 9.0. wget https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.xz wget https://cmake.org/files/v3.15/cmake-3.15.2.tar.gz wget http://ftp.gnu.org/gnu/binutils/binutils-2.32.tar.xz # Patched version in tar form from: http://techinvest.li/git/mrustc.git # Original project at: https://github.com/thepowersgang/mrustc.git wget http://techinvest.li/tinux/mrustc-0.9.1-a35d77a.tar.gz #wget http://techinvest.li/clemens_lahme_at_techinvest_dot_li.pgp #gpg --import clemens_lahme_at_techinvest_dot_li.pgp wget http://techinvest.li/tinux/SHA256SUMS_mrustc.txt.asc wget http://techinvest.li/tinux/SHA256SUMS_mrustc.txt gpg --verify SHA256SUMS_mrustc.txt.asc sha256sum -c SHA256SUMS_mrustc.txt Download rustc source tar files tar xf ./mrustc-0.9.1-a35d77a.tar.gz cd ./mrustc-0.9.1 ./download_rustc_sources.sh cd .. Build GCC 9.2.0 export MAKEFLAGS="-j$(nproc)" tar xf ./gcc-9.2.0.tar.xz cd ./gcc-9.2.0 case $(uname -m) in x86_64) sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64 ;; esac mkdir ./build cd ./build ../configure \ --prefix=/opt/gcc-9.2.0 \ --disable-multilib \ --with-system-zlib \ --enable-languages=c,c++ make sudo make install cd ../.. rm -rf ./gcc-9.2.0 pushd /opt/gcc-9.2.0/bin sudo ln -s gcc cc popd export PATH=/opt/gcc-9.2.0/bin:$PATH export LD_LIBRARY_PATH=/opt/gcc-9.2.0/lib:/usr/lib sudo ldconfig Build cmake 3.15.2 tar xf ./cmake-3.15.2.tar.gz cd ./cmake-3.15.2 sed -i '/"lib64"/s/64//' Modules/GNUInstallDirs.cmake ./bootstrap --prefix=/opt/cmake-3.15.2 \ --system-libs \ --mandir=/opt/cmake-3.15.2/share/man \ --no-system-jsoncpp \ --no-system-librhash \ --docdir=/opt/cmake-3.15.2/share/doc/cmake-3.15.2 make sudo make install cd .. rm -rf ./cmake-3.15.2 export PATH=/opt/cmake-3.15.2/bin:$PATH Build binutils 2.32 tar xf ./binutils-2.32.tar.xz cd ./binutils-2.32 sed -i '/@\tincremental_copy/d' gold/testsuite/Makefile.in mkdir -v ./build cd ./build ../configure --prefix=/opt/binutils-2.32 \ --enable-gold \ --enable-ld=default \ --enable-plugins \ --enable-shared \ --disable-werror \ --enable-64-bit-bfd \ --with-system-zlib make tooldir=/opt/binutils-2.32 sudo make tooldir=/opt/binutils-2.32 install cd ../.. rm -rf ./binutils-2.32 export PATH=/opt/binutils-2.32/bin:$PATH export LD_LIBRARY_PATH=/opt/binutils-2.32/lib:$LD_LIBRARY_PATH sudo ldconfig Setup temporary python link mkdir ./bin cd ./bin ln -s /usr/bin/python3 python cd .. export PATH=$PWD/bin:$PATH Build rustc using mrustc #tar xf ./mrustc-0.9.1-a35d77a.tar.gz cd ./mrustc-0.9.1 ./bootstrap_main.sh 1.52.0 1.51.0 mv rustc-1.39.0-src.tar.gz.processed ../rustc-1.39.0-src.tar.gz mv rustc-*-src.tar.gz ../ cd .. rm -rf ./mrustc-0.9.1 Install Rustc under /opt sudo mv ./mrustc-0.9.1/rustc-1.52.0_bootstrap /opt/rustc-1.52.0 rm /opt/rustc-1.52.0/mrustc.log mkdir /opt/rustc-1.52.0/bin cd /opt/rustc-1.52.0/bin ln -s ../mrustc/rustc-1.52.0-src/build/x86_64-unknown-linux-gnu/stage3/bin/rustc rustc ln -sf ../mrustc/rustc-1.52.0-src/build/x86_64-unknown-linux-gnu/stage3-tools-bin/cargo cargo sudo chown -R root:root /opt/rustc-1.52.0 cd /opt sudo ln -s rustc-1.52.0 rustc export PATH=/opt/rustc/bin:/usr/bin unset LD_LIBRARY_PATH sudo ldconfig rustc --version cargo --version Thanks - Mutabah for helping a lot using mrustc when I was stuck. - LFS crew for code snippets reused here and with help setting up GCC in parallel. - Malina for doing the same before, thought without any documentation trace. My thoughts on the Rust language If the language is so great, why is the compiler so slow and bloated. Please don't add rustc as a dependency to your projects.