Here is what I want to do, in tl;dr form: I wish to compile '$platform-linux-musl
So. Suppose I installed the stable toolchain for my platform, which lives at
$RUSTUP_HOME/toolchains/stable-x86_64-unknown-linux-gnu/, and then I added a target using this compiler, specifically the musl one, which now lives at:
$RUSTUP_HOME/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/. This is all well and good on x86, everything works.
Now suppose that I am not on x86, but it seems that the compiler has definitions for musl on my platform. I would like static CRT linking here also. Suppose then that I have a working musl-gcc from my linux distribution, a working static libc I can use, and a copy of the Rust source. I cannot, as I have alluded, use rustup, since it does not provide my architecture's -musl target. Suppose also that I am curious and even if it did I am interested in how this is actually done, even for x86. Suppose also that I would prefer not to use an outdated docker container from github that was last updated in 201x.
Well, I'm a relatively smart cookie. I have the rust source, checked out at the tag I want, submodules and friends available. So I looked at the rustc dev guide on adding targets and it seems to suggest I want to say something like this:
DESTDIR=../stdlibstage1/ \ ./x.py install -i --stage 1 --host $(uname -m)-unknown-linux-gnu --target $(uname -m)-unknown-linux-musl \ compiler/rustc library/std
What it doesn't document is that I might need to use
config.toml. So I set my options based on a bit of googling and also looking at the CI of the rust project itself:
# Includes one of the default files in src/bootstrap/defaults profile = "codegen" changelog-seen = 2 [build] cargo = "path/to/cargo" rustc = "path/to/rustc" rustfmt = "path/to/rustfmt" [target.$(uname -m)-unknown-linux-musl] crt-static = true musl-root = "/usr/$(uname -m)-linux-musl/"
$(uname -m) provides correct paths on my distro.
This actually produces a working artefact, after a fashion! I can copy its components file and other parts into my rustup setup and cargo will pick them up. However, I then get an error:
error[E0514]: found crate `std` compiled by an incompatible version of rustc | = help: please recompile that crate using this compiler (rustc 1.63.0 (4b91a6ea7 2022-08-08)) (consider running `cargo clean` first)
compiling a hello world with
cargo build --target="$(uname -m)-unknown-linux-musl".
My question is: I think I asked in my
config.toml that the platform rust should be used. It didn't seem to be picked up. What gives?
I've asked this here rather than internals because I am really just a user of Rust, rather than a developer per se. I can ask it there if it is more suitable (if so, even better if someone has the power to move it).