Skip to content

Commit

Permalink
WIP: musl hacks to make tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
mati865 committed Feb 28, 2019
1 parent 4ec89ef commit e676f99
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down Expand Up @@ -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");
}
Expand Down
5 changes: 4 additions & 1 deletion src/test/run-make-fulldeps/link-cfg/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make-fulldeps/linker-output-non-utf8/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions src/test/run-make-fulldeps/reproducible-build/Makefile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
6 changes: 5 additions & 1 deletion src/test/run-make/rustc-macro-dep-files/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 23 additions & 3 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1845,16 +1845,25 @@ 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));
if !is_rustdoc {
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));
}
}
}

Expand Down Expand Up @@ -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.
Expand All @@ -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") {
Expand Down

0 comments on commit e676f99

Please sign in to comment.