From 45498595162abe0b25808b3cf7261935a18adc6d Mon Sep 17 00:00:00 2001 From: Martell Malone Date: Tue, 25 Sep 2018 23:33:07 -0700 Subject: [PATCH] Add x86_64-unknown-linux-musl build support --- .travis.yml | 1 + README.md | 1 + ci/docker/x86_64-unknown-linux-musl/Dockerfile | 11 +++++++++++ rustup-init.sh | 8 ++++++-- src/dist/dist.rs | 8 +++++++- 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 ci/docker/x86_64-unknown-linux-musl/Dockerfile diff --git a/.travis.yml b/.travis.yml index 0eca5248be6..778d8263c32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,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 } + - { <<: *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 } diff --git a/README.md b/README.md index 7ed933ed1df..cf2da074010 100644 --- a/README.md +++ b/README.md @@ -659,6 +659,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)[†](#vs2015) - [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) diff --git a/ci/docker/x86_64-unknown-linux-musl/Dockerfile b/ci/docker/x86_64-unknown-linux-musl/Dockerfile new file mode 100644 index 00000000000..f7a4e9f8e62 --- /dev/null +++ b/ci/docker/x86_64-unknown-linux-musl/Dockerfile @@ -0,0 +1,11 @@ +FROM alpine:3.9 + +RUN apk update && \ + apk add \ + curl \ + ca-certificates \ + perl \ + make \ + gcc + +ENV CC_x86_64_unknown_linux_musl=gcc diff --git a/rustup-init.sh b/rustup-init.sh index 0df9fc3f844..db13870db27 100755 --- a/rustup-init.sh +++ b/rustup-init.sh @@ -172,14 +172,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 @@ -196,7 +200,7 @@ get_architecture() { ;; Linux) - _ostype=unknown-linux-gnu + _ostype=unknown-linux-$_clibtype _bitness=$(get_bitness) ;; diff --git a/src/dist/dist.rs b/src/dist/dist.rs index 3cc5d5a8fe8..fc3c067eeb2 100644 --- a/src/dist/dist.rs +++ b/src/dist/dist.rs @@ -95,6 +95,12 @@ static LIST_ENVS: &'static [&'static str] = &[ "musl", ]; +// MUSL and GNU targets are both linux +#[cfg(not(target_env="musl"))] +const TRIPLE_X86_64_UNKNOWN_LINUX: &'static str = "x86_64-unknown-linux-gnu"; +#[cfg(target_env="musl")] +const TRIPLE_X86_64_UNKNOWN_LINUX: &'static 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() @@ -175,7 +181,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),