Repository: cross-rs/cross (rust)

Issue:
Setup Fallback Mirrors for `pkg.freebsd.org`
In at least 3 separate workflow runs, we've had failures due to an inability to resolve `pkg.freebsd.org`. Normally, mirrors should be made available based on GeoDNS and [automatically handled](https://forums.freebsd.org/threads/how-to-change-mirror-in-pkg.79991/), however, it might be worth looking up a few and using logic similar in #1132 (specifically, commit aac375abdbcacbf473cad116f7e89c7a5d2396f2) to handle when the default gateway fails, or use other mirrors if possible. Less than ideal, but this might be necessary.

https://github.com/cross-rs/cross/actions/runs/3565770837/jobs/5991488382#step:10:28393
https://github.com/cross-rs/cross/actions/runs/3567054500/jobs/5994404235#step:10:28387
https://github.com/cross-rs/cross/actions/runs/3566358814/jobs/5992830213#step:10:28390

Pull request:
Add package site mirrors for FreeBSD.
Closes #1162.

Patch:
diff --git a/.changes/1057.json b/.changes/1057.json
deleted file mode 100644
index 285dcb9..0000000
--- a/.changes/1057.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
-    "description": "fix mount paths outside of the workspace mount directory on Windows and those provided as a WSL path.",
-    "type": "fixed",
-    "issues": [1145, 1156]
-}
diff --git a/.changes/1164.json b/.changes/1164.json
new file mode 100644
index 0000000..df4b742
--- /dev/null
+++ b/.changes/1164.json
@@ -0,0 +1,5 @@
+{
+    "type": "internal",
+    "description": "add fallback mirrors for FreeBSD packages.",
+    "issues": [1162]
+}
diff --git a/ci/shared.sh b/ci/shared.sh
index be112ab..39f8824 100755
--- a/ci/shared.sh
+++ b/ci/shared.sh
@@ -48,20 +48,3 @@ function mkcargotemp {
     ' > "$CARGO_TMP_DIR"/Cargo.toml
     echo "$td"
 }
-
-function binary_path() {
-    local binary="${1}"
-    local home="${2}"
-    local build_mode="${3}"
-    local cross="${home}/target/${build_mode}/${binary}"
-
-    case "$OSTYPE" in
-        msys*|cygwin*)
-            cross="${cross}.exe"
-            ;;
-        *)
-            ;;
-    esac
-
-    echo "${cross}"
-}
diff --git a/docker/freebsd-common.sh b/docker/freebsd-common.sh
index 315c0f1..f5bf75b 100755
--- a/docker/freebsd-common.sh
+++ b/docker/freebsd-common.sh
@@ -6,57 +6,14 @@ set -euo pipefail
 # shellcheck disable=SC1091
 . freebsd-arch.sh
 
-export BSD_ARCH=
+export FREEBSD_ARCH=
 case "${ARCH}" in
     x86_64)
-        BSD_ARCH=amd64
+        FREEBSD_ARCH=amd64
         ;;
     i686)
-        BSD_ARCH=i386
+        FREEBSD_ARCH=i386
         ;;
 esac
 
