Skip to content

Commit eebc75a

Browse files
authored
fix: build native libs via bash, not direct .sh execution (#75)
* fix: build native libs via bash, not direct .sh execution exec-maven-plugin's <executable> pointed straight at scripts/build-zstd.sh, relying on its shebang to make it directly executable. That only works on macOS/Linux; Windows can't interpret a shebang at all, so any native source build there failed outright: Cannot run program ".../scripts/build-zstd.sh": CreateProcess error=193, %1 is not a valid Win32 application Never caught before because ci.yml only runs on ubuntu-latest, and release-smoke.yml's Windows legs consume already-published artifacts rather than building from source. The new benchmark-lto.yml workflow is the first CI job to build natively on a Windows runner, and it surfaced this on its first run (windows-x86_64 leg failed while linux-x86_64/linux-aarch64/osx-aarch64 succeeded). Fix: invoke `bash scripts/build-zstd.sh ...` explicitly instead of executing the script directly. Applied uniformly to all six native/*/pom.xml (not just the Windows two) - bash is on PATH on macOS/Linux too, and GitHub's Windows runners ship Git Bash by default (release-smoke.yml's `shell: bash` steps already rely on this). Verified locally: full clean rebuild + zstd/integration-tests suite still passes on osx-aarch64, checkstyle clean. * fix: handle unrecognized/Windows host OS in build-zstd.sh host detection Second Windows-support bug in the same script, found while verifying the exec-maven-plugin fix in this branch on an actual Windows runner: once bash could finally launch the script, it immediately died at scripts/build-zstd.sh: line 55: HOST_OS_NAME: unbound variable Git Bash's `uname -s` reports "MINGW64_NT-..."/"MSYS_NT-..." (never "Windows"), so the case statement matched neither Darwin nor Linux and left HOST_OS_NAME unset - fatal under `set -u`. HOST_CLASSIFIER is purely cosmetic (the "(cross from ...)" log hint; the actual build is driven entirely by $ZIG_TARGET/$CLASSIFIER from argv, never by host detection), but an unset variable still aborts the whole script under set -euo pipefail. Fix: add a Windows case (MINGW*/MSYS*/CYGWIN*) alongside Darwin/Linux, plus a default `*)` arm on both case statements so no host can leave the variable unset. This gives correct native-vs-cross detection on Windows runners too, not just a crash-avoidance shim. Verified locally: full clean osx-aarch64 rebuild still reports no "(cross from ...)" hint (correctly detected as native), a linux-x86_64 cross-build still correctly reports "(cross from osx-aarch64)", zstd/integration-tests suite and checkstyle both pass.
1 parent 0228314 commit eebc75a

7 files changed

Lines changed: 52 additions & 8 deletions

File tree

‎native/linux-aarch64/pom.xml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@
3535
<goal>exec</goal>
3636
</goals>
3737
<configuration>
38-
<executable>${maven.multiModuleProjectDirectory}/scripts/build-zstd.sh</executable>
38+
<!-- Invoke via bash explicitly: Windows can't execute a .sh via
39+
its shebang the way macOS/Linux can (CreateProcess error=193,
40+
"%1 is not a valid Win32 application"). GitHub's Windows
41+
runners ship Git Bash on PATH; macOS/Linux always have bash. -->
42+
<executable>bash</executable>
3943
<arguments>
44+
<argument>${maven.multiModuleProjectDirectory}/scripts/build-zstd.sh</argument>
4045
<argument>${project.basedir}/src/main/resources</argument>
4146
<argument>linux-aarch64</argument>
4247
</arguments>

‎native/linux-x86_64/pom.xml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@
3535
<goal>exec</goal>
3636
</goals>
3737
<configuration>
38-
<executable>${maven.multiModuleProjectDirectory}/scripts/build-zstd.sh</executable>
38+
<!-- Invoke via bash explicitly: Windows can't execute a .sh via
39+
its shebang the way macOS/Linux can (CreateProcess error=193,
40+
"%1 is not a valid Win32 application"). GitHub's Windows
41+
runners ship Git Bash on PATH; macOS/Linux always have bash. -->
42+
<executable>bash</executable>
3943
<arguments>
44+
<argument>${maven.multiModuleProjectDirectory}/scripts/build-zstd.sh</argument>
4045
<argument>${project.basedir}/src/main/resources</argument>
4146
<argument>linux-x86_64</argument>
4247
</arguments>

‎native/osx-aarch64/pom.xml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@
3535
<goal>exec</goal>
3636
</goals>
3737
<configuration>
38-
<executable>${maven.multiModuleProjectDirectory}/scripts/build-zstd.sh</executable>
38+
<!-- Invoke via bash explicitly: Windows can't execute a .sh via
39+
its shebang the way macOS/Linux can (CreateProcess error=193,
40+
"%1 is not a valid Win32 application"). GitHub's Windows
41+
runners ship Git Bash on PATH; macOS/Linux always have bash. -->
42+
<executable>bash</executable>
3943
<arguments>
44+
<argument>${maven.multiModuleProjectDirectory}/scripts/build-zstd.sh</argument>
4045
<argument>${project.basedir}/src/main/resources</argument>
4146
<argument>osx-aarch64</argument>
4247
</arguments>

‎native/osx-x86_64/pom.xml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@
3535
<goal>exec</goal>
3636
</goals>
3737
<configuration>
38-
<executable>${maven.multiModuleProjectDirectory}/scripts/build-zstd.sh</executable>
38+
<!-- Invoke via bash explicitly: Windows can't execute a .sh via
39+
its shebang the way macOS/Linux can (CreateProcess error=193,
40+
"%1 is not a valid Win32 application"). GitHub's Windows
41+
runners ship Git Bash on PATH; macOS/Linux always have bash. -->
42+
<executable>bash</executable>
3943
<arguments>
44+
<argument>${maven.multiModuleProjectDirectory}/scripts/build-zstd.sh</argument>
4045
<argument>${project.basedir}/src/main/resources</argument>
4146
<argument>osx-x86_64</argument>
4247
</arguments>

‎native/windows-aarch64/pom.xml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@
3535
<goal>exec</goal>
3636
</goals>
3737
<configuration>
38-
<executable>${maven.multiModuleProjectDirectory}/scripts/build-zstd.sh</executable>
38+
<!-- Invoke via bash explicitly: Windows can't execute a .sh via
39+
its shebang the way macOS/Linux can (CreateProcess error=193,
40+
"%1 is not a valid Win32 application"). GitHub's Windows
41+
runners ship Git Bash on PATH; macOS/Linux always have bash. -->
42+
<executable>bash</executable>
3943
<arguments>
44+
<argument>${maven.multiModuleProjectDirectory}/scripts/build-zstd.sh</argument>
4045
<argument>${project.basedir}/src/main/resources</argument>
4146
<argument>windows-aarch64</argument>
4247
</arguments>

‎native/windows-x86_64/pom.xml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@
3535
<goal>exec</goal>
3636
</goals>
3737
<configuration>
38-
<executable>${maven.multiModuleProjectDirectory}/scripts/build-zstd.sh</executable>
38+
<!-- Invoke via bash explicitly: Windows can't execute a .sh via
39+
its shebang the way macOS/Linux can (CreateProcess error=193,
40+
"%1 is not a valid Win32 application"). GitHub's Windows
41+
runners ship Git Bash on PATH; macOS/Linux always have bash. -->
42+
<executable>bash</executable>
3943
<arguments>
44+
<argument>${maven.multiModuleProjectDirectory}/scripts/build-zstd.sh</argument>
4045
<argument>${project.basedir}/src/main/resources</argument>
4146
<argument>windows-x86_64</argument>
4247
</arguments>

‎scripts/build-zstd.sh‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,22 @@ if [ -f "$DEST_DIR/$LIB_NAME" ]; then
5050
fi
5151

5252
HOST_OS=$(uname -s); HOST_ARCH=$(uname -m)
53-
case "$HOST_OS" in Darwin) HOST_OS_NAME="osx" ;; Linux) HOST_OS_NAME="linux" ;; esac
54-
case "$HOST_ARCH" in arm64|aarch64) HOST_ARCH_NAME="aarch64" ;; x86_64) HOST_ARCH_NAME="x86_64" ;; esac
53+
# Git Bash's uname -s reports MINGW64_NT-.../MSYS_NT-... (never "Windows"), and
54+
# an unmatched case leaves HOST_OS_NAME unset - a hard failure under set -u.
55+
# HOST_CLASSIFIER is cosmetic (the "(cross from ...)" log hint only; the build
56+
# itself is driven entirely by $ZIG_TARGET/$CLASSIFIER from argv), but it still
57+
# needs a value on every host, including ones we don't specifically recognize.
58+
case "$HOST_OS" in
59+
Darwin) HOST_OS_NAME="osx" ;;
60+
Linux) HOST_OS_NAME="linux" ;;
61+
MINGW*|MSYS*|CYGWIN*) HOST_OS_NAME="windows" ;;
62+
*) HOST_OS_NAME="unknown" ;;
63+
esac
64+
case "$HOST_ARCH" in
65+
arm64|aarch64) HOST_ARCH_NAME="aarch64" ;;
66+
x86_64) HOST_ARCH_NAME="x86_64" ;;
67+
*) HOST_ARCH_NAME="unknown" ;;
68+
esac
5569
HOST_CLASSIFIER="${HOST_OS_NAME}-${HOST_ARCH_NAME}"
5670
CROSS=""
5771
[ "$CLASSIFIER" != "$HOST_CLASSIFIER" ] && CROSS=" (cross from $HOST_CLASSIFIER)"

0 commit comments

Comments
 (0)