Auto merge of #60474 - mati865:musl_toolchain, r=alexcrichton

Make tests compatible with musl host

As an alternative to passing explicit linker all over the place I could try linking `cc` to musl gcc since this bootstraps itself.

Assigning for discussion:
r? @alexcrichton
This commit is contained in:
bors 2019-05-12 09:19:28 +00:00
commit efa3c27f0f
8 changed files with 40 additions and 9 deletions

View File

@ -1870,6 +1870,10 @@ impl Step for CrateRustdoc {
cargo.arg("--"); cargo.arg("--");
cargo.args(&builder.config.cmd.test_args()); cargo.args(&builder.config.cmd.test_args());
if self.host.contains("musl") {
cargo.arg("'-Ctarget-feature=-crt-static'");
}
if !builder.config.verbose_tests { if !builder.config.verbose_tests {
cargo.arg("--quiet"); cargo.arg("--quiet");
} }

View File

@ -23,7 +23,7 @@ COPY scripts/musl-toolchain.sh /build/
# We need to mitigate rust-lang/rust#34978 when compiling musl itself as well # 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" \ 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" \ 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/ COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh RUN sh /scripts/sccache.sh
@ -35,10 +35,7 @@ ENV RUST_CONFIGURE_ARGS \
--enable-extended \ --enable-extended \
--disable-docs \ --disable-docs \
--set target.x86_64-unknown-linux-musl.crt-static=false \ --set target.x86_64-unknown-linux-musl.crt-static=false \
--build $HOSTS \ --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
# Newer binutils broke things on some vms/distros (i.e., linking against # 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 # 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 \ ENV CFLAGS_x86_64_unknown_linux_musl="-Wa,-mrelax-relocations=no -Wa,--compress-debug-sections=none \
-Wl,--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 ENV SCRIPT python2.7 ../x.py dist --build $HOSTS

View File

@ -45,6 +45,15 @@ cd -
ln -s $OUTPUT/$TARGET/lib/libc.so /lib/ld-musl-$ARCH.so.1 ln -s $OUTPUT/$TARGET/lib/libc.so /lib/ld-musl-$ARCH.so.1
echo $OUTPUT/$TARGET/lib >> /etc/ld-musl-$ARCH.path echo $OUTPUT/$TARGET/lib >> /etc/ld-musl-$ARCH.path
# Now when musl bootstraps itself create proper toolchain symlinks to make build and tests easier
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 CC=$TARGET-gcc
export CXX=$TARGET-g++ export CXX=$TARGET-g++

View File

@ -2,7 +2,7 @@
all: $(call DYLIB,return1) $(call DYLIB,return2) $(call NATIVE_STATICLIB,return3) all: $(call DYLIB,return1) $(call DYLIB,return2) $(call NATIVE_STATICLIB,return3)
ls $(TMPDIR) 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 $(RUSTC) no-deps.rs --cfg foo
$(call RUN,no-deps) $(call RUN,no-deps)

View File

@ -20,4 +20,4 @@ all:
$(RUSTC) library.rs $(RUSTC) library.rs
mkdir $(bad_dir) mkdir $(bad_dir)
mv $(TMPDIR)/liblibrary.a $(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

View File

@ -1,4 +1,8 @@
-include ../tools.mk -include ../tools.mk
# ignore-musl
# Objects are reproducible but their path is not.
all: \ all: \
smoke \ smoke \
debug \ debug \

View File

@ -2,7 +2,10 @@
# FIXME(eddyb) provide `HOST_RUSTC` and `TARGET_RUSTC` # FIXME(eddyb) provide `HOST_RUSTC` and `TARGET_RUSTC`
# instead of hardcoding them everywhere they're needed. # instead of hardcoding them everywhere they're needed.
ifeq ($(IS_MUSL_HOST),1)
ADDITIONAL_ARGS := $(RUSTFLAGS)
endif
all: 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 $(RUSTC) bar.rs --target $(TARGET) --emit dep-info
$(CGREP) -v "proc-macro source" < $(TMPDIR)/bar.d $(CGREP) -v "proc-macro source" < $(TMPDIR)/bar.d

View File

@ -1650,7 +1650,9 @@ impl<'test> TestCx<'test> {
(true, None) (true, None)
} else if self.config.target.contains("cloudabi") } else if self.config.target.contains("cloudabi")
|| self.config.target.contains("emscripten") || 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("wasm32")
|| self.config.target.contains("nvptx") || 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.args(&self.props.compile_flags);
rustc rustc
@ -2725,6 +2732,12 @@ impl<'test> TestCx<'test> {
// compiler flags set in the test cases: // compiler flags set in the test cases:
cmd.env_remove("RUSTFLAGS"); 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 != "" { 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` // We need to pass a path to `lib.exe`, so assume that `cc` is `cl.exe`
// and that `lib.exe` lives next to it. // and that `lib.exe` lives next to it.