summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-01-28 02:23:25 +0100
committerskal <pascal.massimino@gmail.com>2026-01-28 02:23:25 +0100
commit546715dd706d39ccef09c98c9cab2fee25ca2ddd (patch)
tree3aa9923dfbd21d0deb4714d5c0b516098a313c3f /scripts
parent5722d68a3e529fb22886c2430dc0d268c33424e7 (diff)
fix(crunch): Use strip/gzexe on macOS instead of UPX
UPX is unreliable on macOS. Switched to using standard 'strip -u -r' and 'gzexe' for binary compression on Darwin systems. Achieved a compressed binary size of ~48KB (dynamically linked). Updated FETCH_DEPS.md to reflect that UPX is now only required for Linux/Windows.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/crunch_demo.sh40
1 files changed, 31 insertions, 9 deletions
diff --git a/scripts/crunch_demo.sh b/scripts/crunch_demo.sh
index 333faa9..d9c77a4 100755
--- a/scripts/crunch_demo.sh
+++ b/scripts/crunch_demo.sh
@@ -1,23 +1,45 @@
#!/bin/sh
-# Build a size-optimized binary and compress it with UPX.
+# Build a size-optimized binary and compress it.
set -e
-if ! command -v upx >/dev/null 2>&1; then
- echo "Error: upx is not installed or not in PATH."
- echo "Please install it using 'brew install upx' or from https://github.com/upx/upx"
- exit 1
-fi
-
echo "Building stripped binary..."
cmake -S . -B build_strip -DDEMO_STRIP_ALL=ON
cmake --build build_strip
SRC_BIN="build_strip/demo64k"
OUT_BIN="build_strip/demo64k_packed"
+OS_NAME=$(uname -s)
+
+if [ "$OS_NAME" = "Darwin" ]; then
+ echo "macOS detected. Using 'strip' and 'gzexe' (UPX is unreliable on macOS)."
+
+ # Copy original to output to work on it
+ cp "$SRC_BIN" "$OUT_BIN"
+
+ echo "Stripping symbols..."
+ strip -u -r "$OUT_BIN"
+
+ if command -v gzexe >/dev/null 2>&1; then
+ echo "Compressing with gzexe..."
+ gzexe "$OUT_BIN"
+ # gzexe creates a backup file ending in ~, remove it
+ rm -f "$OUT_BIN~"
+ else
+ echo "Warning: gzexe not found, skipping compression."
+ fi
-echo "Compressing with UPX..."
-upx --best --lzma -o "$OUT_BIN" "$SRC_BIN"
+else
+ # Linux / other
+ if ! command -v upx >/dev/null 2>&1; then
+ echo "Error: upx is not installed or not in PATH."
+ echo "Please install it using your package manager."
+ exit 1
+ fi
+
+ echo "Compressing with UPX..."
+ upx --best --lzma -o "$OUT_BIN" "$SRC_BIN"
+fi
echo "Done."
ls -lh "$SRC_BIN" "$OUT_BIN"