Skip to content

Commit efa3c27

Browse files
committed
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
2 parents 16e356e + 0caa251 commit efa3c27

File tree

8 files changed

+40
-9
lines changed

8 files changed

+40
-9
lines changed

src/bootstrap/test.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,10 @@ impl Step for CrateRustdoc {
18701870
cargo.arg("--");
18711871
cargo.args(&builder.config.cmd.test_args());
18721872

1873+
if self.host.contains("musl") {
1874+
cargo.arg("'-Ctarget-feature=-crt-static'");
1875+
}
1876+
18731877
if !builder.config.verbose_tests {
18741878
cargo.arg("--quiet");
18751879
}

src/ci/docker/dist-x86_64-musl/Dockerfile

+3-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ COPY scripts/musl-toolchain.sh /build/
2323
# We need to mitigate rust-lang/rust#34978 when compiling musl itself as well
2424
RUN CFLAGS="-Wa,-mrelax-relocations=no -Wa,--compress-debug-sections=none -Wl,--compress-debug-sections=none" \
2525
CXXFLAGS="-Wa,-mrelax-relocations=no -Wa,--compress-debug-sections=none -Wl,--compress-debug-sections=none" \
26-
bash musl-toolchain.sh x86_64 && rm -rf build
26+
REPLACE_CC=1 bash musl-toolchain.sh x86_64 && rm -rf build
2727

2828
COPY scripts/sccache.sh /scripts/
2929
RUN sh /scripts/sccache.sh
@@ -35,10 +35,7 @@ ENV RUST_CONFIGURE_ARGS \
3535
--enable-extended \
3636
--disable-docs \
3737
--set target.x86_64-unknown-linux-musl.crt-static=false \
38-
--build $HOSTS \
39-
--set target.x86_64-unknown-linux-musl.cc=x86_64-linux-musl-gcc \
40-
--set target.x86_64-unknown-linux-musl.cxx=x86_64-linux-musl-g++ \
41-
--set target.x86_64-unknown-linux-musl.linker=x86_64-linux-musl-gcc
38+
--build $HOSTS
4239

4340
# Newer binutils broke things on some vms/distros (i.e., linking against
4441
# unknown relocs disabled by the following flag), so we need to go out of our
@@ -49,4 +46,5 @@ ENV RUST_CONFIGURE_ARGS \
4946
ENV CFLAGS_x86_64_unknown_linux_musl="-Wa,-mrelax-relocations=no -Wa,--compress-debug-sections=none \
5047
-Wl,--compress-debug-sections=none"
5148

49+
# To run native tests replace `dist` below with `test`
5250
ENV SCRIPT python2.7 ../x.py dist --build $HOSTS

src/ci/docker/scripts/musl-toolchain.sh

+9
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ cd -
4545
ln -s $OUTPUT/$TARGET/lib/libc.so /lib/ld-musl-$ARCH.so.1
4646
echo $OUTPUT/$TARGET/lib >> /etc/ld-musl-$ARCH.path
4747

48+
# Now when musl bootstraps itself create proper toolchain symlinks to make build and tests easier
49+
if [ "$REPLACE_CC" = "1" ]; then
50+
for exec in cc gcc; do
51+
ln -s $TARGET-gcc /usr/local/bin/$exec
52+
done
53+
for exec in cpp c++ g++; do
54+
ln -s $TARGET-g++ /usr/local/bin/$exec
55+
done
56+
fi
4857

4958
export CC=$TARGET-gcc
5059
export CXX=$TARGET-g++

src/test/run-make-fulldeps/link-cfg/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
all: $(call DYLIB,return1) $(call DYLIB,return2) $(call NATIVE_STATICLIB,return3)
44
ls $(TMPDIR)
5-
$(RUSTC) --print cfg --target x86_64-unknown-linux-musl | $(CGREP) crt-static
5+
$(BARE_RUSTC) --print cfg --target x86_64-unknown-linux-musl | $(CGREP) crt-static
66

77
$(RUSTC) no-deps.rs --cfg foo
88
$(call RUN,no-deps)

src/test/run-make-fulldeps/linker-output-non-utf8/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ all:
2020
$(RUSTC) library.rs
2121
mkdir $(bad_dir)
2222
mv $(TMPDIR)/liblibrary.a $(bad_dir)
23-
LIBRARY_PATH=$(bad_dir) $(RUSTC) exec.rs 2>&1 | $(CGREP) this_symbol_not_defined
23+
$(RUSTC) -L $(bad_dir) exec.rs 2>&1 | $(CGREP) this_symbol_not_defined

src/test/run-make-fulldeps/reproducible-build/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
-include ../tools.mk
2+
3+
# ignore-musl
4+
# Objects are reproducible but their path is not.
5+
26
all: \
37
smoke \
48
debug \

src/test/run-make/rustc-macro-dep-files/Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
# FIXME(eddyb) provide `HOST_RUSTC` and `TARGET_RUSTC`
44
# instead of hardcoding them everywhere they're needed.
5+
ifeq ($(IS_MUSL_HOST),1)
6+
ADDITIONAL_ARGS := $(RUSTFLAGS)
7+
endif
58
all:
6-
$(BARE_RUSTC) foo.rs --out-dir $(TMPDIR)
9+
$(BARE_RUSTC) $(ADDITIONAL_ARGS) foo.rs --out-dir $(TMPDIR)
710
$(RUSTC) bar.rs --target $(TARGET) --emit dep-info
811
$(CGREP) -v "proc-macro source" < $(TMPDIR)/bar.d

src/tools/compiletest/src/runtest.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,9 @@ impl<'test> TestCx<'test> {
16501650
(true, None)
16511651
} else if self.config.target.contains("cloudabi")
16521652
|| self.config.target.contains("emscripten")
1653-
|| (self.config.target.contains("musl") && !aux_props.force_host)
1653+
|| (self.config.target.contains("musl")
1654+
&& !aux_props.force_host
1655+
&& !self.config.host.contains("musl"))
16541656
|| self.config.target.contains("wasm32")
16551657
|| self.config.target.contains("nvptx")
16561658
{
@@ -1932,6 +1934,11 @@ impl<'test> TestCx<'test> {
19321934
}
19331935
}
19341936

1937+
// Use dynamic musl for tests because static doesn't allow creating dylibs
1938+
if self.config.host.contains("musl") {
1939+
rustc.arg("-Ctarget-feature=-crt-static");
1940+
}
1941+
19351942
rustc.args(&self.props.compile_flags);
19361943

19371944
rustc
@@ -2725,6 +2732,12 @@ impl<'test> TestCx<'test> {
27252732
// compiler flags set in the test cases:
27262733
cmd.env_remove("RUSTFLAGS");
27272734

2735+
// Use dynamic musl for tests because static doesn't allow creating dylibs
2736+
if self.config.host.contains("musl") {
2737+
cmd.env("RUSTFLAGS", "-Ctarget-feature=-crt-static")
2738+
.env("IS_MUSL_HOST", "1");
2739+
}
2740+
27282741
if self.config.target.contains("msvc") && self.config.cc != "" {
27292742
// We need to pass a path to `lib.exe`, so assume that `cc` is `cl.exe`
27302743
// and that `lib.exe` lives next to it.

0 commit comments

Comments
 (0)