-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to compile rust in a musl libc based linux system #31322
Comments
Is the musl ld compatible enough with gnu ld (and the two libc's themselves)? If so, symlinking should be sufficient. |
Yes unfortunately we only produce glibc snapshots that are dynamically linked. There are currently no statically linked snapshots of the compiler. |
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 |
@petevine @nodakai Did not work. Some Symbol not found @alexcrichton Get it. : ) |
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 |
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 |
I got a bash script that uses docker to cross compile a |
@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. |
@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. |
@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? |
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 |
Wouldn't it make sense for the stage0 rustc to be statically linked in general? |
(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 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 |
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. |
I've been working on producing a static rustc the last few days, to no avail unfortunately. |
@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. :( |
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) |
Not bad @jirutka! I wonder if |
I think you only need to call
We are not building Cargo for |
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. |
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? |
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? |
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? |
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. |
I tried to bootstrap rust 1.20.0 on Alpine ppc64le ( |
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 :) |
@rustbot modify labels: +O-musl Now with beta musl host toolchain available (x86_64 only) and updated bootstrap it should work when you run I'll test and try to address issues on next week. |
Tried this today on an Alpine container. I got much further this time
|
@mati865 Thanks so much for trying to help. I do have the flags set
|
That's weird. I'll check it soon and report here. |
Is |
Bootstrap doesn't respect To bootstrap with musl you have to uncomment Line 475 in bfb443e
Line 115 in bfb443e
x86_64-unknown-linux-musl .
I tested it only in quite more complex environment (see #60240) but this should work on musl distros:
|
Is this issue obsolete now? |
Yes, it is. |
Closing then. |
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 ?
The text was updated successfully, but these errors were encountered: