Rustup: No init build against musl libc

Created on 22 Apr 2016  Â·  16Comments  Â·  Source: rust-lang/rustup

There's no build of rustup-init against musl libc, which means that rustup cannot be installed on Alpine Linux, for example, without building rustup yourself.

Most helpful comment

Is rust-lang/rust producing rustc binaries for x86_64-unknown-linux-musl?

No, they _still_ do not. 😞 However, it is possible to build rustc on and for x86_64-unknown-linux-musl system with fully working both static and dynamic compilation, but it still requires some patches (see here). We in Alpine Linux do it since rust 1.17.0 (package rust). About half of the patches has been already upstreamed, somewhere between 1.19.0 and 1.21.0.

All 16 comments

Building rustup-init for x86_64-unknown-linux-musl is not going to be enough because there is no rustc component for that triple. I'm not aware of anyone that has built a _working_ rustc for that triple. I have tried and managed to built a rustc but it always crashed in the LLVM phase when I tried to compile anything. Probably, LLVM needed more patching (I applied some of Alpine Linux patches) to work correctly with musl but I didn't investigate further.

Alright then, my bad. This issue isn't really relevant to rustup then, so I'll close it.

Thanks anyway!

Using https://github.com/emk/rust-musl-builder I've just built what appears to be a perfectly good x86_64-unknown-linux-musl rustup-init (nothing fancy, just a cargo build --release). Is this problem now solvable or am I missing some other missing detail?

@palfrey, @japaric: Also wondering ...

It's still not possible to build a rustc that works on musl distros like Alpine. PR rust-lang/rust#40113 is one of the requirements to build such rustc.

It's still not possible to build a rustc that works on musl distros like Alpine.

That’s not entirely correct. It _is_ possible (see APKBUILD), I did it in August 2016 (with your help), but it requires cross-compiling rustc against musl on GNU-based system and applying some hacks.

It’d like to also note that there’s no problem with musl itself, just in Rust build system. 😿

Oy, the cargo package on alpine:edge fails to access the cargo index, due to linking against a broken libgit2... Could someone fix the Alpine rust & cargo packages plz

Rust and Cargo in Alpine testing are currently broken. We’ve updated Rust to the latest version, with better patches that allow both dynamic and static linking on Alpine. Initially it seemed that everything is okay, but then we found many breakages. Still hard working on it, fixing Rust build system…

Now that https://github.com/rust-lang/rust/pull/40113 has closed can't this be reopened?

@japaric WDYT?

@fzgregor

@japaric WDYT?

The same thing as almost two years ago:

Building rustup-init for x86_64-unknown-linux-musl is not going to be enough because there is no rustc component for that triple.

Is rust-lang/rust producing rustc binaries for x86_64-unknown-linux-musl? I'm no longer involved with infrastructure stuff so I don't know. Producing rustc binaries is a rust-lang/rust issue that the infra team is in charge of so you should ask them.

P.S. Also, I'm not a rustup developer so I can't reopen issues in this repo.

Thanks I will ping them then. This is super important for things like building rocket services into a docker container

Is rust-lang/rust producing rustc binaries for x86_64-unknown-linux-musl?

No, they _still_ do not. 😞 However, it is possible to build rustc on and for x86_64-unknown-linux-musl system with fully working both static and dynamic compilation, but it still requires some patches (see here). We in Alpine Linux do it since rust 1.17.0 (package rust). About half of the patches has been already upstreamed, somewhere between 1.19.0 and 1.21.0.

@corbinu @japaric Not sure if this is helpful, but it is possible to run rustup-init on Alpine Linux if one builds (or installs) glibc first and then uses patchelf to adjust the rpath of the rust binaries. See this docket file for an example script https://github.com/libertine-linux/libertine/blob/master/dockers/libertine-build-environment/Dockerfile.

I've got my fingers crossed that mrustc gets mature enough that I can bootstrap new Linux distros without this horrible chicken-and-egginess.

@raphaelcohn Your amazing! After only a little playing it looks like you don't even need the patches

FROM frolvlad/alpine-glibc

RUN apk add --no-cache curl bash

RUN curl https://sh.rustup.rs -o rustup-init
RUN chmod +x rustup-init
RUN ./rustup-init --verbose -y --no-modify-path --default-toolchain nightly --default-host x86_64-unknown-linux-gnu
RUN rm rustup-init

ENV PATH=/root/.cargo/bin:"$PATH"
RUN rustup target add x86_64-unknown-linux-musl
RUN rustup update
RUN rustc -Vv

ENTRYPOINT ["rustc"]

However it does appear that if I try to compile anything with a C/C++ dep then it implodes on jemalloc. I will have to look into other solutions there.

@raphaelcohn actually it looks like this may finally be coming anyway! https://github.com/rust-lang/rust/pull/55163

Was this page helpful?
0 / 5 - 0 ratings