Repository: cross-rs/cross
Pull request #776 (2022-06-09 21:32:42)

Bug fix for dragonfly and CI tests.
Added `build-std` flag to CI, so for targets that support `std` but are tier 3 targets, we can use the experimental `build-std` support to ensure they build. Also patches linking on dragonfly to ensure we use `libgcc_s` instead of `libgcc_pic`, which no longer exists. We just create a symlink for that purpose.

Necessary to merge #775.

Alexhuszagh: bors try --target *-dragonfly
bors[bot]: ## try

Build succeeded:
  * [conclusion](https://github.com/cross-rs/cross/runs/6821592236?check_suite_focus=true)
Emilgardis: it's not working
Alexhuszagh: Checking it, yeah don't merge it yet.
Alexhuszagh: Ok I think I've fixed everything. I've just changed the logic so instead of `cross`, we use `${CROSS[@]}` and `"${CROSS_FLAGS[@]}"` everywhere, which then sets the toolchain version and if we need `-Zbuild-std`. It works locally on my machine.

bors try --target x86_64-unknown-dragonfly --target arm-unknown-linux-gnueabihf --target thumbv6m-none-eabi
Emilgardis: im not a fan of this, instead I think it'd suffice if we make https://github.com/cross-rs/cross/blob/ee2fc1b55d3e5fd4aee37d3ce3ffa88016fd26cc/src/lib.rs#L352-L354 actually properly determine if build-std is needed, and then provide the needed flags if possible. Obviously, that's a bigger change than this simple fix, but I think that's the long-term solution, especially if we add more t3 targets to be "builtins"
Alexhuszagh: > im not a fan of this, instead I think it'd suffice if we make
> 
> https://github.com/cross-rs/cross/blob/ee2fc1b55d3e5fd4aee37d3ce3ffa88016fd26cc/src/lib.rs#L352-L354
> actually properly determine if build-std is needed, and then provide the needed flags if possible. Obviously, that's a bigger change than this simple fix, but I think that's the long-term solution, especially if we add more t3 targets to be "builtins"

Probably a more logical solution, should I incorporate this into this PR then? It's probably better to have this logic outside our test suite for sure.
Emilgardis: I'm fine with merging this already or with the suggested "real" fix. 
bors[bot]: ## try

Build succeeded:
  * [conclusion](https://github.com/cross-rs/cross/runs/6822218949?check_suite_focus=true)
bors[bot]: This PR was included in a batch that was canceled, it will be automatically retried
Emilgardis: bors r-
bors[bot]: Canceled.

Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f049d76..5a7f7c0 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -176,7 +176,7 @@ jobs:
             # Disabled for now, see https://github.com/rust-lang/rust/issues/85821
             #- { target: asmjs-unknown-emscripten,         os: ubuntu-latest,  cpp: 1,           std: 1, run: 1 }
             #- { target: wasm32-unknown-emscripten,        os: ubuntu-latest,  cpp: 1,           std: 1, run: 1 }
-            - { target: x86_64-unknown-dragonfly,         os: ubuntu-latest,  cpp: 1, dylib: 1 }
+            - { target: x86_64-unknown-dragonfly,         os: ubuntu-latest,  cpp: 1, dylib: 1, std: 1, build-std: 1 }
             - { target: i686-unknown-freebsd,             os: ubuntu-latest,          dylib: 1, std: 1 }
             - { target: x86_64-unknown-freebsd,           os: ubuntu-latest,          dylib: 1, std: 1 }
             - { target: x86_64-unknown-netbsd,            os: ubuntu-latest,  cpp: 1, dylib: 1, std: 1 }
@@ -243,6 +243,7 @@ jobs:
           CPP: ${{ matrix.cpp }}
           DYLIB: ${{ matrix.dylib }}
           STD: ${{ matrix.std }}
+          BUILD_STD: ${{ matrix.build-std }}
           RUN: ${{ matrix.run }}
           RUNNERS: ${{ matrix.runners }}
         shell: bash
diff --git a/docker/dragonfly.sh b/docker/dragonfly.sh
index 2ccf371..167aff4 100755
--- a/docker/dragonfly.sh
+++ b/docker/dragonfly.sh
@@ -134,6 +134,11 @@ EOF
     make install
     cd ..
 
+    # rust incorrectly adds link args to libgcc_pic, which is no longer
+    # a present target, and it should link to libgcc_s.
+    # https://github.com/rust-lang/rust/blob/60361f2/library/unwind/build.rs#L23-L38
+    ln -s "${destdir}"/lib/libgcc_s.so "${destdir}"/lib/libgcc_pic.so
+
     # clean up
     popd
 


Test patch:
diff --git a/ci/test.sh b/ci/test.sh
index 207c95d..d47a52a 100755
--- a/ci/test.sh
+++ b/ci/test.sh
@@ -1,8 +1,13 @@
 #!/usr/bin/env bash
+# shellcheck disable=SC2086
 
 set -x
 set -euo pipefail
 
+# NOTE: "${@}" is an unbound variable for bash 3.2, which is the
+# installed version on macOS. likewise, "${var[@]}" is an unbound
+# error if var is an empty array.
+
 function retry {
   local tries="${TRIES-5}"
   local timeout="${TIMEOUT-1}"
@@ -26,11 +31,10 @@ function retry {
 }
 
 workspace_test() {
-  # "${@}" is an unbound variable for bash 3.2, which is the installed version on macOS
-  cross build --target "${TARGET}" --workspace "$@"
-  cross run --target "${TARGET}" -p binary "$@"
-  cross run --target "${TARGET}" --bin dependencies \
-    --features=dependencies "$@"
+  "${CROSS[@]}" build --target "${TARGET}" --workspace "$@" ${CROSS_FLAGS}
+  "${CROSS[@]}" run --target "${TARGET}" -p binary "$@" ${CROSS_FLAGS}
+  "${CROSS[@]}" run --target "${TARGET}" --bin dependencies \
+    --features=dependencies "$@" ${CROSS_FLAGS}
 }
 
 main() {
@@ -41,13 +45,28 @@ main() {
 
     export QEMU_STRACE=1
 
+    # ensure we have the proper toolchain and optional rust flags
+    export CROSS=(cross)
+    export CROSS_FLAGS=""
+    if (( ${BUILD_STD:-0} )); then
+        # use build-std instead of xargo, due to xargo being
+        # maintenance-only. build-std requires a nightly compiler
+        rustup toolchain add nightly
+        CROSS_FLAGS="${CROSS_FLAGS} -Zbuild-std"
+        CROSS+=("+nightly")
+    elif ! (( ${STD:-0} )); then
+        # don't use xargo: should have native support just from rustc
+        rustup toolchain add nightly
+        CROSS+=("+nightly")
+    fi
+
     if (( ${STD:-0} )); then
         # test `cross check`
         td=$(mktemp -d)
         cargo init --lib --name foo "${td}"
         pushd "${td}"
         echo '#![no_std]' > src/lib.rs
-        cross check --target "${TARGET}"
+        "${CROSS[@]}" check --target "${TARGET}" ${CROSS_FLAGS}
         popd
         rm -rf "${td}"
     else
@@ -60,12 +79,10 @@ main() {
             https://github.com/rust-lang-nursery/compiler-builtins "${td}"
 
         pushd "${td}"
-        cat > Cross.toml <<EOF
-[build]
-xargo = true
-EOF
         retry cargo fetch
-        cross build --lib --target "${TARGET}"
+        # don't use xargo: should have native support just from rustc
+        rustup toolchain add nightly
+        "${CROSS[@]}" build --lib --target "${TARGET}" ${CROSS_FLAGS}
         popd
 
         rm -rf "${td}"
@@ -80,7 +97,7 @@ EOF
         pushd "${td}"
         cargo init --lib --name foo .
         retry cargo fetch
-        cross build --target "${TARGET}"
+        "${CROSS[@]}" build --target "${TARGET}" ${CROSS_FLAGS}
         popd
 
         rm -rf "${td}"
@@ -91,7 +108,7 @@ EOF
         # test that linking works
         cargo init --bin --name hello .
         retry cargo fetch
-        cross build --target "${TARGET}"
+        "${CROSS[@]}" build --target "${TARGET}" ${CROSS_FLAGS}
         popd
 
         rm -rf "${td}"
@@ -154,7 +171,7 @@ EOF
                 pushd "workspace"
                 TARGET="${TARGET}" workspace_test
                 pushd "binary"
-                cross run --target "${TARGET}"
+                "${CROSS[@]}" run --target "${TARGET}" ${CROSS_FLAGS}
                 popd
                 popd
                 popd
@@ -174,7 +191,7 @@ EOF
         if (( ${RUN:-0} )); then
             cross_run --target "${TARGET}"
         else
-            cross build --target "${TARGET}"
+            "${CROSS[@]}" build --target "${TARGET}" ${CROSS_FLAGS}
         fi
         popd
 
@@ -184,33 +201,33 @@ EOF
 
 cross_run() {
     if [[ -z "${RUNNERS:-}" ]]; then
-        cross run "$@"
+        "${CROSS[@]}" run "$@" ${CROSS_FLAGS}
     else
         for runner in ${RUNNERS}; do
             echo -e "[target.${TARGET}]\nrunner = \"${runner}\"" > Cross.toml
-            cross run "$@"
+            "${CROSS[@]}" run "$@" ${CROSS_FLAGS}
         done
     fi
 }
 
 cross_test() {
     if [[ -z "${RUNNERS:-}" ]]; then
-        cross test "$@"
+        "${CROSS[@]}" test "$@" ${CROSS_FLAGS}
     else
         for runner in ${RUNNERS}; do
             echo -e "[target.${TARGET}]\nrunner = \"${runner}\"" > Cross.toml
-            cross test "$@"
+            "${CROSS[@]}" test "$@" ${CROSS_FLAGS}
         done
     fi
 }
 
 cross_bench() {
     if [[ -z "${RUNNERS:-}" ]]; then
-        cross bench "$@"
+        "${CROSS[@]}" bench "$@" ${CROSS_FLAGS}
     else
         for runner in ${RUNNERS}; do
             echo -e "[target.${TARGET}]\nrunner = \"${runner}\"" > Cross.toml
-            cross bench "$@"
+            "${CROSS[@]}" bench "$@" ${CROSS_FLAGS}
         done
     fi
 }