Skip to content

Add x86_64-unknown-linux-musl build support #1517

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ matrix:
- { <<: *linux, env: SKIP_TESTS=1 TARGET=mips64-unknown-linux-gnuabi64 }
- { <<: *linux, env: SKIP_TESTS=1 TARGET=mips64el-unknown-linux-gnuabi64 }
- { <<: *linux, env: SKIP_TESTS=1 TARGET=s390x-unknown-linux-gnu }
- { os: linux, env: SKIP_TESTS=1 TARGET=x86_64-unknown-linux-musl }
- { <<: *linux, env: SKIP_TESTS=1 TARGET=arm-linux-androideabi }
- { <<: *linux, env: SKIP_TESTS=1 TARGET=armv7-linux-androideabi }
- { <<: *linux, env: SKIP_TESTS=1 TARGET=aarch64-linux-android }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ platform of your choice:
- [x86_64-pc-windows-msvc](https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe)<sup>[†](#vs2019)</sup>
- [x86_64-unknown-freebsd](https://static.rust-lang.org/rustup/dist/x86_64-unknown-freebsd/rustup-init)
- [x86_64-unknown-linux-gnu](https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init)
- [x86_64-unknown-linux-musl](https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-musl/rustup-init)
- [x86_64-unknown-netbsd](https://static.rust-lang.org/rustup/dist/x86_64-unknown-netbsd/rustup-init)

<a name="vs2019">†</a>
Expand Down
13 changes: 13 additions & 0 deletions ci/docker/x86_64-unknown-linux-musl/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ubuntu:18.04

RUN apt-get update && apt-get install -y \
musl-dev \
musl-tools \
curl \
ca-certificates \
perl \
make \
gcc

RUN curl -L https://github.com/mozilla/sccache/releases/download/0.2.8/sccache-0.2.8-x86_64-unknown-linux-musl.tar.gz | tar xzf - \
&& mv ./sccache-0.2.8-x86_64-unknown-linux-musl/sccache /usr/bin/sccache && rm -rf ./sccache-0.2.8-x86_64-unknown-linux-musl
8 changes: 6 additions & 2 deletions rustup-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,18 @@ get_endianness() {
}

get_architecture() {
local _ostype _cputype _bitness _arch
local _ostype _cputype _bitness _arch _clibtype
_ostype="$(uname -s)"
_cputype="$(uname -m)"
_clibtype="gnu"

if [ "$_ostype" = Linux ]; then
if [ "$(uname -o)" = Android ]; then
_ostype=Android
fi
if [ "$(ldd --version 2>&1 | grep 'musl')" ]; then
_clibtype="musl"
fi
fi

if [ "$_ostype" = Darwin ] && [ "$_cputype" = i386 ]; then
Expand All @@ -187,7 +191,7 @@ get_architecture() {
;;

Linux)
_ostype=unknown-linux-gnu
_ostype=unknown-linux-$_clibtype
_bitness=$(get_bitness)
;;

Expand Down
9 changes: 8 additions & 1 deletion src/dist/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ static LIST_ENVS: &[&str] = &[
"musl",
];

// Linux hosts don't indicate clib in uname, however binaries only
// run on boxes with the same clib, as expected.
#[cfg(all(not(windows), not(target_env = "musl")))]
const TRIPLE_X86_64_UNKNOWN_LINUX: &str = "x86_64-unknown-linux-gnu";
#[cfg(all(not(windows), target_env = "musl"))]
const TRIPLE_X86_64_UNKNOWN_LINUX: &str = "x86_64-unknown-linux-musl";

// MIPS platforms don't indicate endianness in uname, however binaries only
// run on boxes with the same endianness, as expected.
// Hence we could distinguish between the variants with compile-time cfg()
Expand Down Expand Up @@ -175,7 +182,7 @@ impl TargetTriple {
(_, b"aarch64") if cfg!(target_os = "android") => Some("aarch64-linux-android"),
(_, b"i686") if cfg!(target_os = "android") => Some("i686-linux-android"),
(_, b"x86_64") if cfg!(target_os = "android") => Some("x86_64-linux-android"),
(b"Linux", b"x86_64") => Some("x86_64-unknown-linux-gnu"),
(b"Linux", b"x86_64") => Some(TRIPLE_X86_64_UNKNOWN_LINUX),
(b"Linux", b"i686") => Some("i686-unknown-linux-gnu"),
(b"Linux", b"mips") => Some(TRIPLE_MIPS_UNKNOWN_LINUX_GNU),
(b"Linux", b"mips64") => Some(TRIPLE_MIPS64_UNKNOWN_LINUX_GNUABI64),
Expand Down