From cafc01e94f7d52dcde53ec45a4affc4dfddf0fba Mon Sep 17 00:00:00 2001 From: JonathanS Date: Wed, 17 Oct 2018 22:13:21 +0200 Subject: [PATCH 01/10] Enable dist-x86_64-musl as a host architexture --- src/ci/docker/dist-x86_64-musl/Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ci/docker/dist-x86_64-musl/Dockerfile b/src/ci/docker/dist-x86_64-musl/Dockerfile index 06f8a2fbba836..e6ffac4019946 100644 --- a/src/ci/docker/dist-x86_64-musl/Dockerfile +++ b/src/ci/docker/dist-x86_64-musl/Dockerfile @@ -41,6 +41,8 @@ ENV RUST_CONFIGURE_ARGS \ # See: https://github.com/rust-lang/rust/issues/34978 ENV CFLAGS_x86_64_unknown_linux_musl=-Wa,-mrelax-relocations=no +ENV HOSTS=x86_64-unknown-linux-musl + ENV SCRIPT \ - python2.7 ../x.py test --target x86_64-unknown-linux-musl && \ - python2.7 ../x.py dist --target x86_64-unknown-linux-musl + python2.7 ../x.py test --host $HOSTS --target $HOSTS && \ + python2.7 ../x.py dist --host $HOSTS --target $HOSTS From cb823dfe4c3fec96497649fc273b8b538045ea7c Mon Sep 17 00:00:00 2001 From: JonathanS Date: Wed, 17 Oct 2018 22:14:27 +0200 Subject: [PATCH 02/10] throwaway commit: Test Travis build only on x86_64 musl --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 14fb17aeeddca..2024d46c40940 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ matrix: include: # Images used in testing PR and try-build should be run first. - env: IMAGE=x86_64-gnu-llvm-5.0 RUST_BACKTRACE=1 - if: type = pull_request OR branch = auto + if: branch = auto - env: IMAGE=dist-x86_64-linux DEPLOY=1 if: branch = try OR branch = auto @@ -159,7 +159,7 @@ matrix: - env: IMAGE=dist-x86_64-freebsd DEPLOY=1 if: branch = auto - env: IMAGE=dist-x86_64-musl DEPLOY=1 - if: branch = auto +# if: branch = auto - env: IMAGE=dist-x86_64-netbsd DEPLOY=1 if: branch = auto - env: IMAGE=asmjs @@ -185,7 +185,7 @@ matrix: - env: IMAGE=x86_64-gnu-distcheck if: branch = auto - env: IMAGE=mingw-check - if: type = pull_request OR branch = auto + if: branch = auto - stage: publish toolstate if: branch = master AND type = push From e52ea151b4cff9ea69512b4c46842a95c4ed56d6 Mon Sep 17 00:00:00 2001 From: Jonathan Sieber Date: Thu, 18 Oct 2018 21:47:26 +0200 Subject: [PATCH 03/10] Set RUSTFLAGS env to make dylib work The musl-target doesn't automatically disable static linking of musl when building a dylib, and then complains it can't build a dylib. As a workaround, disable static linking via RUSTFLAGS, to see how far the build gets. The proper fix is to have rustc figure that out automagically. --- src/ci/docker/dist-x86_64-musl/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ci/docker/dist-x86_64-musl/Dockerfile b/src/ci/docker/dist-x86_64-musl/Dockerfile index e6ffac4019946..441c2e7c57a07 100644 --- a/src/ci/docker/dist-x86_64-musl/Dockerfile +++ b/src/ci/docker/dist-x86_64-musl/Dockerfile @@ -43,6 +43,8 @@ ENV CFLAGS_x86_64_unknown_linux_musl=-Wa,-mrelax-relocations=no ENV HOSTS=x86_64-unknown-linux-musl +ENV RUSTFLAGS="-C target-feature=-crt-static" + ENV SCRIPT \ python2.7 ../x.py test --host $HOSTS --target $HOSTS && \ python2.7 ../x.py dist --host $HOSTS --target $HOSTS From c775e0b79467269d32166e55f6394974fddbb3bb Mon Sep 17 00:00:00 2001 From: Jonathan Sieber Date: Fri, 19 Oct 2018 19:04:33 +0000 Subject: [PATCH 04/10] build a proper c++-enabled musl toolchain with musl-cross-make --- src/ci/docker/dist-x86_64-musl/Dockerfile | 22 ++++---- src/ci/docker/scripts/musl-toolchain.sh | 66 +++++++++++++++++++++++ 2 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 src/ci/docker/scripts/musl-toolchain.sh diff --git a/src/ci/docker/dist-x86_64-musl/Dockerfile b/src/ci/docker/dist-x86_64-musl/Dockerfile index 441c2e7c57a07..2f538a28b4364 100644 --- a/src/ci/docker/dist-x86_64-musl/Dockerfile +++ b/src/ci/docker/dist-x86_64-musl/Dockerfile @@ -4,6 +4,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ g++ \ make \ file \ + wget \ curl \ ca-certificates \ python2.7 \ @@ -18,19 +19,17 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ WORKDIR /build/ -COPY scripts/musl.sh /build/ +COPY scripts/musl-toolchain.sh /build/ # We need to mitigate rust-lang/rust#34978 when compiling musl itself as well -RUN CC=gcc \ - CFLAGS="-Wa,-mrelax-relocations=no" \ - CXX=g++ \ - CXXFLAGS="-Wa,-mrelax-relocations=no" \ - bash musl.sh x86_64 && rm -rf /build +# TODO: Check what this issue is and if we can ignore it + +RUN bash musl-toolchain.sh x86_64-linux-musl && rm -rf build COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh ENV RUST_CONFIGURE_ARGS \ - --musl-root-x86_64=/musl-x86_64 \ + --musl-root-x86_64=/usr/local/x86_64-linux-musl \ --enable-extended \ --disable-docs @@ -39,9 +38,14 @@ ENV RUST_CONFIGURE_ARGS \ # way to produce "super compatible" binaries. # # See: https://github.com/rust-lang/rust/issues/34978 -ENV CFLAGS_x86_64_unknown_linux_musl=-Wa,-mrelax-relocations=no +#ENV CFLAGS_x86_64_unknown_linux_musl=-Wa,-mrelax-relocations=no + +ENV HOSTS=x86_64-unknown-linux-musl \ + CC_x86_64_unknown_linux_musl=x86_64-linux-musl-gcc \ + CXX_x86_64_unknown_linux_musl=x86_64-linux-musl-g++ -ENV HOSTS=x86_64-unknown-linux-musl +# CARGO_TARGET_ARM_UNKNOWN_LINUX_MUSLEABIHF_LINKER=musl-gcc \ +# CARGO_TARGET_ARM_UNKNOWN_LINUX_MUSLEABIHF_RUNNER="qemu-arm -L /musl-arm" ENV RUSTFLAGS="-C target-feature=-crt-static" diff --git a/src/ci/docker/scripts/musl-toolchain.sh b/src/ci/docker/scripts/musl-toolchain.sh new file mode 100644 index 0000000000000..db609a8666f30 --- /dev/null +++ b/src/ci/docker/scripts/musl-toolchain.sh @@ -0,0 +1,66 @@ +# Copyright 2016 The Rust Project Developers. See the COPYRIGHT +# file at the top-level directory of this distribution and at +# http://rust-lang.org/COPYRIGHT. +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +set -ex + +hide_output() { + set +x + on_err=" +echo ERROR: An error was encountered with the build. +cat /tmp/build.log +exit 1 +" + trap "$on_err" ERR + bash -c "while true; do sleep 30; echo \$(date) - building ...; done" & + PING_LOOP_PID=$! + $@ &> /tmp/build.log + trap - ERR + kill $PING_LOOP_PID + rm /tmp/build.log + set -x +} + +TARGET=$1 +OUTPUT=/usr/local +shift + +git clone https://github.com/richfelker/musl-cross-make -b v0.9.7 +cd musl-cross-make + +hide_output make -j$(nproc) TARGET=$TARGET +hide_output make install TARGET=$TARGET OUTPUT=$OUTPUT + +cd .. + +export CC=$TARGET-gcc +export CXX=$TARGET-g++ + +LLVM=60 + +# may have been downloaded in a previous run +if [ ! -d libunwind-release_$LLVM ]; then + curl -L https://github.com/llvm-mirror/llvm/archive/release_$LLVM.tar.gz | tar xzf - + curl -L https://github.com/llvm-mirror/libunwind/archive/release_$LLVM.tar.gz | tar xzf - +fi + +mkdir libunwind-build +cd libunwind-build +cmake ../libunwind-release_$LLVM \ + -DLLVM_PATH=/build/llvm-release_$LLVM \ + -DLIBUNWIND_ENABLE_SHARED=0 \ + -DCMAKE_C_COMPILER=$CC \ + -DCMAKE_CXX_COMPILER=$CXX \ + -DCMAKE_C_FLAGS="$CFLAGS" \ + -DCMAKE_CXX_FLAGS="$CXXFLAGS" + +hide_output make -j$(nproc) +cp lib/libunwind.a $OUTPUT/$TARGET/lib +cd ../ && rm -rf libunwind-build + From 7d21c49d3f9d9d7717df592883402a87f4873e53 Mon Sep 17 00:00:00 2001 From: Jonathan Sieber Date: Fri, 19 Oct 2018 20:28:34 +0000 Subject: [PATCH 05/10] Make the musl dynamic loader known to the system, so it can execute target binaries --- src/ci/docker/scripts/musl-toolchain.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ci/docker/scripts/musl-toolchain.sh b/src/ci/docker/scripts/musl-toolchain.sh index db609a8666f30..0406d5182e8f6 100644 --- a/src/ci/docker/scripts/musl-toolchain.sh +++ b/src/ci/docker/scripts/musl-toolchain.sh @@ -28,6 +28,10 @@ exit 1 } TARGET=$1 +#ARCH=$1 +#TARGET=linux-musl-$ARCH +ARCH=x86_64 + OUTPUT=/usr/local shift @@ -39,6 +43,13 @@ hide_output make install TARGET=$TARGET OUTPUT=$OUTPUT cd .. +# Make musl binaries executable + +ln -s $OUTPUT/$TARGET/lib/ld-musl-$ARCH.so.1 /lib +ln -s $OUTPUT/$TARGET/lib/libc.so /lib +echo $OUTPUT/$TARGET/lib >> /etc/ld-musl-$ARCH.path + + export CC=$TARGET-gcc export CXX=$TARGET-g++ From 19b4bc69a3d9f1131f0e14423a652911a42a3a63 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sun, 16 Sep 2018 16:40:04 +0000 Subject: [PATCH 06/10] runtest: Fix proc-macro tests on musl hosts --- src/tools/compiletest/src/runtest.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 399f9f577edf5..052de384fcf5c 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1582,7 +1582,6 @@ impl<'test> TestCx<'test> { None } else if self.config.target.contains("cloudabi") || self.config.target.contains("emscripten") - || (self.config.target.contains("musl") && !aux_props.force_host) || self.config.target.contains("wasm32") { // We primarily compile all auxiliary libraries as dynamic libraries @@ -1590,10 +1589,8 @@ impl<'test> TestCx<'test> { // for the test suite (otherwise including libstd statically in all // executables takes up quite a bit of space). // - // For targets like MUSL or Emscripten, however, there is no support for - // dynamic libraries so we just go back to building a normal library. Note, - // however, that for MUSL if the library is built with `force_host` then - // it's ok to be a dylib as the host should always support dylibs. + // For targets like Emscripten, however, there is no support for + // dynamic libraries so we just go back to building a normal library. Some("lib") } else { Some("dylib") From 7e984c9ee13b657de8e374297a233cea7d4dc08f Mon Sep 17 00:00:00 2001 From: Jonathan Sieber Date: Tue, 27 Nov 2018 20:56:34 +0100 Subject: [PATCH 07/10] musl-toolchain: fix global lib paths (dont create /lib/libc.so) --- src/ci/docker/scripts/musl-toolchain.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ci/docker/scripts/musl-toolchain.sh b/src/ci/docker/scripts/musl-toolchain.sh index 0406d5182e8f6..25781c747493a 100644 --- a/src/ci/docker/scripts/musl-toolchain.sh +++ b/src/ci/docker/scripts/musl-toolchain.sh @@ -45,8 +45,7 @@ cd .. # Make musl binaries executable -ln -s $OUTPUT/$TARGET/lib/ld-musl-$ARCH.so.1 /lib -ln -s $OUTPUT/$TARGET/lib/libc.so /lib +ln -s $OUTPUT/$TARGET/lib/libc.so /lib/ld-musl-$ARCH.so.1 echo $OUTPUT/$TARGET/lib >> /etc/ld-musl-$ARCH.path From a72cfe2dd5818360884ed504e8c8abaa29aaddef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 6 Dec 2018 15:50:08 +0100 Subject: [PATCH 08/10] musl: enable dynamic linking in the spec --- src/librustc_target/spec/linux_musl_base.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/librustc_target/spec/linux_musl_base.rs b/src/librustc_target/spec/linux_musl_base.rs index c87f14977cb1d..0eb74b782a038 100644 --- a/src/librustc_target/spec/linux_musl_base.rs +++ b/src/librustc_target/spec/linux_musl_base.rs @@ -40,5 +40,13 @@ pub fn opts() -> TargetOptions { // These targets allow the user to choose between static and dynamic linking. base.crt_static_respected = true; + // Defaults for dynamic linking + base.dynamic_linking = true; + base.executables = true; + base.has_elf_tls = true; + base.has_rpath = true; + base.position_independent_executables = true; + base.relro_level = true; + base } From 609afa62a155b3345f1ee8572615d9f7e0d0f71d Mon Sep 17 00:00:00 2001 From: Jonathan Sieber Date: Thu, 6 Dec 2018 20:45:33 +0100 Subject: [PATCH 09/10] fix RelroLevel --- src/librustc_target/spec/linux_musl_base.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_target/spec/linux_musl_base.rs b/src/librustc_target/spec/linux_musl_base.rs index 0eb74b782a038..ec8f245cacf27 100644 --- a/src/librustc_target/spec/linux_musl_base.rs +++ b/src/librustc_target/spec/linux_musl_base.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use spec::{LinkerFlavor, TargetOptions}; +use spec::{LinkerFlavor, TargetOptions, RelroLevel}; pub fn opts() -> TargetOptions { let mut base = super::linux_base::opts(); @@ -46,7 +46,7 @@ pub fn opts() -> TargetOptions { base.has_elf_tls = true; base.has_rpath = true; base.position_independent_executables = true; - base.relro_level = true; + base.relro_level = RelroLevel::Full; base } From a4a325c704c676009b626f7ab5a36ddb3fd944f4 Mon Sep 17 00:00:00 2001 From: Jonathan Sieber Date: Fri, 7 Dec 2018 01:35:18 +0100 Subject: [PATCH 10/10] Revert "Set RUSTFLAGS env to make dylib work" This reverts commit e52ea151b4cff9ea69512b4c46842a95c4ed56d6. --- src/ci/docker/dist-x86_64-musl/Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ci/docker/dist-x86_64-musl/Dockerfile b/src/ci/docker/dist-x86_64-musl/Dockerfile index 2f538a28b4364..dae2b4d10a2e8 100644 --- a/src/ci/docker/dist-x86_64-musl/Dockerfile +++ b/src/ci/docker/dist-x86_64-musl/Dockerfile @@ -47,8 +47,6 @@ ENV HOSTS=x86_64-unknown-linux-musl \ # CARGO_TARGET_ARM_UNKNOWN_LINUX_MUSLEABIHF_LINKER=musl-gcc \ # CARGO_TARGET_ARM_UNKNOWN_LINUX_MUSLEABIHF_RUNNER="qemu-arm -L /musl-arm" -ENV RUSTFLAGS="-C target-feature=-crt-static" - ENV SCRIPT \ python2.7 ../x.py test --host $HOSTS --target $HOSTS && \ python2.7 ../x.py dist --host $HOSTS --target $HOSTS