-# we prefer those closer in geography to the US. they're triaged in
-# order of ease of use, reliability, and then geography. the mirror
-# list is at https://docs.freebsd.org/en/books/handbook/mirrors/.
-# these mirrors were known to work as of 2022-11-27. this does
-# not include any mirrors that are known to be rate-limited or
-# commercial.
-export BSD_HOME=(
-    # these do not return HTML, and only list the directories
-    "ftp.freebsd.org/pub/FreeBSD/releases"
-    # these return HTML output, and therefore are lower priority
-    "ftp11.freebsd.org/pub/FreeBSD/releases"
-    "ftp3.br.freebsd.org/pub/FreeBSD/releases"
-    "ftp2.uk.freebsd.org/pub/FreeBSD/releases"
-    "ftp2.nl.freebsd.org/pub/FreeBSD/releases"
-    "ftp6.fr.freebsd.org/pub/FreeBSD/releases"
-    "ftp1.de.freebsd.org/pub/FreeBSD/releases"
-    "ftp2.de.freebsd.org/pub/FreeBSD/releases"
-    "ftp5.de.freebsd.org/pub/FreeBSD/releases"
-    "ftp2.ru.freebsd.org/pub/FreeBSD/releases"
-    "ftp2.gr.freebsd.org/pub/FreeBSD/releases"
-    "ftp4.za.freebsd.org/pub/FreeBSD/releases"
-    "ftp2.za.freebsd.org/pub/FreeBSD/releases"
-    "ftp4.tw.freebsd.org/pub/FreeBSD/releases"
-    "ftp3.jp.freebsd.org/pub/FreeBSD/releases"
-    "ftp6.jp.freebsd.org/pub/FreeBSD/releases"
-    # these only support HTTP, and not implicit
-    # FTP as well, and have HTML output
-    "http://ftp.uk.freebsd.org/pub/FreeBSD/releases"
-    "http://ftp.nl.freebsd.org/pub/FreeBSD/releases"
-    "http://ftp.fr.freebsd.org/pub/FreeBSD/releases"
-    "http://ftp.at.freebsd.org/pub/FreeBSD/releases"
-    "http://ftp.dk.freebsd.org/FreeBSD/releases"
-    "http://ftp.cz.freebsd.org/pub/FreeBSD/releases"
-    "http://ftp.se.freebsd.org/pub/FreeBSD/releases"
-    "http://ftp.lv.freebsd.org/freebsd/releases"
-    "http://ftp.pl.freebsd.org/pub/FreeBSD/releases"
-    "http://ftp.ua.freebsd.org/pub/FreeBSD/releases"
-    "http://ftp.gr.freebsd.org/pub/FreeBSD/releases"
-    "http://ftp.ru.freebsd.org/pub/FreeBSD/releases"
-    "http://ftp.nz.freebsd.org/pub/FreeBSD/releases"
-    "http://ftp.kr.freebsd.org/pub/FreeBSD/releases"
-    "http://ftp.jp.freebsd.org/pub/FreeBSD/releases"
-)
-export BSD_MAJOR=12
+export FREEBSD_MAJOR=12
diff --git a/docker/freebsd-extras.sh b/docker/freebsd-extras.sh
index e1d4146..3cf48b9 100755
--- a/docker/freebsd-extras.sh
+++ b/docker/freebsd-extras.sh
@@ -11,8 +11,16 @@ set -euo pipefail
 . freebsd-install.sh
 
 main() {
-    setup_packagesite
-    install_freebsd_package openssl sqlite3
+    apt-get update && apt-get install --assume-yes --no-install-recommends \
+        curl \
+        dnsutils \
+        jq \
+        xz-utils
+
+    local url=
+    url=$(fetch_best_freebsd_mirror)
+    FREEBSD_MIRROR="${url}" setup_freebsd_packagesite
+    FREEBSD_MIRROR="${url}" install_freebsd_package openssl sqlite3
 
     rm "${0}"
 }
diff --git a/docker/freebsd-install.sh b/docker/freebsd-install.sh
index dba0d1d..eb7b304 100755
--- a/docker/freebsd-install.sh
+++ b/docker/freebsd-install.sh
@@ -6,35 +6,147 @@ set -euo pipefail
 # shellcheck disable=SC1091
 . freebsd-common.sh
 
-export PACKAGESITE=/opt/freebsd-packagesite/packagesite.yaml
-export PKG_SOURCE="https://pkg.freebsd.org/FreeBSD:${BSD_MAJOR}:${BSD_ARCH}/quarterly"
-export TARGET="${ARCH}-unknown-freebsd${BSD_MAJOR}"
+# list of SRV records to query if the default mirror fails
+FREEBSD_HTTP_TCP_SOURCES=(
+    # these return all mirrors, including local ones
+    "_http._tcp.pkg.all.freebsd.org"
+    # this only returns geodns mirrors
+    "_http._tcp.pkg.freebsd.org"
+)
+FREEBSD_PACKAGEDIR="/opt/freebsd-packagesite"
+FREEBSD_PACKAGESITE="${FREEBSD_PACKAGEDIR}/packagesite.yaml"
+FREEBSD_TARGET="${ARCH}-unknown-freebsd${FREEBSD_MAJOR}"
+FREEBSD_DEFAULT_MIRROR="pkg.freebsd.org"
+# NOTE: these mirrors were known to work as of 2022-11-28.
+# no availability guarantees are made for any of them.
+FREEBSD_BACKUP_MIRRORS=(
+    "pkg0.syd.freebsd.org"
+    "pkg0.bme.freebsd.org"
+    "pkg0.bra.freebsd.org"
+    "pkg0.fra.freebsd.org"
+    "pkg0.jinx.freebsd.org"
+    "pkg0.kul.freebsd.org"
+    "pkg0.kwc.freebsd.org"
+    "pkg0.nyi.freebsd.org"
+    "pkg0.tuk.freebsd.org"
+    "pkg0.twn.freebsd.org"
+)
 
