Auto merge of #26302 - aidanhs:aphs-fix-musl-libc, r=alexcrichton

musl may not be available on the target user's machine, and even if it is, we may not be able to find it because of how static libraries are searched for.
Instead, use the liblibc archive created at rust compile time which already contains libc.a.

---

To be honest, my brain is bending a bit at this point and I wonder if I'm doing something a bit stupid.

Problem: building the libc crate with target musl. It says "could not find native static library `c`, perhaps an -L flag is missing?".

Some pondering: the key problem is the way static archives are searched for (note that a musl build attempts to statically link to libc) - they aren't. There are three locations which are checked (including `$PREFIX/lib/rustlib/x86_64-unknown-linux-musl/lib`), but this does not include `$PREFIX/lib`...and it probably shouldn't - rustc is mimicking the way native lib generation works by forcing you to provide the path yourself. You can make it work `cargo rustc` with `-L native=/path/to/musl/lib`, but even if this went in a build script for the libc crate, it wouldn't work if musl isn't installed by the end user.

I've sprinkled `not(test)` around but I've no idea if I've done it right.

This patch allows `cargo build --target x86_64-unknown-linux-musl` to work on a crate with a dependency on libc, where the musl-enabled rust was compiled before this patch. I've not yet kicked off the long process to build a musl-enabled rust with this patch, so it might be broken there.

Sorry for the rambling.

r? @alexcrichton
This commit is contained in:
bors 2015-06-15 14:07:48 +00:00
commit d9b8015828

View File

@ -146,7 +146,10 @@ pub use funcs::bsd43::*;
#[link(name = "m")]
extern {}
#[cfg(all(target_env = "musl", not(test)))]
// When compiling rust with musl, statically include libc.a in liblibc.rlib.
// A cargo build of the libc crate will therefore automatically pick up the
// libc.a symbols because liblibc is transitively linked to by the stdlib.
#[cfg(all(target_env = "musl", not(feature = "cargo-build"), not(test)))]
#[link(name = "c", kind = "static")]
extern {}