From e676f99e1373148721565184df1ca1a9b9acba55 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] 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 51412f79c3d0c..ba8dd2e9e8977 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 188cba5fe4127..034108d2a7d6e 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 3fffd1e7aa2a2..b47ce17ec8baa 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 ca76a5e5d77b6..0a15c1d7eb9e0 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 0420a389168f1..0e162c89d936c 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 b4c0f142448af..898bd0e4aff74 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") {