-setup_packagesite() {
-    apt-get update && apt-get install --assume-yes --no-install-recommends \
-        curl \
-        jq \
-        xz-utils
+# NOTE: out of convention, we use `url` for mirrors with the scheme,
+# and `mirror` for those without the scheme for consistent naming.
+freebsd_package_source() {
+    local url="${1}"
+    echo "${url}/FreeBSD:${FREEBSD_MAJOR}:${FREEBSD_ARCH}/quarterly"
+}
+
+freebsd_mirror_works() {
+    local mirror="${1}"
+    local scheme="${2}"
+    local pkg_source=
+
+    # meta.conf is a small file for quick confirmation the mirror works
+    pkg_source=$(freebsd_package_source "${scheme}://${mirror}")
+    local path="${pkg_source}/meta.conf"
+
+    timeout 20s curl --retry 3 -sSfL "${path}" >/dev/null 2>&1
+}
 
-    mkdir /opt/freebsd-packagesite
-    curl --retry 3 -sSfL "${PKG_SOURCE}/packagesite.txz" -O
-    tar -C /opt/freebsd-packagesite -xJf packagesite.txz
+_fetch_best_freebsd_mirror() {
+    # in case if the default mirror is down, we can use various known
+    # fallbacks, or at worst, SRV fallbacks to find the ideal package
+    # site. no individual mirror other than the default mirror is
+    # guaranteed to exist, so we use a tiered approach. only
+    # the default mirror supports https.
+    if freebsd_mirror_works "${FREEBSD_DEFAULT_MIRROR}" "https"; then
+        echo "https://${FREEBSD_DEFAULT_MIRROR}"
+        return 0
+    fi
+
+    # if we've gotten here, it could be a DNS issue, so using a DNS
+    # resolver to fetch SRV fallbacks may not work. let's first try
+    # a few previously tested mirrors and see if any work.
+    local mirror=
+    for mirror in "${FREEBSD_BACKUP_MIRRORS[@]}"; do
+        if freebsd_mirror_works "${mirror}" "http"; then
+            echo "http://${mirror}"
+            return 0
+        fi
+    done
+
+    local http_tcp_source=
+    local response=
+    local lines=
+    # shellcheck disable=SC2016
+    local regex='/\d+\s+\d+\s+\d+\s+(.*)\./; print $1'
+    for http_tcp_source in "${FREEBSD_HTTP_TCP_SOURCES[@]}"; do
+        # the output will have the following format, but we only want the
+        # target and ignore everything else:
+        #   $priority $port $weight $target.
+        #
+        # some output may not match, so we skip those lines, for example:
+        #   96.47.72.71
+        response=$(dig +short srv "${http_tcp_source}")
+        readarray -t lines <<< "${response}"
+        for line in "${lines[@]}"; do
+            mirror=$(echo "${line}" | perl -nle "${regex}")
+            if [[ -n "${mirror}" ]]; then
+                if freebsd_mirror_works "${mirror}" "http"; then
+                    echo "http://${mirror}"
+                    return 0
+                fi
+            fi
+        done
+    done
+
+    echo -e "\e[31merror:\e[0m could not find a working FreeBSD package mirror." 1>&2
+    exit 1
+}
+
+fetch_best_freebsd_mirror() {
+    set +e
+    _fetch_best_freebsd_mirror
+    code=$?
+    set -e
+
+    return "${code}"
+}
+
+setup_freebsd_packagesite() {
+    local url="${FREEBSD_MIRROR:-}"
+    local pkg_source=
+
+    if [[ -z "${url}" ]]; then
+        url=$(fetch_best_freebsd_mirror)
+    fi
+    pkg_source=$(freebsd_package_source "${url}")
+
+    mkdir -p "${FREEBSD_PACKAGEDIR}"
+    curl --retry 3 -sSfL "${pkg_source}/packagesite.txz" -O
+    tar -C "${FREEBSD_PACKAGEDIR}" -xJf packagesite.txz
 
     rm packagesite.txz
 }
 
+# don't provide the mirror as a positional argument, so it can be optional
 install_freebsd_package() {
+    local url="${FREEBSD_MIRROR:-}"
+    local pkg_source=
     local name
     local path
     local pkg
     local td
-    local destdir="/usr/local/${TARGET}"
+    local destdir="/usr/local/${FREEBSD_TARGET}"
+
+    if [[ -z "${url}" ]]; then
+        url=$(fetch_best_freebsd_mirror)
+    fi
+    pkg_source=$(freebsd_package_source "${url}")
 
     td="$(mktemp -d)"
     pushd "${td}"
 
     for name in "${@}"; do
-        path=$(jq -c '. | select ( .name == "'"${name}"'" ) | .repopath' "${PACKAGESITE}")
+        path=$(jq -c '. | select ( .name == "'"${name}"'" ) | .repopath' "${FREEBSD_PACKAGESITE}")
         if [[ -z "${path}" ]]; then
             echo "Unable to find package ${name}" >&2
             exit 1
@@ -43,7 +155,7 @@ install_freebsd_package() {
         pkg=$(basename "${path}")
 
         mkdir "${td}"/package
-        curl --retry 3 -sSfL "${PKG_SOURCE}/${path}" -O
+        curl --retry 3 -sSfL "${pkg_source}/${path}" -O
         tar -C "${td}/package" -xJf "${pkg}"
         cp -r "${td}/package/usr/local"/* "${destdir}"/
 
diff --git a/docker/freebsd.sh b/docker/freebsd.sh
index 6c9481f..39fe3d6 100755
--- a/docker/freebsd.sh
+++ b/docker/freebsd.sh
@@ -8,6 +8,47 @@ set -euo pipefail
 # shellcheck disable=SC1091
 . lib.sh
 
+# we prefer those closer in geography to the US. they're triaged in
+# order of ease of use, reliability, and then geography. the mirror
+# list is at https://docs.freebsd.org/en/books/handbook/mirrors/.
+# these mirrors were known to work as of 2022-11-27. this does
+# not include any mirrors that are known to be rate-limited or
+# commercial. everything returns HTML output.
+MIRRORS=(
+    # this is a guaranteed mirror, unlike those below.
+    "http://ftp.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp11.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp3.br.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp2.uk.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp2.nl.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp6.fr.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp1.de.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp2.de.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp5.de.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp2.ru.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp2.gr.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp4.za.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp2.za.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp4.tw.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp3.jp.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp6.jp.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp.uk.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp.nl.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp.fr.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp.at.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp.dk.freebsd.org/FreeBSD/releases"
+    "http://ftp.cz.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp.se.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp.lv.freebsd.org/freebsd/releases"
+    "http://ftp.pl.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp.ua.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp.gr.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp.ru.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp.nz.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp.kr.freebsd.org/pub/FreeBSD/releases"
+    "http://ftp.jp.freebsd.org/pub/FreeBSD/releases"
+)
+
 max_freebsd() {
     local best=
     local minor=0
@@ -18,13 +59,13 @@ max_freebsd() {
         version=$(echo "${release}" | cut -d '-' -f 1)
         release_major=$(echo "${version}"| cut -d '.' -f 1)
         release_minor=$(echo "${version}"| cut -d '.' -f 2)
-        if [ "${release_major}" == "${BSD_MAJOR}" ] && [ "${release_minor}" -gt "${minor}" ]; then
+        if [ "${release_major}" == "${FREEBSD_MAJOR}" ] && [ "${release_minor}" -gt "${minor}" ]; then
             best="${release}"
             minor="${release_minor}"
         fi
     done
     if [[ -z "$best" ]]; then
-        echo -e "\e[31merror:\e[0m could not find best release for FreeBSD ${BSD_MAJOR}." 1>&2
+        echo -e "\e[31merror:\e[0m could not find best release for FreeBSD ${FREEBSD_MAJOR}." 1>&2
         exit 1
     fi
     echo "${best}"
@@ -38,9 +79,9 @@ latest_freebsd() {
     local releases=
     local max_release=
 
-    response=$(curl --silent --list-only --location "${mirror}/${BSD_ARCH}/" | grep RELEASE)
+    response=$(curl --retry 3 -sSfL "${mirror}/${FREEBSD_ARCH}/" | grep RELEASE)
     if [[ "${response}" != *RELEASE* ]]; then
-        echo -e "\e[31merror:\e[0m could not find a candidate release for FreeBSD ${BSD_MAJOR}." 1>&2
+        echo -e "\e[31merror:\e[0m could not find a candidate release for FreeBSD ${FREEBSD_MAJOR}." 1>&2
         exit 1
     fi
     readarray -t lines <<< "${response}"
@@ -66,43 +107,45 @@ latest_freebsd() {
     echo "${max_release//-RELEASE/}"
 }
 
-freebsd_mirror() {
-    local home=
+_freebsd_mirror() {
+    local mirror=
     local code=
 
-    set +e
-    for home in "${BSD_HOME[@]}"; do
+    for mirror in "${MIRRORS[@]}"; do
         # we need a timeout in case the server is down to avoid
         # infinitely hanging. timeout error code is always 124
         # these mirrors can be quite slow, so have a long timeout
-        timeout 20s curl --silent --list-only --location "${home}/${BSD_ARCH}/" >/dev/null
+        timeout 20s curl --retry 3 -sSfL "${mirror}/${FREEBSD_ARCH}/" >/dev/null
         code=$?
         if [[ "${code}" == 0 ]]; then
-            echo "${home}"
+            echo "${mirror}"
             return 0
         elif [[ "${code}" != 124 ]]; then
-            echo -e "\e[1;33mwarning:\e[0m mirror ${home} does not seem to work." 1>&2
+            echo -e "\e[1;33mwarning:\e[0m mirror ${mirror} does not seem to work." 1>&2
         fi
     done
-    set -e
 
     echo -e "\e[31merror:\e[0m could not find a working FreeBSD mirror." 1>&2
     exit 1
 }
 
+freebsd_mirror() {
+    set +e
+    _freebsd_mirror
+    code=$?
+    set -e
+
+    return "${code}"
+}
+
 mirror=$(freebsd_mirror)
 base_release=$(latest_freebsd "${mirror}")
-bsd_base_url="${mirror}/${BSD_ARCH}/${base_release}-RELEASE"
-if [[ "${bsd_base_url}" == "http"* ]]; then
-    bsd_url="${bsd_base_url}"
-else
-    bsd_url="http://${bsd_base_url}"
-fi
+bsd_url="${mirror}/${FREEBSD_ARCH}/${base_release}-RELEASE"
 
 main() {
     local binutils=2.32 \
         gcc=6.4.0 \
-        target="${ARCH}-unknown-freebsd${BSD_MAJOR}"
+        target="${ARCH}-unknown-freebsd${FREEBSD_MAJOR}"
 
     install_packages ca-certificates \
         curl \
diff --git a/src/docker/local.rs b/src/docker/local.rs
index 92e9efd..8ecc38a 100644
--- a/src/docker/local.rs
+++ b/src/docker/local.rs
@@ -78,7 +78,6 @@ pub(crate) fn run(
         ])
         // Prevent `bin` from being mounted inside the Docker container.
         .args(["-v", &format!("{}/bin", toolchain_dirs.cargo_mount_path())]);
-
     docker.args([
         "-v",
         &format!(
diff --git a/src/file.rs b/src/file.rs
index 7858285..d2854c8 100644
--- a/src/file.rs
+++ b/src/file.rs
@@ -34,7 +34,7 @@ pub trait PathExt {
 #[cfg(target_family = "windows")]
 fn format_prefix(prefix: &str) -> Result<String> {
     match prefix {
-        "" => Ok("".to_owned()),
+        "" => eyre::bail!("Error: got empty windows prefix"),
         _ => Ok(format!("/mnt/{}", prefix.to_lowercase())),
     }
 }
@@ -196,28 +196,13 @@ fn _canonicalize(path: &Path) -> Result<PathBuf> {
     }
 }
 
-fn is_wsl_absolute(path: &str) -> bool {
-    if !cfg!(target_os = "windows") {
-        return false;
-    }
-    let path = path.strip_prefix("/mnt/").unwrap_or(path);
-    let maybe_drive = path.split_once('/').map_or(path, |x| x.0);
-
-    maybe_drive.len() == 1 && matches!(maybe_drive.chars().next(), Some('a'..='z'))
-}
-
 // Fix for issue #581. target_dir must be absolute.
 pub fn absolute_path(path: impl AsRef<Path>) -> Result<PathBuf> {
-    let as_ref = path.as_ref();
-    Ok(
-        if as_ref.is_absolute()
-            || cfg!(target_family = "windows") && is_wsl_absolute(as_ref.to_utf8()?)
-        {
-            as_ref.to_path_buf()
-        } else {
-            env::current_dir()?.join(path)
-        },
-    )
+    Ok(if path.as_ref().is_absolute() {
+        path.as_ref().to_path_buf()
+    } else {
+        env::current_dir()?.join(path)
+    })
 }
 
 /// Pretty format a file path. Also removes the path prefix from a command if wanted
@@ -334,22 +319,9 @@ mod tests {
         assert!(p!("C:").join("..").as_posix_relative().is_err());
     }
 
-    #[test]
-    #[cfg(target_family = "windows")]
-    fn is_absolute_wslpath() {
-        assert!(is_wsl_absolute("/mnt/c/Users"));
-        assert!(is_wsl_absolute("/mnt/c"));
-        assert!(is_wsl_absolute("/mnt/z/Users"));
-        assert!(!is_wsl_absolute("/mnt"));
-        assert!(!is_wsl_absolute("/mnt/cc"));
-        assert!(!is_wsl_absolute("/mnt/zc"));
-    }
-
     #[test]
     #[cfg(target_family = "windows")]
     fn as_posix_with_drive() {
-        use regex::Regex;
-
         result_eq(p!(r"C:\").as_posix_absolute(), Ok("/mnt/c".to_owned()));
         result_eq(
             p!(r"C:\Users").as_posix_absolute(),
@@ -364,17 +336,6 @@ mod tests {
             p!(r"\\.\C:\Users").as_posix_absolute(),
             Ok("/mnt/c/Users".to_owned()),
         );
-
-        result_eq(
-            p!(r"/mnt/c/Users").as_posix_absolute(),
-            Ok("/mnt/c/Users".to_owned()),
-        );
-        result_eq(p!(r"/mnt/c").as_posix_absolute(), Ok("/mnt/c".to_owned()));
-
-        let regex = Regex::new("/mnt/[A-Za-z]/mnt").unwrap();
-        let result = p!(r"/mnt").as_posix_absolute();
-        assert!(result.is_ok());
-        assert!(regex.is_match(&result.unwrap()));
     }
 
     #[test]


Test patch:
diff --git a/ci/test-bisect.sh b/ci/test-bisect.sh
index 0b847c4..1e1771d 100755
--- a/ci/test-bisect.sh
+++ b/ci/test-bisect.sh
@@ -22,8 +22,7 @@ main() {
     retry cargo fetch
     cargo build
     cargo install cargo-bisect-rustc --debug
-    CROSS=$(binary_path cross "${PROJECT_HOME}" debug)
-    export CROSS
+    export CROSS="${PROJECT_HOME}/target/debug/cross"
 
     td="$(mktemp -d)"
     git clone --depth 1 https://github.com/cross-rs/rust-cpp-hello-word "${td}"
diff --git a/ci/test-foreign-toolchain.sh b/ci/test-foreign-toolchain.sh
index ea5a6c4..2f92fdf 100755
--- a/ci/test-foreign-toolchain.sh
+++ b/ci/test-foreign-toolchain.sh
@@ -15,8 +15,7 @@ main() {
 
     retry cargo fetch
     cargo build
-    CROSS=$(binary_path cross "${PROJECT_HOME}" debug)
-    export CROSS
+    export CROSS="${PROJECT_HOME}/target/debug/cross"
 
     td="$(mkcargotemp -d)"
 
@@ -32,7 +31,7 @@ image.name = "alpine:edge"
 image.toolchain = ["x86_64-unknown-linux-musl"]
 pre-build = ["apk add --no-cache gcc musl-dev"]' >"${CARGO_TMP_DIR}"/Cross.toml
 
-    "${CROSS}" run -v
+    "$CROSS" run -v
 
     local tmp_basename
     tmp_basename=$(basename "${CARGO_TMP_DIR}")
@@ -60,7 +59,7 @@ name = "ubuntu:20.04"
 toolchain = ["aarch64-unknown-linux-gnu"]
     ' >"${CARGO_TMP_DIR}"/Cross.toml
 
-    "${CROSS}" build -v
+    "$CROSS" build -v
 
     "${CROSS_ENGINE}" images --format '{{.Repository}}:{{.Tag}}' --filter 'label=org.cross-rs.for-cross-target' | grep "cross-custom-${tmp_basename}" | xargs "${CROSS_ENGINE}" rmi
 
diff --git a/ci/test-podman.sh b/ci/test-podman.sh
index 4e49f7a..774977c 100755
--- a/ci/test-podman.sh
+++ b/ci/test-podman.sh
@@ -22,8 +22,7 @@ main() {
 
     retry cargo fetch
     cargo build
-    CROSS=$(binary_path cross "${PROJECT_HOME}" debug)
-    export CROSS
+    export CROSS="${PROJECT_HOME}/target/debug/cross"
 
     td="$(mkcargotemp -d)"
     parent=$(dirname "${td}")
diff --git a/ci/test-remote.sh b/ci/test-remote.sh
index e9a4bec..b6e506c 100755
--- a/ci/test-remote.sh
+++ b/ci/test-remote.sh
@@ -20,10 +20,8 @@ main() {
 
     retry cargo fetch
     cargo build
-    CROSS=$(binary_path cross "${PROJECT_HOME}" debug)
-    export CROSS
-    CROSS_UTIL=$(binary_path cross-util "${PROJECT_HOME}" debug)
-    export CROSS_UTIL
+    export CROSS="${PROJECT_HOME}/target/debug/cross"
+    export CROSS_UTIL="${PROJECT_HOME}/target/debug/cross-util"
 
     # if the create volume fails, ensure it exists.
     if ! err=$("${CROSS_UTIL}" volumes create 2>&1 >/dev/null); then
diff --git a/ci/test-zig-image.sh b/ci/test-zig-image.sh
index 6b3092d..6417ee8 100755
--- a/ci/test-zig-image.sh
+++ b/ci/test-zig-image.sh
@@ -34,8 +34,7 @@ main() {
 
     retry cargo fetch
     cargo build
-    CROSS=$(binary_path cross "${PROJECT_HOME}" debug)
-    export CROSS
+    export CROSS="${PROJECT_HOME}/target/debug/cross"
 
     td="$(mktemp -d)"
     git clone --depth 1 https://github.com/cross-rs/rust-cpp-hello-word "${td}"
diff --git a/ci/test.sh b/ci/test.sh
index ca33e7d..474d61a 100755
--- a/ci/test.sh
+++ b/ci/test.sh
@@ -31,8 +31,7 @@ main() {
     export QEMU_STRACE=1
 
     # ensure we have the proper toolchain and optional rust flags
-    CROSS=$(binary_path cross "${PROJECT_HOME}" debug)
-    export CROSS=("${CROSS}")
+    export CROSS=("${PROJECT_HOME}/target/debug/cross")
     export CROSS_FLAGS="-v"
     if (( ${BUILD_STD:-0} )); then
         # use build-std instead of xargo, due to xargo being