6

I want to build static Rust executables with a customized version of musl. As a first step, I'm making myself familiar with Rust's build system.

I took the slightly outdated docker-rust-musl GitHub project and updated URLs that went out-of-date. Everything seems to work well with the build, but when I want to compile with x86_64-unknown-linux-musl the compiler doesn't find the musl std crate:

root@beb234fba4af:/build# cat example.rs
fn main() { println!("hi!"); panic!("failed"); }

root@beb234fba4af:/build# rustc --target=x86_64-unknown-linux-musl example.rs
error[E0463]: can't find crate for `std`
  |
  = note: the `x86_64-unknown-linux-musl` target may not be installed

error: aborting due to previous error

In fact, /usr/local/lib/rustlib/ only contains the x86_64-unknown-linux-gnu directory, even though output during the build indicates that x86_64-unknown-linux-musl is built:

[...]
Building stage2 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-musl)
[...]

However, when it comes to the installation step x86_64-unknown-linux-gnu is nowhere to be seen:

[...]
Install std stage2 (x86_64-unknown-linux-gnu)
install: creating uninstall script at /usr/local/lib/rustlib/uninstall.sh
install: installing component 'rust-std-x86_64-unknown-linux-gnu'

    std is standing at the ready.

Install rustc stage2 (x86_64-unknown-linux-gnu)
install: creating uninstall script at /usr/local/lib/rustlib/uninstall.sh
install: installing component 'rustc'

    Rust is ready to roll.

Build completed in 0:31:07

What do I have to do to install the x86_64-unknown-linux-musl Rust standard library?

Progress:

Digging through the build environment revealed that make all builds the Rust std library with musl but the subsequent make install step does not install it. We have a temporary fix in the build.sh script of the previously mentioned docker image. It is unclear whether that is an issue of the build environment or of its usage.

The issue is known to the Rust developers. No eta of the fix, however.

fzgregor
  • 1,807
  • 14
  • 20
  • Not exactly an answer to your question, but since all you want to do is to build a static executable might want to just check out https://github.com/clux/muslrust instead. – Erik Vesteraas Feb 13 '17 at 13:07
  • This image uses `rustup` to install a pre-compiled version of the rust std library compiled with musl which you can use then to statically compile rust applications. I want to build static rust applications with my customized version of musl. – fzgregor Feb 14 '17 at 08:17

0 Answers0