From 8389c0bec8d25a1c42ec32b14ba51e43b10fbd8a Mon Sep 17 00:00:00 2001 From: JonathanS Date: Wed, 17 Oct 2018 22:13:21 +0200 Subject: [PATCH 01/18] 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 06f8a2fbba83..e6ffac401994 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 be62a60bbd3990bacbab6c3ad2afe8d18c01d040 Mon Sep 17 00:00:00 2001 From: JonathanS Date: Wed, 17 Oct 2018 22:14:27 +0200 Subject: [PATCH 02/18] 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 7985b6c0e191..cab6eed2d2a8 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-6.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 ac95b8b556712417c60c12ec8f8396a7b168e507 Mon Sep 17 00:00:00 2001 From: Jonathan Sieber Date: Thu, 18 Oct 2018 21:47:26 +0200 Subject: [PATCH 03/18] 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 e6ffac401994..441c2e7c57a0 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 fc3db7024103e143660a049a9d54d57e9f9fdc6a Mon Sep 17 00:00:00 2001 From: Jonathan Sieber Date: Fri, 19 Oct 2018 19:04:33 +0000 Subject: [PATCH 04/18] 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 441c2e7c57a0..2f538a28b436 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 000000000000..db609a8666f3 --- /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 f997cd27edee6f458561e5cfba4be31636c88d3b Mon Sep 17 00:00:00 2001 From: Jonathan Sieber Date: Fri, 19 Oct 2018 20:28:34 +0000 Subject: [PATCH 05/18] 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 db609a8666f3..0406d5182e8f 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 b1fa7f6a272e9217cfe4eaf114b7f14b301a98b7 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sun, 16 Sep 2018 16:40:04 +0000 Subject: [PATCH 06/18] 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 bac41a7c5790..d103c6020a79 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1602,7 +1602,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 @@ -1610,10 +1609,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 91429cec7b6ea9ad243ac61e2511ad7fe0e5bca4 Mon Sep 17 00:00:00 2001 From: Jonathan Sieber Date: Tue, 27 Nov 2018 20:56:34 +0100 Subject: [PATCH 07/18] 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 0406d5182e8f..25781c747493 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 b4c1df03451e9ffc6be58ef43cbf890a0bc6968f Mon Sep 17 00:00:00 2001 From: Martell Malone Date: Sat, 5 Jan 2019 12:59:46 -0800 Subject: [PATCH 08/18] Address review comments --- src/ci/docker/scripts/musl-toolchain.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ci/docker/scripts/musl-toolchain.sh b/src/ci/docker/scripts/musl-toolchain.sh index 25781c747493..11954b82b844 100644 --- a/src/ci/docker/scripts/musl-toolchain.sh +++ b/src/ci/docker/scripts/musl-toolchain.sh @@ -41,7 +41,7 @@ cd musl-cross-make hide_output make -j$(nproc) TARGET=$TARGET hide_output make install TARGET=$TARGET OUTPUT=$OUTPUT -cd .. +cd - # Make musl binaries executable @@ -72,5 +72,5 @@ cmake ../libunwind-release_$LLVM \ hide_output make -j$(nproc) cp lib/libunwind.a $OUTPUT/$TARGET/lib -cd ../ && rm -rf libunwind-build +cd - && rm -rf libunwind-build From 979c744faf0eddcad9c8011ff7b30a95b868b7d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Fri, 11 Jan 2019 18:45:37 +0100 Subject: [PATCH 09/18] musl: update LLVM to 7 --- src/ci/docker/scripts/musl-toolchain.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/scripts/musl-toolchain.sh b/src/ci/docker/scripts/musl-toolchain.sh index 11954b82b844..45bca4bfdfe4 100644 --- a/src/ci/docker/scripts/musl-toolchain.sh +++ b/src/ci/docker/scripts/musl-toolchain.sh @@ -52,7 +52,7 @@ echo $OUTPUT/$TARGET/lib >> /etc/ld-musl-$ARCH.path export CC=$TARGET-gcc export CXX=$TARGET-g++ -LLVM=60 +LLVM=70 # may have been downloaded in a previous run if [ ! -d libunwind-release_$LLVM ]; then From e359a23a1a1c37050b12b216c52ecb2ce7a9eb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Fri, 11 Jan 2019 18:52:52 +0100 Subject: [PATCH 10/18] musl: tests workaround --- src/tools/compiletest/src/runtest.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index d103c6020a79..b4c0f142448a 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1842,7 +1842,10 @@ impl<'test> TestCx<'test> { None => {} } - if self.props.force_host { + // Musl toolchain is build on linux-gnu host + // but with proper setup it can behave almost* like native linux-musl. + // One difference is "cc" which will link to glibc; force musl cc. + if self.props.force_host && !self.config.target.contains("musl") { self.maybe_add_external_args(&mut rustc, self.split_maybe_args(&self.config.host_rustcflags)); } else { @@ -1855,6 +1858,11 @@ impl<'test> TestCx<'test> { } } + // Use dynamic musl for tests because static doesn't allow creating dylibs + if self.config.target.contains("musl") { + rustc.arg("-Ctarget-feature=-crt-static"); + } + rustc.args(&self.props.compile_flags); rustc From e9dd3ed0db924f120df024720525793ee3107a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Sat, 10 Feb 2018 14:03:13 +0100 Subject: [PATCH 11/18] Drop copyright notice --- src/ci/docker/scripts/musl-toolchain.sh | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/ci/docker/scripts/musl-toolchain.sh b/src/ci/docker/scripts/musl-toolchain.sh index 45bca4bfdfe4..00b6a113da10 100644 --- a/src/ci/docker/scripts/musl-toolchain.sh +++ b/src/ci/docker/scripts/musl-toolchain.sh @@ -1,13 +1,3 @@ -# 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() { From f59deb2851976ef5a7c3128f0a52d085276d26d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 28 Feb 2019 18:45:14 +0100 Subject: [PATCH 12/18] WIP: musl hacks to make tests pass --- src/bootstrap/test.rs | 7 ++++- src/test/run-make-fulldeps/link-cfg/Makefile | 5 +++- .../linker-output-non-utf8/Makefile | 2 +- .../reproducible-build/Makefile | 7 +++++ .../run-make/rustc-macro-dep-files/Makefile | 6 ++++- src/tools/compiletest/src/runtest.rs | 26 ++++++++++++++++--- 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 51412f79c3d0..ba8dd2e9e897 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1636,8 +1636,9 @@ impl Step for Crate { // libstd, then what we're actually testing is the libstd produced in // stage1. Reflect that here by updating the compiler that we're working // with automatically. + // FIXME(mati865): do similar for the other branch if this is correct let compiler = if builder.force_use_stage1(compiler, target) { - builder.compiler(1, compiler.host) + builder.compiler(1, builder.config.build) } else { compiler.clone() }; @@ -1802,6 +1803,10 @@ impl Step for CrateRustdoc { cargo.arg("--"); cargo.args(&builder.config.cmd.test_args()); + if target.contains("musl") { + cargo.arg("'-Ctarget-feature=-crt-static'"); + } + if !builder.config.verbose_tests { cargo.arg("--quiet"); } diff --git a/src/test/run-make-fulldeps/link-cfg/Makefile b/src/test/run-make-fulldeps/link-cfg/Makefile index 188cba5fe412..034108d2a7d6 100644 --- a/src/test/run-make-fulldeps/link-cfg/Makefile +++ b/src/test/run-make-fulldeps/link-cfg/Makefile @@ -2,7 +2,10 @@ all: $(call DYLIB,return1) $(call DYLIB,return2) $(call NATIVE_STATICLIB,return3) ls $(TMPDIR) - $(RUSTC) --print cfg --target x86_64-unknown-linux-musl | $(CGREP) crt-static + + ifneq ($(IS_MUSL_HOST),1) + $(RUSTC) --print cfg --target x86_64-unknown-linux-musl | $(CGREP) crt-static + endif $(RUSTC) no-deps.rs --cfg foo $(call RUN,no-deps) diff --git a/src/test/run-make-fulldeps/linker-output-non-utf8/Makefile b/src/test/run-make-fulldeps/linker-output-non-utf8/Makefile index 3fffd1e7aa2a..b47ce17ec8ba 100644 --- a/src/test/run-make-fulldeps/linker-output-non-utf8/Makefile +++ b/src/test/run-make-fulldeps/linker-output-non-utf8/Makefile @@ -20,4 +20,4 @@ all: $(RUSTC) library.rs mkdir $(bad_dir) mv $(TMPDIR)/liblibrary.a $(bad_dir) - LIBRARY_PATH=$(bad_dir) $(RUSTC) exec.rs 2>&1 | $(CGREP) this_symbol_not_defined + $(RUSTC) -L $(bad_dir) exec.rs 2>&1 | $(CGREP) this_symbol_not_defined diff --git a/src/test/run-make-fulldeps/reproducible-build/Makefile b/src/test/run-make-fulldeps/reproducible-build/Makefile index ca76a5e5d77b..0a15c1d7eb9e 100644 --- a/src/test/run-make-fulldeps/reproducible-build/Makefile +++ b/src/test/run-make-fulldeps/reproducible-build/Makefile @@ -1,4 +1,11 @@ -include ../tools.mk + +# ignore-musl +# +# diff: +# -/checkout/obj/build/x86_64-unknown-linux-musl/test/run-make-fulldeps/reproducible-build/reproducible-build/rustcORhwur/libunwind-cfdf9e23c318976b.rlib: 6220632559893696134 +# +/checkout/obj/build/x86_64-unknown-linux-musl/test/run-make-fulldeps/reproducible-build/reproducible-build/rustcMaw0kI/libunwind-cfdf9e23c318976b.rlib: 6220632559893696134 + all: \ smoke \ debug \ diff --git a/src/test/run-make/rustc-macro-dep-files/Makefile b/src/test/run-make/rustc-macro-dep-files/Makefile index 0420a389168f..0e162c89d936 100644 --- a/src/test/run-make/rustc-macro-dep-files/Makefile +++ b/src/test/run-make/rustc-macro-dep-files/Makefile @@ -3,6 +3,10 @@ # FIXME(eddyb) provide `HOST_RUSTC` and `TARGET_RUSTC` # instead of hardcoding them everywhere they're needed. all: - $(BARE_RUSTC) foo.rs --out-dir $(TMPDIR) + ifeq ($(IS_MUSL_HOST),1) + $(BARE_RUSTC) $(RUSTFLAGS) -Clinker=$(RUSTC_LINKER) foo.rs --out-dir $(TMPDIR) + else + $(BARE_RUSTC) foo.rs --out-dir $(TMPDIR) + endif $(RUSTC) bar.rs --target $(TARGET) --emit dep-info $(CGREP) -v "proc-macro source" < $(TMPDIR)/bar.d diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index b4c0f142448a..898bd0e4aff7 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1845,9 +1845,14 @@ impl<'test> TestCx<'test> { // Musl toolchain is build on linux-gnu host // but with proper setup it can behave almost* like native linux-musl. // One difference is "cc" which will link to glibc; force musl cc. - if self.props.force_host && !self.config.target.contains("musl") { + if self.props.force_host { self.maybe_add_external_args(&mut rustc, self.split_maybe_args(&self.config.host_rustcflags)); + if self.config.target.contains("musl") { + if let Some(ref linker) = self.config.linker { + rustc.arg(format!("-Clinker={}", linker)); + } + } } else { self.maybe_add_external_args(&mut rustc, self.split_maybe_args(&self.config.target_rustcflags)); @@ -1855,6 +1860,10 @@ impl<'test> TestCx<'test> { if let Some(ref linker) = self.config.linker { rustc.arg(format!("-Clinker={}", linker)); } + } else if self.config.target.contains("musl") { + if let Some(ref linker) = self.config.linker { + rustc.arg(format!("--linker={}", linker)); + } } } @@ -2646,6 +2655,12 @@ impl<'test> TestCx<'test> { // compiler flags set in the test cases: cmd.env_remove("RUSTFLAGS"); + // Use dynamic musl for tests because static doesn't allow creating dylibs + if self.config.target.contains("musl") { + cmd.env("RUSTFLAGS", "-Ctarget-feature=-crt-static") + .env("IS_MUSL_HOST", "1"); + } + if self.config.target.contains("msvc") && self.config.cc != "" { // We need to pass a path to `lib.exe`, so assume that `cc` is `cl.exe` // and that `lib.exe` lives next to it. @@ -2668,8 +2683,13 @@ impl<'test> TestCx<'test> { .env("CC", format!("'{}' {}", self.config.cc, cflags)) .env("CXX", format!("'{}'", &self.config.cxx)); } else { - cmd.env("CC", format!("{} {}", self.config.cc, self.config.cflags)) - .env("CXX", format!("{} {}", self.config.cxx, self.config.cflags)) + let cflags = if self.config.target.contains("musl") { + self.config.cflags.replace("-static", "") + } else { + self.config.cflags.to_string() + }; + cmd.env("CC", format!("{} {}", self.config.cc, cflags)) + .env("CXX", format!("{} {}", self.config.cxx, cflags)) .env("AR", &self.config.ar); if self.config.target.contains("windows") { From ce2baa7d0f45983d720f7660edb4d2252e10b05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Mon, 4 Mar 2019 13:56:14 +0100 Subject: [PATCH 13/18] simplify link-cfg workaround --- src/test/run-make-fulldeps/link-cfg/Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/run-make-fulldeps/link-cfg/Makefile b/src/test/run-make-fulldeps/link-cfg/Makefile index 034108d2a7d6..e884c5f2ee0e 100644 --- a/src/test/run-make-fulldeps/link-cfg/Makefile +++ b/src/test/run-make-fulldeps/link-cfg/Makefile @@ -3,9 +3,7 @@ all: $(call DYLIB,return1) $(call DYLIB,return2) $(call NATIVE_STATICLIB,return3) ls $(TMPDIR) - ifneq ($(IS_MUSL_HOST),1) - $(RUSTC) --print cfg --target x86_64-unknown-linux-musl | $(CGREP) crt-static - endif + $(BARE_RUSTC) --print cfg --target x86_64-unknown-linux-musl | $(CGREP) crt-static $(RUSTC) no-deps.rs --cfg foo $(call RUN,no-deps) From f57df5579ef6f9a36ae8209cf0cd9fcf69a89b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Mon, 4 Mar 2019 14:00:05 +0100 Subject: [PATCH 14/18] Disable relax relocations again --- src/ci/docker/dist-x86_64-musl/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/dist-x86_64-musl/Dockerfile b/src/ci/docker/dist-x86_64-musl/Dockerfile index 2f538a28b436..8cae26f1ac39 100644 --- a/src/ci/docker/dist-x86_64-musl/Dockerfile +++ b/src/ci/docker/dist-x86_64-musl/Dockerfile @@ -38,7 +38,7 @@ 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 \ From ec42123e386a0e3a6bda65040d5814c96db9da8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 7 Mar 2019 22:25:45 +0100 Subject: [PATCH 15/18] disable tests --- src/ci/docker/dist-x86_64-musl/Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ci/docker/dist-x86_64-musl/Dockerfile b/src/ci/docker/dist-x86_64-musl/Dockerfile index 8cae26f1ac39..e2e7645316c3 100644 --- a/src/ci/docker/dist-x86_64-musl/Dockerfile +++ b/src/ci/docker/dist-x86_64-musl/Dockerfile @@ -49,6 +49,4 @@ 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 +ENV SCRIPT python2.7 ../x.py dist --host $HOSTS --target $HOSTS From c1010883d5ce355f9119c05cf6bc8f03ed1e8b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Fri, 8 Mar 2019 16:49:40 +0100 Subject: [PATCH 16/18] Temporary revert all tests workarounds and run tests with gnu host --- src/bootstrap/test.rs | 7 +--- src/ci/docker/dist-x86_64-musl/Dockerfile | 4 +- src/test/run-make-fulldeps/link-cfg/Makefile | 3 +- .../linker-output-non-utf8/Makefile | 2 +- .../reproducible-build/Makefile | 7 ---- .../run-make/rustc-macro-dep-files/Makefile | 6 +-- src/tools/compiletest/src/runtest.rs | 39 ++++--------------- 7 files changed, 14 insertions(+), 54 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index ba8dd2e9e897..51412f79c3d0 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1636,9 +1636,8 @@ impl Step for Crate { // libstd, then what we're actually testing is the libstd produced in // stage1. Reflect that here by updating the compiler that we're working // with automatically. - // FIXME(mati865): do similar for the other branch if this is correct let compiler = if builder.force_use_stage1(compiler, target) { - builder.compiler(1, builder.config.build) + builder.compiler(1, compiler.host) } else { compiler.clone() }; @@ -1803,10 +1802,6 @@ impl Step for CrateRustdoc { cargo.arg("--"); cargo.args(&builder.config.cmd.test_args()); - if target.contains("musl") { - cargo.arg("'-Ctarget-feature=-crt-static'"); - } - if !builder.config.verbose_tests { cargo.arg("--quiet"); } diff --git a/src/ci/docker/dist-x86_64-musl/Dockerfile b/src/ci/docker/dist-x86_64-musl/Dockerfile index e2e7645316c3..4d5ccf18501d 100644 --- a/src/ci/docker/dist-x86_64-musl/Dockerfile +++ b/src/ci/docker/dist-x86_64-musl/Dockerfile @@ -49,4 +49,6 @@ ENV HOSTS=x86_64-unknown-linux-musl \ ENV RUSTFLAGS="-C target-feature=-crt-static" -ENV SCRIPT python2.7 ../x.py dist --host $HOSTS --target $HOSTS +ENV SCRIPT \ + python2.7 ../x.py test --target $HOSTS && \ + python2.7 ../x.py dist --host $HOSTS --target $HOSTS diff --git a/src/test/run-make-fulldeps/link-cfg/Makefile b/src/test/run-make-fulldeps/link-cfg/Makefile index e884c5f2ee0e..188cba5fe412 100644 --- a/src/test/run-make-fulldeps/link-cfg/Makefile +++ b/src/test/run-make-fulldeps/link-cfg/Makefile @@ -2,8 +2,7 @@ all: $(call DYLIB,return1) $(call DYLIB,return2) $(call NATIVE_STATICLIB,return3) ls $(TMPDIR) - - $(BARE_RUSTC) --print cfg --target x86_64-unknown-linux-musl | $(CGREP) crt-static + $(RUSTC) --print cfg --target x86_64-unknown-linux-musl | $(CGREP) crt-static $(RUSTC) no-deps.rs --cfg foo $(call RUN,no-deps) diff --git a/src/test/run-make-fulldeps/linker-output-non-utf8/Makefile b/src/test/run-make-fulldeps/linker-output-non-utf8/Makefile index b47ce17ec8ba..3fffd1e7aa2a 100644 --- a/src/test/run-make-fulldeps/linker-output-non-utf8/Makefile +++ b/src/test/run-make-fulldeps/linker-output-non-utf8/Makefile @@ -20,4 +20,4 @@ all: $(RUSTC) library.rs mkdir $(bad_dir) mv $(TMPDIR)/liblibrary.a $(bad_dir) - $(RUSTC) -L $(bad_dir) exec.rs 2>&1 | $(CGREP) this_symbol_not_defined + LIBRARY_PATH=$(bad_dir) $(RUSTC) exec.rs 2>&1 | $(CGREP) this_symbol_not_defined diff --git a/src/test/run-make-fulldeps/reproducible-build/Makefile b/src/test/run-make-fulldeps/reproducible-build/Makefile index 0a15c1d7eb9e..ca76a5e5d77b 100644 --- a/src/test/run-make-fulldeps/reproducible-build/Makefile +++ b/src/test/run-make-fulldeps/reproducible-build/Makefile @@ -1,11 +1,4 @@ -include ../tools.mk - -# ignore-musl -# -# diff: -# -/checkout/obj/build/x86_64-unknown-linux-musl/test/run-make-fulldeps/reproducible-build/reproducible-build/rustcORhwur/libunwind-cfdf9e23c318976b.rlib: 6220632559893696134 -# +/checkout/obj/build/x86_64-unknown-linux-musl/test/run-make-fulldeps/reproducible-build/reproducible-build/rustcMaw0kI/libunwind-cfdf9e23c318976b.rlib: 6220632559893696134 - all: \ smoke \ debug \ diff --git a/src/test/run-make/rustc-macro-dep-files/Makefile b/src/test/run-make/rustc-macro-dep-files/Makefile index 0e162c89d936..0420a389168f 100644 --- a/src/test/run-make/rustc-macro-dep-files/Makefile +++ b/src/test/run-make/rustc-macro-dep-files/Makefile @@ -3,10 +3,6 @@ # FIXME(eddyb) provide `HOST_RUSTC` and `TARGET_RUSTC` # instead of hardcoding them everywhere they're needed. all: - ifeq ($(IS_MUSL_HOST),1) - $(BARE_RUSTC) $(RUSTFLAGS) -Clinker=$(RUSTC_LINKER) foo.rs --out-dir $(TMPDIR) - else - $(BARE_RUSTC) foo.rs --out-dir $(TMPDIR) - endif + $(BARE_RUSTC) foo.rs --out-dir $(TMPDIR) $(RUSTC) bar.rs --target $(TARGET) --emit dep-info $(CGREP) -v "proc-macro source" < $(TMPDIR)/bar.d diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 898bd0e4aff7..bac41a7c5790 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1602,6 +1602,7 @@ 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 @@ -1609,8 +1610,10 @@ 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 Emscripten, however, there is no support for - // dynamic libraries so we just go back to building a normal library. + // 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. Some("lib") } else { Some("dylib") @@ -1842,17 +1845,9 @@ impl<'test> TestCx<'test> { None => {} } - // Musl toolchain is build on linux-gnu host - // but with proper setup it can behave almost* like native linux-musl. - // One difference is "cc" which will link to glibc; force musl cc. if self.props.force_host { self.maybe_add_external_args(&mut rustc, self.split_maybe_args(&self.config.host_rustcflags)); - if self.config.target.contains("musl") { - if let Some(ref linker) = self.config.linker { - rustc.arg(format!("-Clinker={}", linker)); - } - } } else { self.maybe_add_external_args(&mut rustc, self.split_maybe_args(&self.config.target_rustcflags)); @@ -1860,18 +1855,9 @@ impl<'test> TestCx<'test> { if let Some(ref linker) = self.config.linker { rustc.arg(format!("-Clinker={}", linker)); } - } else if self.config.target.contains("musl") { - if let Some(ref linker) = self.config.linker { - rustc.arg(format!("--linker={}", linker)); - } } } - // Use dynamic musl for tests because static doesn't allow creating dylibs - if self.config.target.contains("musl") { - rustc.arg("-Ctarget-feature=-crt-static"); - } - rustc.args(&self.props.compile_flags); rustc @@ -2655,12 +2641,6 @@ impl<'test> TestCx<'test> { // compiler flags set in the test cases: cmd.env_remove("RUSTFLAGS"); - // Use dynamic musl for tests because static doesn't allow creating dylibs - if self.config.target.contains("musl") { - cmd.env("RUSTFLAGS", "-Ctarget-feature=-crt-static") - .env("IS_MUSL_HOST", "1"); - } - if self.config.target.contains("msvc") && self.config.cc != "" { // We need to pass a path to `lib.exe`, so assume that `cc` is `cl.exe` // and that `lib.exe` lives next to it. @@ -2683,13 +2663,8 @@ impl<'test> TestCx<'test> { .env("CC", format!("'{}' {}", self.config.cc, cflags)) .env("CXX", format!("'{}'", &self.config.cxx)); } else { - let cflags = if self.config.target.contains("musl") { - self.config.cflags.replace("-static", "") - } else { - self.config.cflags.to_string() - }; - cmd.env("CC", format!("{} {}", self.config.cc, cflags)) - .env("CXX", format!("{} {}", self.config.cxx, cflags)) + cmd.env("CC", format!("{} {}", self.config.cc, self.config.cflags)) + .env("CXX", format!("{} {}", self.config.cxx, self.config.cflags)) .env("AR", &self.config.ar); if self.config.target.contains("windows") { From c5612cbf67675b8daf881b63806043f9b07c4f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Tue, 12 Mar 2019 17:15:03 +0100 Subject: [PATCH 17/18] Move testing to test-various --- src/ci/docker/dist-x86_64-musl/Dockerfile | 9 ++++----- src/ci/docker/test-various/Dockerfile | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/ci/docker/dist-x86_64-musl/Dockerfile b/src/ci/docker/dist-x86_64-musl/Dockerfile index 4d5ccf18501d..543b9377357f 100644 --- a/src/ci/docker/dist-x86_64-musl/Dockerfile +++ b/src/ci/docker/dist-x86_64-musl/Dockerfile @@ -22,8 +22,9 @@ WORKDIR /build/ COPY scripts/musl-toolchain.sh /build/ # We need to mitigate rust-lang/rust#34978 when compiling musl itself as well # TODO: Check what this issue is and if we can ignore it - -RUN bash musl-toolchain.sh x86_64-linux-musl && rm -rf build +RUN CFLAGS="-Wa,-mrelax-relocations=no" \ + CXXFLAGS="-Wa,-mrelax-relocations=no" \ + bash musl-toolchain.sh x86_64-linux-musl && rm -rf build COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh @@ -49,6 +50,4 @@ ENV HOSTS=x86_64-unknown-linux-musl \ ENV RUSTFLAGS="-C target-feature=-crt-static" -ENV SCRIPT \ - python2.7 ../x.py test --target $HOSTS && \ - python2.7 ../x.py dist --host $HOSTS --target $HOSTS +ENV SCRIPT python2.7 ../x.py dist --host $HOSTS --target $HOSTS diff --git a/src/ci/docker/test-various/Dockerfile b/src/ci/docker/test-various/Dockerfile index 6c419e13c9f0..f70ea9da92e7 100644 --- a/src/ci/docker/test-various/Dockerfile +++ b/src/ci/docker/test-various/Dockerfile @@ -11,7 +11,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ cmake \ sudo \ gdb \ - xz-utils + xz-utils \ + # for musl + wget \ + patch # FIXME: build the `ptx-linker` instead. RUN curl -sL https://github.com/denzp/rust-ptx-linker/releases/download/v0.9.0-alpha.2/rust-ptx-linker.linux64.tar.gz | \ @@ -20,10 +23,18 @@ RUN curl -sL https://github.com/denzp/rust-ptx-linker/releases/download/v0.9.0-a RUN curl -sL https://nodejs.org/dist/v9.2.0/node-v9.2.0-linux-x64.tar.xz | \ tar -xJ +WORKDIR /build/ +COPY scripts/musl-toolchain.sh /build/ +RUN CFLAGS="-Wa,-mrelax-relocations=no" \ + CXXFLAGS="-Wa,-mrelax-relocations=no" \ + bash musl-toolchain.sh x86_64-linux-musl && rm -rf build +WORKDIR / + COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh ENV RUST_CONFIGURE_ARGS \ + --musl-root-x86_64=/usr/local/x86_64-linux-musl \ --set build.nodejs=/node-v9.2.0-linux-x64/bin/node \ --set rust.lld @@ -47,4 +58,9 @@ ENV NVPTX_TARGETS=nvptx64-nvidia-cuda ENV NVPTX_SCRIPT python2.7 /checkout/x.py test --target $NVPTX_TARGETS \ src/test/run-make -ENV SCRIPT $WASM_SCRIPT && $NVPTX_SCRIPT +ENV MUSL_TARGETS=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 MUSL_SCRIPT python2.7 /checkout/x.py test --target $MUSL_TARGETS + +ENV SCRIPT $WASM_SCRIPT && $NVPTX_SCRIPT && $MUSL_SCRIPT From 987ac7c9251c987a676dd23f45ec4d4a05557501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Tue, 12 Mar 2019 17:15:54 +0100 Subject: [PATCH 18/18] DELETE_ME: run test-various on try --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cab6eed2d2a8..b9f6dd8144f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -169,7 +169,7 @@ matrix: - env: IMAGE=i686-gnu-nopt if: branch = auto - env: IMAGE=test-various - if: branch = auto + if: branch = try OR branch = auto - env: IMAGE=x86_64-gnu if: branch = auto - env: IMAGE=x86_64-gnu-full-bootstrap