build: Add upx compression

This commit is contained in:
wanghe-fit2cloud 2025-05-12 15:48:33 +08:00
parent a0dfbde0d3
commit d6af9cd088
2 changed files with 75 additions and 26 deletions

View file

@ -32,6 +32,9 @@ builds:
- arm - arm
- ppc64le - ppc64le
- s390x - s390x
hooks:
post:
- ./ci/script.sh compress_binary {{ .Path }} {{ .Arch }}
- id: core - id: core
dir: core dir: core
@ -54,6 +57,9 @@ builds:
- arm - arm
- ppc64le - ppc64le
- s390x - s390x
hooks:
post:
- ./ci/script.sh compress_binary {{ .Path }} {{ .Arch }}
archives: archives:
- formats: [ 'tar.gz' ] - formats: [ 'tar.gz' ]

View file

@ -1,5 +1,8 @@
#!/bin/bash #!/bin/bash
set -e
download_resources() {
command -v wget >/dev/null || { command -v wget >/dev/null || {
echo "wget not found, please install it and try again." echo "wget not found, please install it and try again."
exit 1 exit 1
@ -34,3 +37,43 @@ if [ ! -f "GeoIP.mmdb" ]; then
fi fi
chmod 755 1pctl install.sh chmod 755 1pctl install.sh
}
compress_binary() {
local binary_path="$1"
local arch="$2"
echo "Attempting to compress: $binary_path for arch: $arch"
if [ "$arch" = "s390x" ]; then
echo "Skipping UPX compression for s390x"
return
fi
if ! command -v upx >/dev/null; then
echo "Installing upx..."
if [ "$(uname -m)" = "s390x" ]; then
echo "UPX not supported on s390x"
return
fi
sudo apt-get update
sudo apt-get install -y upx-ucl || {
echo "Failed to install upx via apt, trying source build"
git clone https://github.com/upx/upx.git
cd upx
git checkout v4.2.2
make
sudo cp src/upx /usr/local/bin/
cd ..
}
fi
upx --best --lzma "$binary_path" && echo "[ok] Compressed: $binary_path" || echo "[warn] Failed to compress: $binary_path"
}
if [ "$1" = "compress_binary" ]; then
compress_binary "$2" "$3"
else
download_resources
fi