Repository: cross-rs/cross
Pull request #1394 (2023-12-23 17:19:27)

fix mips

Emilgardis: https://github.com/cross-rs/cross/actions/runs/7309556138
Emilgardis: https://github.com/cross-rs/cross/actions/runs/7309567138
Emilgardis: `mips64-unknown-linux-muslabi64` and `mips64el-unknown-linux-muslabi64` both fail with similar error, not sure why the crt is not found

```
exec mips64-linux-musl-gcc crt1.o crti.o crtbegin.o /tmp/rustcdYwR8P/symbols.o /target/mips64-unknown-linux-muslabi64/debug/deps/hello-5bf60b377dad2126.hello.e88678c3ba72d42f-cgu.0.rcgu.o /target/mips64-unknown-linux-muslabi64/debug/deps/hello-5bf60b377dad2126.2dfyjk85w6hfes7y.rcgu.o -Wl,--as-needed -L /target/mips64-unknown-linux-muslabi64/debug/deps -L /target/debug/deps -L /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mips64-unknown-linux-muslabi64/lib -Wl,-Bstatic /target/mips64-unknown-linux-muslabi64/debug/deps/libstd-d3b77a59fc4a4692.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/libpanic_unwind-bd17e36809258b66.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/libobject-c324cc8ae5c8b0fd.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/libmemchr-d2297200f09ebffb.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/libaddr2line-df98f44c6c9bf083.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/libgimli-ef99e9f6f07d70f7.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/librustc_demangle-fdf113e05b6bda0e.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/libstd_detect-00376d04620172bb.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/libhashbrown-ae72689e36c6c38f.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/librustc_std_workspace_alloc-484259eb32fcf99b.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/libminiz_oxide-ad0f123872cb76d5.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/libadler-14be33b389d9a409.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/libunwind-60ed854b6acd3f5d.rlib -lunwind /target/mips64-unknown-linux-muslabi64/debug/deps/libcfg_if-da28e98563d4d896.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/liblibc-68f0059b243ac4f6.rlib -lc /target/mips64-unknown-linux-muslabi64/debug/deps/liballoc-1015b8740106b8ee.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/librustc_std_workspace_core-115450f57a6d633a.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/libcore-55d11291351dd73f.rlib /target/mips64-unknown-linux-muslabi64/debug/deps/libcompiler_builtins-a42345a970f32ae4.rlib -Wl,-Bdynamic -Wl,--eh-frame-hdr -Wl,-z,noexecstack -nostartfiles -L /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mips64-unknown-linux-muslabi64/lib -L /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mips64-unknown-linux-muslabi64/lib/self-contained -o /target/mips64-unknown-linux-muslabi64/debug/deps/hello-5bf60b377dad2126 -Wl,--gc-sections -static -no-pie -Wl,-z,relro,-z,now -nodefaultlibs crtend.o crtn.o
          mips64-linux-musl-gcc: error: crt1.o: No such file or directory
          mips64-linux-musl-gcc: error: crti.o: No such file or directory
          mips64-linux-musl-gcc: error: crtbegin.o: No such file or directory
          mips64-linux-musl-gcc: error: crtend.o: No such file or directory
          mips64-linux-musl-gcc: error: crtn.o: No such file or directory
```

I can't find any existing issue for this, all the .sh file does is workaround https://github.com/rust-lang/compiler-builtins/pull/483 which is not a problem for us in CI
Emilgardis: https://github.com/cross-rs/cross/pull/1346 didn't help :/

Patch:
diff --git a/targets.toml b/targets.toml
index 78bb9c7..117845e 100644
--- a/targets.toml
+++ b/targets.toml
@@ -122,6 +122,7 @@ dylib = true
 std = true
 run = true
 runners = "qemu-user"
+build-std = true
 
 [[target]]
 target = "mipsel-unknown-linux-gnu"
@@ -131,6 +132,7 @@ dylib = true
 std = true
 run = true
 runners = "qemu-user qemu-system"
+build-std = true
 
 [[target]]
 target = "mips64-unknown-linux-gnuabi64"
@@ -139,6 +141,7 @@ cpp = true
 dylib = true
 std = true
 run = true
+build-std = true
 
 [[target]]
 target = "mips64el-unknown-linux-gnuabi64"
@@ -148,6 +151,7 @@ dylib = true
 std = true
 run = true
 runners = "qemu-user qemu-system"
+build-std = true
 
 [[target]]
 target = "mips64-unknown-linux-muslabi64"
@@ -156,6 +160,7 @@ cpp = true
 dylib = true
 std = true
 run = true
+build-std = true
 
 [[target]]
 target = "mips64el-unknown-linux-muslabi64"
@@ -164,6 +169,7 @@ os = "ubuntu-latest"
 cpp = true
 std = true
 run = true
+build-std = true
 
 [[target]]
 target = "powerpc-unknown-linux-gnu"


Test patch:
diff --git a/ci/test.sh b/ci/test.sh
index 27319cc..e41f5ab 100755
--- a/ci/test.sh
+++ b/ci/test.sh
@@ -40,6 +40,10 @@ main() {
         rustup toolchain add nightly
         CROSS_FLAGS="${CROSS_FLAGS} -Zbuild-std"
         CROSS+=("+nightly")
+        if [[ "${TARGET}" == *"mips"* ]]; then
+            # workaround for https://github.com/cross-rs/cross/issues/1322 & https://github.com/rust-lang/rust/issues/108835
+            [[ ! "$RUSTFLAGS" =~ opt-level ]] && export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }-C opt-level=1"
+        fi
     elif ! (( ${STD:-0} )); then
         # don't use xargo: should have native support just from rustc
         rustup toolchain add nightly
@@ -204,7 +208,7 @@ main() {
         pushd "${td}"
         cargo init --bin --name hello .
         retry cargo fetch
-        RUSTFLAGS="-C target-feature=-crt-static" \
+        RUSTFLAGS="$RUSTFLAGS -C target-feature=-crt-static" \
             cross_build --target "${TARGET}"
         popd