Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upHow to compile rust in a musl libc based linux system #31322
Comments
This comment has been minimized.
This comment has been minimized.
MagaTailor
commented
Jan 31, 2016
|
Is the musl ld compatible enough with gnu ld (and the two libc's themselves)? If so, symlinking should be sufficient. |
This comment has been minimized.
This comment has been minimized.
|
Yes unfortunately we only produce glibc snapshots that are dynamically linked. There are currently no statically linked snapshots of the compiler. |
This comment has been minimized.
This comment has been minimized.
|
Can you try My understanding is it's similar to overriding a Shebang line in a shell script by explicitly calling a shell, like The |
This comment has been minimized.
This comment has been minimized.
|
@petevine @nodakai Did not work. Some Symbol not found @alexcrichton Get it. : ) |
steveklabnik
added
the
A-build
label
Feb 2, 2016
This comment has been minimized.
This comment has been minimized.
|
How about referencing a pre-built glibc (eg. https://www.archlinux.org/packages/core/x86_64/glibc/ ) ? It's shipped with a dynamic loader as well.
(Not sure if |
This comment has been minimized.
This comment has been minimized.
jirutka
commented
Jul 7, 2016
•
Well, obviously, because Alpine doesn’t use glibc, but musl libc, that is only partially binary compatible with glibc (musl strictly follows standards, but glibc does not). Therefore you can’t run rustc snapshot compiled against glibc on Alpine and it’s not possible to build rustc without rustc.
This is not about distributions, but different libc. So you need something to cross-compile between glibc and musl. It’s very similar to cross-compiling between different architectures.
I believe that it may be easy for someone skilled in cross compiling, but unfortunately me and other guys from Alpine community, who would like Rust on Alpine, are not. And those few skilled C programmers doesn’t like Rust, because… you know… C programmers… /cc @japaric |
This comment has been minimized.
This comment has been minimized.
|
I got a bash script that uses docker to cross compile a |
This comment has been minimized.
This comment has been minimized.
jirutka
commented
Jul 7, 2016
•
|
@japaric Thanks for your effort. I’ve discussed your gist in our IRC channel and skarnet recommends to use richfelker/musl-cross-make instead of GregorR/musl-cross. He said that GregorR’s musl-cross is pretty much obsoleted by richfelker’s (dalias’) musl-cross-make that is more up-to-date. |
japaric
referenced this issue
Jul 7, 2016
Closed
Adding non freestanding crates to list of crates xargo builds #17
jirutka
referenced this issue
Jul 7, 2016
Closed
Rust can be compiled against musl libc without cross-compilation from glibc #7
This comment has been minimized.
This comment has been minimized.
|
@jirutka Thanks for tip. I've updated the gist to use musl-cross-make instead of musl-cross. Unfortunately, it didn't magically fix the llvm issue. |
This comment has been minimized.
This comment has been minimized.
jirutka
commented
Jul 15, 2016
|
@japaric I’m trying to compile rustc using your script and it always fail in the last phase with:
I’ve tried it with gcc 5.3.0 and 5.2.0, with and without Do you have some idea what’s wrong? |
This comment has been minimized.
This comment has been minimized.
While building Are you following the gist instructions "to the letter"? In particular, are you using a Ubuntu 15.10 docker image? Because, IIRC, there some was some bug in the Ubuntu 16.04 Or it could be a recent regression in the |
This comment has been minimized.
This comment has been minimized.
|
Wouldn't it make sense for the stage0 rustc to be statically linked in general? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
(Heh, I'm not totally sure if I should this here or in one of the other closely related open issues but here it goes) Update: I got a rustc that works an Alpine. I have thrown a tarball of said compiler in my Dropbox in case anyone is interested in trying it out. I tested the compiler with the following smoke test:
I cheated to make this work though. I hacked the The way forward: I think we should add a new musl target that's just like the existing Implementations details: The implementation seems straightforward, but the unresolved question is: what should we call this new target? @alexcrichton suggested calling the new target |
This comment has been minimized.
This comment has been minimized.
jirutka
commented
Jul 26, 2016
•
|
This is really great news! Excellent work, @japaric!
Absolutely. Although I’m more a fan of static linking, I don’t understand Rust’s implication musl → static linking. musl can be statically linked without any problems (unlike ***** glibc…), but that doesn’t mean that it can’t be dynamically linked as well. Most of the Alpine Linux is dynamically linked.
Me neither, musl libc and Alpine are two different projects and Alpine is probably not the only distro that uses (dynamically linked) musl.
I’m afraid that it’s already too late to change it, but to be consistent with others,
I’m not sure about colon. It may be problematic e.g. on Windows when used in a file name. Triplet is already not a triplet, but quaternion, so maybe it would not hurt to use a quintuplet? ;) That said, I’m probably okay with any name, I can’t wait for rustc officially supported for musl. I’m gonna try your tarball yesterday. Thanks a lot! Could you please also update your gist with the build script? /cc @LeoUnglaub |
This comment has been minimized.
This comment has been minimized.
I agree, but it's too late. Changing it will probably break a bunch of build scripts.
Sure, I'll ping you when it's updated. |
This comment has been minimized.
This comment has been minimized.
|
I've been working on producing a static rustc the last few days, to no avail unfortunately. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
jirutka
commented
Jul 31, 2016
|
@japaric I can confirm that rustc you’ve compiled works well on Alpine Linux. Could you please create a complete snapshot like those hosted on http://static.rust-lang.org? I’ve spent half day just trying to built cargo, using cargo-bootstrap, and it’s like a nightmare. :( |
This comment has been minimized.
This comment has been minimized.
jirutka
commented
Jul 31, 2016
|
Uff, I finally managed to build cargo on musl (with a lot of ad-hoc fixes during the process)! cargo-0.11.0-nightly-x86_64-alpine-linux-musl.tar.gz (3.9 MiB) |
This comment has been minimized.
This comment has been minimized.
MagaTailor
commented
Jul 31, 2016
|
Not bad @jirutka! I wonder if |
This comment has been minimized.
This comment has been minimized.
I think you only need to call
We are not building Cargo for |
This comment has been minimized.
This comment has been minimized.
jirutka
commented
Aug 1, 2016
Hm, I’m still getting errors like below when compiling rustc on Alpine: /usr/lib/gcc/x86_64-alpine-linux-musl/6.1.0/../../../../x86_64-alpine-linux-musl/bin/ld:
/tmp/rustc.DH17TbBpNCoJ/liblibc-5aeeadd0596ef5a0.rlib(posix_spawn.lo):
relocation R_X86_64_PC32 against protected symbol `execve' can not be used when making a shared object
Yes, that’s what I’m doing.
No, https://static.rust-lang.org/cargo-dist/2016-03-21/cargo-nightly-x86_64-unknown-linux-gnu.tar.gz returns 404. BTW, it’s kinda hard to find what snapshots are available when static.rust-lang.org doesn’t provide indexes…
Uh, I’m stupid… I found this issue, but wanted to try it with cargo-bootstrap and then forgot about this easier way. |
This comment has been minimized.
This comment has been minimized.
Hmm, could that be related to #34978? If that's the case, I think a "snapshot" would still have the same problems. What version of binutils do you have installed in your Alpine box? It seems the binutils version is the root of the issue. A possible solution would be to cross compile the initial musl rustc from an older Ubuntu release (15.10 maybe?).
I've been annoyed by that before. Could you open an issue in rust-lang/cargo? |
jirutka
referenced this issue
Aug 2, 2016
Closed
Make https://static.rust-lang.org/cargo-dist browsable (i.e. add indexes) #2950
This comment has been minimized.
This comment has been minimized.
I agree. Whether that feature should always be exposed as flag or as a second target on all platforms is still undecided. So far, x86 Linux and ARM Linux use the second target (the musl target) approach.
Building a static binary with a dynamic rustc is also supported, via cross compilation to the musl target.
IMO, the use cases in order of importance/frequency are: dynamic binary (the default), static binary (mainly used to ease deployment) and static rustc (not too many people bootstrap the compiler). |
This comment has been minimized.
This comment has been minimized.
Perhaps, yes, but if we extend the concept of a target to also take into account extra configuration (like how we link libc) then we may not necessarily diverge literally in the name of the target. I definitely agree however that we're always going to be producing two artifacts! It's just a question of what to call them :( I wouldn't feel too too bad about adding new target names, if we can especially figure out a good name pattern that would solve the MSVC case as well then that'd be great. |
This comment has been minimized.
This comment has been minimized.
Does this approach work if you link against native libraries? My specific use case is producing a static linux binary including libclang. |
This comment has been minimized.
This comment has been minimized.
emilymaier
commented
Aug 8, 2016
I didn't get that far. The more immediate problem I had was building liblibc, as I wanted the .rlib to include libc.a and the .so to link to libc.so, but the link args only permitted one or the other for building a single target as far as I could tell. |
This comment has been minimized.
This comment has been minimized.
|
Sure, as long as the crate with the Rust bindings to libclang (and actually, all your other dependencies that bind to a C library) tells Cargo that it will statically link to BTW, which clang crate are you using?
My understanding is that a libfoo.rlib will either contain a copy of libbar.a or simply contain a "must link to libbar.so" instruction in its metadata (it doesn't contain a copy of libbar.so!). It doesn't seem possible to tell the rlib to do both things because when building a dynamically linked binary, rustc will have to pass libfoo.rlib, which contains libbar.a, and -lbar to the linker and the linker will likely fail because it will end up with two sets of the same symbols: one set of defined symbols (libbar.a) and set of undefined symbols (libbar.so). |
This comment has been minimized.
This comment has been minimized.
|
@japaric Should there be a way for a crate to link dynamically to an external library if and only if it itself is to be linked dynamically? |
This comment has been minimized.
This comment has been minimized.
|
https://github.com/KyleMayes/clang-sys does an excellent job of enabling dynamic or static linking of external libraries via cargo feature flags. |
This comment has been minimized.
This comment has been minimized.
|
@DemiMarie That can be done in the build.rs: one can pick between @jupp0r Oh, that's nice. That crate with the |
This comment has been minimized.
This comment has been minimized.
jirutka
commented
Sep 17, 2016
|
@japaric One month passed, so I’d like to ask, is there some progress on this issue? When will Rust support dynamic linking on Musl libc and when will Rust start providing precompiled rustc for musl? |
This comment has been minimized.
This comment has been minimized.
|
@jirutka Sorry, not much progress since then. We haven't decided how we want to expose the static vs dynamic linking choice to the user though there is a RFC (rust-lang/rfcs#1721) on that topic. Without that settled, it's not clear if we want to add a second musl target (same definition, different name) that always links dynamically or if we can keep using a single musl target (and have a single musl rustc release) and simply have the user specify whether they want to use static (the default, which is unlikely to change at this point) vs dynamic linking at build time. |
This comment has been minimized.
This comment has been minimized.
jirutka
commented
Sep 25, 2016
This RFC is definitely the better way, but it’s one month since the last comment on the RFC and 3/4 of the year since this issue has been opened. Until the decision is made for rust-lang/rfcs#1721, could you please add new (temporary) targets
It’ll be probably used only in Alpine and Void. I have no problem with changing the Alpine packages to use the new mechanism after rust-lang/rfcs#1721 is implemented. I guess that @chneukirchen can take care of Void packages. |
This comment has been minimized.
This comment has been minimized.
jirutka
commented
Sep 25, 2016
|
BTW, is it already possible to build statically linked rustc? |
This comment has been minimized.
This comment has been minimized.
|
I asked this to the tools team. And they are leaning to:
I didn't explicitly ask about the temporary solution of adding a new target but, IMO, seems unlikely that we'll do that because we'll have to maintain that target "forever" even if it's stop being useful/used.
I haven't tried since more than one moth ago but last time I tried it still segfaulted. Our LLVM fork got upgraded to 3.9 in the meantime so there may have been some change on that front. |
This comment has been minimized.
This comment has been minimized.
To clarify, this will probably be configurable via a |
This comment has been minimized.
This comment has been minimized.
lluixhi
commented
Nov 4, 2016
|
@jirutka |
This comment has been minimized.
This comment has been minimized.
|
Update: PR #37545 implements the |
This comment has been minimized.
This comment has been minimized.
misery
commented
Feb 2, 2017
|
PR is merged.... is it possible to build rust 1.15.0 on AlpineLinux now? :-) |
This comment has been minimized.
This comment has been minimized.
jirutka
commented
Feb 2, 2017
•
|
@misery I’ve tried to build 1.11.0 with our current 1.10.0 some time ago and it failed. So I’m afraid that I have to cross-compile it again. Unfortunately there’s still no precompiled rustc for bootstrapping rustc on must-based distro (or statically linked rustc so it can be used anywhere) and I haven’t had time yet for another cross-compiling and hacking session. |
vishvananda
referenced this issue
Feb 23, 2017
Closed
change musl linker to /lib/ld-musl-x86_64.so.1 or support -dynamic-linker option #40049
This comment has been minimized.
This comment has been minimized.
pickfire
commented
Feb 24, 2017
|
Yes, I have tried to build it with https://s3.amazonaws.com/rust-lang-ci/cargo-builds/fbeea902d2c9a5be6d99cc35681565d8f7832592/cargo-nightly-x86_64-unknown-linux-gnu.tar.gz as well but no luck.
Might as well be python 2's fault, does it supports python 3? |
cengizIO
referenced this issue
Mar 14, 2017
Open
rustbuild: if stage0 binaries can't be run, kindly inform user #40529
maniankara
referenced this issue
Mar 26, 2017
Closed
Fix for saving in rpm, deb and docker repo/registries #84
This comment has been minimized.
This comment has been minimized.
ncopa
commented
Apr 11, 2017
|
We are adding support for ppc64le and s390x to Alpine (with musl libc). Are there any progress in a sane way to bootstrap/port rustc? |
This comment has been minimized.
This comment has been minimized.
jirutka
referenced this issue
Apr 12, 2017
Closed
rustbuild check does not support “keep going” (-k) #41248
Mark-Simulacrum
added
the
C-tracking-issue
label
Jul 24, 2017
This comment has been minimized.
This comment has been minimized.
corbinu
commented
Sep 14, 2017
|
Now that #40113 has closed does anybody know how I actually build master for Alpine. I have tried both on Alpine and Ubuntu and keep hitting walls. If anybody would be willing to help me through it I would be happy to document it for others. |
This comment has been minimized.
This comment has been minimized.
rgdoliveira
commented
Sep 14, 2017
|
I tried to bootstrap rust 1.20.0 on Alpine ppc64le ( |
This comment has been minimized.
This comment has been minimized.
stefson
commented
Sep 15, 2017
•
|
It is complicated. The guy who wrote #40113 explained (tried to explain) to me how it works, see here: gentoo/musl#44 (comment) You need for sure a fully working rust and cargo plus llvm and gcc (for linking) installed on the system you will start the build, so before that isn't done you don't have to worry about further details :) |
uuhan commentedJan 31, 2016
Hi, recently I need to compile rust in my musl libc based linux system. I download the rust's source code, configure it and make.
But it failed due to the rust/x86_64-unknown-linux-gnu/stage0/bin/rustc run failed.
It's interpreter is
/lib64/ld-linux-x86-64.so.2
but my system has just the
/lib/ld-musl-x86_64.so.1
I have already the llvm-3.5 installed, It seems to be it just lack of a runable rust stage0 binary for my system.
So, is there a STATICALLY LINKED RUST STAGE0 binary to feed my needs?
Or, how can I compile the proper stage0 rustc binary from stretch ?