Since the official Rust compiler is written in Rust, there’s an unpleasant chicken-egg problem as we need a Rust compiler in order to compile a Rust compiler. Also, given the security implications of compilers distributed solely as binaries (including compilers compiled from source code but using those distributed binaries), that’s an absolute no go for me.
Still, there is a way to bootstrap the Rust compiler from source code and here is how to do it (in Gentoo Linux).
TestRustcBootstrap.sh
like this (1.54.0 is the latest version mrustc can compile as of writing this note):
diff --git a/TestRustcBootstrap.sh b/TestRustcBootstrap.sh
index d34dca1f..7283fd54 100755
--- a/TestRustcBootstrap.sh
+++ b/TestRustcBootstrap.sh
@@ -6,7 +6,7 @@ set -u # Error on unset variables
WORKDIR=${WORKDIR:-rustc_bootstrap}/
RUSTC_TARGET=${RUSTC_TARGET:-x86_64-unknown-linux-gnu}
-RUSTC_VERSION=${*-1.29.0}
+RUSTC_VERSION=${*-1.54.0}
RUN_RUSTC_SUF=""
if [[ "$RUSTC_VERSION" == "1.29.0" ]]; then
RUSTC_VERSION_NEXT=1.30.0
@@ -67,6 +67,7 @@ rm -rf ${WORKDIR}mrustc-output
cp -r ${WORKDIR}mrustc/rustc-${RUSTC_VERSION_NEXT}-src/build/${RUSTC_TARGET}/stage2 ${WORKDIR}mrustc-output
tar -czf ${WORKDIR}mrustc.tar.gz -C ${WORKDIR} mrustc-output
+exit
#
# Build rustc by downloading the previous version of rustc (and its matching cargo)
#
(Optionally, also change -j8
to a number better fitting your CPU.)
find
cargo
in rustc_bootstrap/
and copy/link it to rustc_bootstrap/mrustc-output/bin/
.EAPI=8
SRC_URI
PYTHON_COMPAT
to what you have installedBOOTSTRAP_DEPEND
from BDEPEND
pkg_setup
section, comment out line calling bootstrap_rust_version_check
(and make sure you compile the right version yourself)src_configure
section, comment out lines setting printsysroot
and rust_stage0_root
and hardcode path to mrustc-output/
, e.g.:rust_stage0_root="/tmp/mrustc/rustc_bootstrap/mrustc-output"
/usr/portage/
(corresponding directories) or into your local overlay (in this case, make sure you have all needed patch files) and rebuild manifests.Personally, I have only these USE
flags enabled for dev-lang/rust
: system-bootstrap system-llvm verify-sig
.
I would like to express huge kudos to thepowersgang, the author of mrustc. Without his immeasurable work, the bootstrap of Rust simply wouldn’t be possible. It’s a shame that the Rust community and Foundation don’t help him or toss a coin in his direction (it’s not surprising, though :·\ ).
Tagged with: Gentoo Linux, Rust
Written: 2023-03-22