From 3474d66b13bec7b9c04c797296091ae6a12df05a Mon Sep 17 00:00:00 2001 From: Joshua Sing Date: Sun, 25 Jan 2026 03:46:28 +1100 Subject: scripts/test: fix missing env vars for cross-compilation --- scripts/test | 58 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 14 deletions(-) (limited to 'scripts/test') diff --git a/scripts/test b/scripts/test index a7ce1ea..1c00e61 100755 --- a/scripts/test +++ b/scripts/test @@ -12,6 +12,33 @@ fi ENABLE_ASM="${ENABLE_ASM:=ON}" +# setup_cross_compiler sets up environment variables for cross-compilation with the given prefix. +setup_cross_compiler() { + cross_prefix=$1 + + # Use unversioned symlink if available, otherwise find versioned binary + if command -v "${cross_prefix}-gcc" >/dev/null 2>&1; then + CC=${cross_prefix}-gcc + CXX=${cross_prefix}-g++ + else + gcc_ver=$(find /usr/bin -maxdepth 1 -name "${cross_prefix}-gcc-[0-9]*" 2>/dev/null \ + | sed "s/.*${cross_prefix}-gcc-//" | sort -V | tail -1) + CC=${cross_prefix}-gcc-${gcc_ver} + CXX=${cross_prefix}-g++-${gcc_ver} + fi + + if ! command -v "${CC}" >/dev/null 2>&1; then + echo "##### Error: ${CC} not found in PATH" + exit 1 + fi + + AR=${cross_prefix}-ar + STRIP=${cross_prefix}-strip + RANLIB=${cross_prefix}-ranlib + + echo "##### Using $($CC --version | head -1)" +} + if type apt-get >/dev/null 2>&1; then sudo apt-get update sudo apt-get install -y cmake ninja-build @@ -87,7 +114,7 @@ elif [ "$ARCH" = "native" ]; then ninja test ) -elif [ "$ARCH" = "mingw32" -o "$ARCH" = "mingw64" ]; then +elif [ "$ARCH" = "mingw32" ] || [ "$ARCH" = "mingw64" ]; then CPU=i686 if [ "$ARCH" = "mingw64" ]; then CPU=x86_64 @@ -115,54 +142,57 @@ elif [ "$ARCH" = "mingw32" -o "$ARCH" = "mingw64" ]; then ninja -j 4 ) -elif [ "$ARCH" = "arm32" -o "$ARCH" = "arm64" ]; then +elif [ "$ARCH" = "arm32" ] || [ "$ARCH" = "arm64" ]; then sudo apt-get install -y qemu-user-static binfmt-support if [ "$ARCH" = "arm32" ]; then sudo apt-get install -y g++-arm-linux-gnueabihf sudo ln -sf /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3 /lib/ + setup_cross_compiler arm-linux-gnueabihf + ./configure --host=arm-linux-gnueabihf LD_LIBRARY_PATH=/usr/arm-linux-gnueabihf/lib make -j 4 check else sudo apt-get install -y g++-aarch64-linux-gnu sudo ln -sf /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 /lib/ + setup_cross_compiler aarch64-linux-gnu + ./configure --host=aarch64-linux-gnu LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib make -j 4 check fi - file apps/openssl/.libs/openssl + file apps/openssl/openssl elif [ "$ARCH" = "loong64" ]; then sudo apt install -y qemu-user-static binfmt-support g++-14-loongarch64-linux-gnu sudo ln -sf /usr/loongarch64-linux-gnu/lib64/ld-linux-loongarch-lp64d.so.1 /lib64 - - CC=loongarch64-linux-gnu-gcc-14 - CXX=loongarch64-linux-gnu++-14 - AR=loongarch64-linux-gnu-ar - STRIP=loongarch64-linux-gnu-strip-14 - RANLIB=loongarch64-linux-gnu-ranlib + setup_cross_compiler loongarch64-linux-gnu ./configure --host=loongarch64-linux-gnu LD_LIBRARY_PATH=/usr/loongarch64-linux-gnu/lib make -j 4 check file apps/openssl/openssl -elif [ "$ARCH" = "mips32" -o "$ARCH" = "mips64" ]; then +elif [ "$ARCH" = "mips32" ] || [ "$ARCH" = "mips64" ]; then sudo apt-get install -y qemu-user-static binfmt-support if [ "$ARCH" = "mips32" ]; then sudo apt-get install -y g++-mips-linux-gnu - sudo ln -sf /usr/mipsel-linux-gnu/lib/ld.so.1 /lib/ - ./configure --host=mipsel-linux-gnu - LD_LIBRARY_PATH=/usr/mipsel-linux-gnu/lib make -j 4 check + sudo ln -sf /usr/mips-linux-gnu/lib/ld.so.1 /lib/ + setup_cross_compiler mips-linux-gnu + + ./configure --host=mips-linux-gnu + LD_LIBRARY_PATH=/usr/mips-linux-gnu/lib make -j 4 check else sudo apt-get install -y g++-mips64el-linux-gnuabi64 sudo ln -sf /usr/mips64el-linux-gnuabi64/lib64/ld.so.1 /lib64 + setup_cross_compiler mips64el-linux-gnuabi64 + ./configure --host=mips64el-linux-gnuabi64 LD_LIBRARY_PATH=/usr/mips64el-linux-gnuabi64/lib make -j 4 check fi - file apps/openssl/.libs/openssl + file apps/openssl/openssl elif [ "$ARCH" = "android" ]; then export TC_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake -- cgit v1.2.3-55-g6feb From 1c945c2e11776c78c7e49e86c5a5aac23f48434b Mon Sep 17 00:00:00 2001 From: Joshua Sing Date: Sun, 25 Jan 2026 16:10:09 +1100 Subject: scripts/test: remove non-standard sort, tail and find flags --- scripts/test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/test') diff --git a/scripts/test b/scripts/test index 1c00e61..5e95dfd 100755 --- a/scripts/test +++ b/scripts/test @@ -21,8 +21,8 @@ setup_cross_compiler() { CC=${cross_prefix}-gcc CXX=${cross_prefix}-g++ else - gcc_ver=$(find /usr/bin -maxdepth 1 -name "${cross_prefix}-gcc-[0-9]*" 2>/dev/null \ - | sed "s/.*${cross_prefix}-gcc-//" | sort -V | tail -1) + gcc_ver=$(find /usr/bin -name "${cross_prefix}-gcc-[0-9]*" -prune 2>/dev/null \ + | sed "s/.*${cross_prefix}-gcc-//" | sort -n | tail -n 1) CC=${cross_prefix}-gcc-${gcc_ver} CXX=${cross_prefix}-g++-${gcc_ver} fi -- cgit v1.2.3-55-g6feb From 09c99a505f255164de53a404b81d1aaf3f8c6a23 Mon Sep 17 00:00:00 2001 From: Joshua Sing Date: Sun, 25 Jan 2026 16:10:55 +1100 Subject: scripts/test: check all binaries for cross-compile Probably safer to check all of them instead of just CC, since previously it seems the loongarch64 RANLIB variable could have been wrong. I am not sure if a missing binary could cause unexpected behaviour. --- scripts/test | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'scripts/test') diff --git a/scripts/test b/scripts/test index 5e95dfd..d874b64 100755 --- a/scripts/test +++ b/scripts/test @@ -27,15 +27,18 @@ setup_cross_compiler() { CXX=${cross_prefix}-g++-${gcc_ver} fi - if ! command -v "${CC}" >/dev/null 2>&1; then - echo "##### Error: ${CC} not found in PATH" - exit 1 - fi - AR=${cross_prefix}-ar STRIP=${cross_prefix}-strip RANLIB=${cross_prefix}-ranlib + # Check all binaries actually exist. + for c in "$CC" "$CXX" "$AR" "$STRIP" "$RANLIB"; do + if ! command -v "$c" >/dev/null 2>&1; then + echo "##### Error: $c not found" + exit 1 + fi + done + echo "##### Using $($CC --version | head -1)" } -- cgit v1.2.3-55-g6feb From 836c23eb15c1d4c2d408f22c7e2e34e87a3697c2 Mon Sep 17 00:00:00 2001 From: Joshua Sing Date: Sun, 25 Jan 2026 20:06:32 +1100 Subject: scripts/test: reorder setup_cross_compiler, fix head -1 --- scripts/test | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'scripts/test') diff --git a/scripts/test b/scripts/test index d874b64..2148d52 100755 --- a/scripts/test +++ b/scripts/test @@ -16,21 +16,20 @@ ENABLE_ASM="${ENABLE_ASM:=ON}" setup_cross_compiler() { cross_prefix=$1 - # Use unversioned symlink if available, otherwise find versioned binary - if command -v "${cross_prefix}-gcc" >/dev/null 2>&1; then - CC=${cross_prefix}-gcc - CXX=${cross_prefix}-g++ - else - gcc_ver=$(find /usr/bin -name "${cross_prefix}-gcc-[0-9]*" -prune 2>/dev/null \ - | sed "s/.*${cross_prefix}-gcc-//" | sort -n | tail -n 1) - CC=${cross_prefix}-gcc-${gcc_ver} - CXX=${cross_prefix}-g++-${gcc_ver} - fi - + CC=${cross_prefix}-gcc + CXX=${cross_prefix}-g++ AR=${cross_prefix}-ar STRIP=${cross_prefix}-strip RANLIB=${cross_prefix}-ranlib + # If the unversioned symlink for gcc doesn't exist, find versioned binary. + if ! command -v "$CC" >/dev/null 2>&1; then + gcc_ver=$(find /usr/bin -name "${CC}-[0-9]*" -prune 2>/dev/null \ + | sed "s/.*${CC}-//" | sort -n | tail -n 1) + CC=${CC}-${gcc_ver} + CXX=${CXX}-${gcc_ver} + fi + # Check all binaries actually exist. for c in "$CC" "$CXX" "$AR" "$STRIP" "$RANLIB"; do if ! command -v "$c" >/dev/null 2>&1; then @@ -39,7 +38,7 @@ setup_cross_compiler() { fi done - echo "##### Using $($CC --version | head -1)" + echo "##### Using $($CC --version | head -n 1)" } if type apt-get >/dev/null 2>&1; then -- cgit v1.2.3-55-g6feb