From f74debbe7d2bf43171270d5f3f5b42f2cc2e6243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Thu, 2 May 2019 17:22:14 +0200 Subject: [PATCH 1/2] Make tests compatible with musl host --- src/bootstrap/test.rs | 4 ++++ src/ci/docker/dist-x86_64-musl/Dockerfile | 6 ++---- src/ci/docker/scripts/musl-toolchain.sh | 7 +++++++ src/test/run-make-fulldeps/link-cfg/Makefile | 2 +- .../linker-output-non-utf8/Makefile | 2 +- .../run-make-fulldeps/reproducible-build/Makefile | 4 ++++ src/test/run-make/rustc-macro-dep-files/Makefile | 5 ++++- src/tools/compiletest/src/runtest.rs | 15 ++++++++++++++- 8 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index a3d96836aad..9867113e48f 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1870,6 +1870,10 @@ impl Step for CrateRustdoc { cargo.arg("--"); cargo.args(&builder.config.cmd.test_args()); + if self.host.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 39ad785b41a..bc3a3bd6fbc 100644 --- a/src/ci/docker/dist-x86_64-musl/Dockerfile +++ b/src/ci/docker/dist-x86_64-musl/Dockerfile @@ -35,10 +35,7 @@ ENV RUST_CONFIGURE_ARGS \ --enable-extended \ --disable-docs \ --set target.x86_64-unknown-linux-musl.crt-static=false \ - --build $HOSTS \ - --set target.x86_64-unknown-linux-musl.cc=x86_64-linux-musl-gcc \ - --set target.x86_64-unknown-linux-musl.cxx=x86_64-linux-musl-g++ \ - --set target.x86_64-unknown-linux-musl.linker=x86_64-linux-musl-gcc + --build $HOSTS # Newer binutils broke things on some vms/distros (i.e., linking against # unknown relocs disabled by the following flag), so we need to go out of our @@ -49,4 +46,5 @@ ENV RUST_CONFIGURE_ARGS \ ENV CFLAGS_x86_64_unknown_linux_musl="-Wa,-mrelax-relocations=no -Wa,--compress-debug-sections=none \ -Wl,--compress-debug-sections=none" +# To run native tests replace `dist` below with `test` ENV SCRIPT python2.7 ../x.py dist --build $HOSTS diff --git a/src/ci/docker/scripts/musl-toolchain.sh b/src/ci/docker/scripts/musl-toolchain.sh index 8cdbfebea4d..e132615738b 100644 --- a/src/ci/docker/scripts/musl-toolchain.sh +++ b/src/ci/docker/scripts/musl-toolchain.sh @@ -45,6 +45,13 @@ cd - ln -s $OUTPUT/$TARGET/lib/libc.so /lib/ld-musl-$ARCH.so.1 echo $OUTPUT/$TARGET/lib >> /etc/ld-musl-$ARCH.path +# Now when musl bootstraps itself create proper toolchain symlinks to make build and tests easier +for exec in cc gcc; do + ln -s $TARGET-gcc /usr/local/bin/$exec +done +for exec in cpp c++ g++; do + ln -s $TARGET-g++ /usr/local/bin/$exec +done export CC=$TARGET-gcc export CXX=$TARGET-g++ diff --git a/src/test/run-make-fulldeps/link-cfg/Makefile b/src/test/run-make-fulldeps/link-cfg/Makefile index 188cba5fe41..2701b4a593c 100644 --- a/src/test/run-make-fulldeps/link-cfg/Makefile +++ b/src/test/run-make-fulldeps/link-cfg/Makefile @@ -2,7 +2,7 @@ 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 + $(BARE_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 3fffd1e7aa2..b47ce17ec8b 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 ca76a5e5d77..a17ec212cfd 100644 --- a/src/test/run-make-fulldeps/reproducible-build/Makefile +++ b/src/test/run-make-fulldeps/reproducible-build/Makefile @@ -1,4 +1,8 @@ -include ../tools.mk + +# ignore-musl +# Objects are reproducible but their path is not. + 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 0420a389168..a08a63fb44b 100644 --- a/src/test/run-make/rustc-macro-dep-files/Makefile +++ b/src/test/run-make/rustc-macro-dep-files/Makefile @@ -2,7 +2,10 @@ # FIXME(eddyb) provide `HOST_RUSTC` and `TARGET_RUSTC` # instead of hardcoding them everywhere they're needed. +ifeq ($(IS_MUSL_HOST),1) +ADDITIONAL_ARGS := $(RUSTFLAGS) +endif all: - $(BARE_RUSTC) foo.rs --out-dir $(TMPDIR) + $(BARE_RUSTC) $(ADDITIONAL_ARGS) 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 3689946c055..10b8133326b 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1650,7 +1650,9 @@ impl<'test> TestCx<'test> { (true, 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("musl") + && !aux_props.force_host + && !self.config.host.contains("musl")) || self.config.target.contains("wasm32") || self.config.target.contains("nvptx") { @@ -1932,6 +1934,11 @@ impl<'test> TestCx<'test> { } } + // Use dynamic musl for tests because static doesn't allow creating dylibs + if self.config.host.contains("musl") { + rustc.arg("-Ctarget-feature=-crt-static"); + } + rustc.args(&self.props.compile_flags); rustc @@ -2725,6 +2732,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.host.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. From 0caa251da2d7272fdecb32aae6e0a9e1c3ec0756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Fri, 10 May 2019 16:12:32 +0200 Subject: [PATCH 2/2] Conditionally provide cc in musl-toolchain.sh --- src/ci/docker/dist-x86_64-musl/Dockerfile | 2 +- src/ci/docker/scripts/musl-toolchain.sh | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ci/docker/dist-x86_64-musl/Dockerfile b/src/ci/docker/dist-x86_64-musl/Dockerfile index bc3a3bd6fbc..385eefde846 100644 --- a/src/ci/docker/dist-x86_64-musl/Dockerfile +++ b/src/ci/docker/dist-x86_64-musl/Dockerfile @@ -23,7 +23,7 @@ COPY scripts/musl-toolchain.sh /build/ # We need to mitigate rust-lang/rust#34978 when compiling musl itself as well RUN CFLAGS="-Wa,-mrelax-relocations=no -Wa,--compress-debug-sections=none -Wl,--compress-debug-sections=none" \ CXXFLAGS="-Wa,-mrelax-relocations=no -Wa,--compress-debug-sections=none -Wl,--compress-debug-sections=none" \ - bash musl-toolchain.sh x86_64 && rm -rf build + REPLACE_CC=1 bash musl-toolchain.sh x86_64 && rm -rf build COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh diff --git a/src/ci/docker/scripts/musl-toolchain.sh b/src/ci/docker/scripts/musl-toolchain.sh index e132615738b..d5988a25671 100644 --- a/src/ci/docker/scripts/musl-toolchain.sh +++ b/src/ci/docker/scripts/musl-toolchain.sh @@ -46,12 +46,14 @@ ln -s $OUTPUT/$TARGET/lib/libc.so /lib/ld-musl-$ARCH.so.1 echo $OUTPUT/$TARGET/lib >> /etc/ld-musl-$ARCH.path # Now when musl bootstraps itself create proper toolchain symlinks to make build and tests easier -for exec in cc gcc; do - ln -s $TARGET-gcc /usr/local/bin/$exec -done -for exec in cpp c++ g++; do - ln -s $TARGET-g++ /usr/local/bin/$exec -done +if [ "$REPLACE_CC" = "1" ]; then + for exec in cc gcc; do + ln -s $TARGET-gcc /usr/local/bin/$exec + done + for exec in cpp c++ g++; do + ln -s $TARGET-g++ /usr/local/bin/$exec + done +fi export CC=$TARGET-gcc export CXX=$TARGET-g++