To speed up compilation, I want to build rustc optimized for my processor. To simplify the process, I do this in a container of the official Rust 1.64.0 Docker image. To actually speed up the compiler, I pass -march=native
when building LLVM and the environment varible RUSTFLAGS
is set to -C target-cpu=native
; my config.toml
can be found below. After compiling and installing the stage 2_ compiler with env DESTDIR="$(pwd -P)/install" python3 x.py install
, I get a dynamically linked executable. The thread How do I build rustc with statically linked rustlib? from 2016 suggests that a stage 3 compiler will be statically linked. When I set install-stage = 3
in config.toml
though, I get this error:
$ git rev-parse HEAD
a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52 # tag 1.64.0
$ export RUSTFLAGS='-C target-cpu=native'
$ export DESTDIR="$(pwd -P)/install"
$ time python3 x.py install
[snip]
Copying stage1 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Assembling stage2 compiler (x86_64-unknown-linux-gnu)
Uplifting stage1 std (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
Copying stage2 std from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Assembling stage3 compiler (x86_64-unknown-linux-gnu)
thread 'main' panicked at 'fs::read(stamp) failed with No such file or directory (os error 2) ("/home/docker/rust/build/x86_64-unknown-linux-gnu/stage2-rustc/x86_64-unknown-linux-gnu/release/.librustc.stamp")', lib.rs:1395:24
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
How can I fix this problem or is this a bug that needs to be reported?
By the way this error message matches the one in espr-rs/rust-build#17 but it occurred in a different context.
My config.toml:
profile = "user"
cflags = "-march=native"
cxxflags = "-march=native"
install-stage = 3
cargo = "/usr/local/cargo/bin/cargo"
rustc = "/usr/local/cargo/bin/rustc"
rustfmt = "/usr/local/cargo/bin/rustfmt"
cargo-native-static = true
low-priority = true
channel = "stable"