build: add optional compact Windows release packaging
This commit is contained in:
1 parent
ee7844cb40
commit
789342ab4f
6 files changed
+114
-6
No files matched your search
+48
-6
@@ -9,7 +9,7 @@ compose_file=$repo_root/deploy/compose.yaml
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
usage: scripts/release build --version VERSION --bootstrap-server-url WSS_URL [--output DIR] [--sign-windows-hook FILE]
|
||||
usage: scripts/release build --version VERSION --bootstrap-server-url WSS_URL [--windows-compression none|upx] [--output DIR] [--sign-windows-hook FILE]
|
||||
|
||||
Builds a fresh immutable bundle containing:
|
||||
rvbox-server-linux-amd64
|
||||
@@ -20,6 +20,15 @@ Builds a fresh immutable bundle containing:
|
||||
SHA256SUMS
|
||||
manifest.json
|
||||
|
||||
--windows-compression upx creates a compact, directly runnable Windows executable
|
||||
with pinned UPX/LZMA and keeps rvbox-windows-amd64-unpacked.exe as a fallback.
|
||||
The default is none. Icons, manifest, and version resources stay uncompressed
|
||||
and are compared against the original. Relocations are retained. UPX integrity
|
||||
and smaller-output checks must pass before signing/checksumming either variant.
|
||||
Packed binaries still require native Windows acceptance; they may encounter
|
||||
antivirus false positives or higher runtime memory/startup costs. No external
|
||||
extractor is needed on Windows. Rebuilding an outdated toolchain is automatic.
|
||||
|
||||
The default output is dist/rvbox-VERSION. --output must remain below this
|
||||
repository's ignored dist/ tree. VERSION must be a safe release label
|
||||
([0-9A-Za-z][0-9A-Za-z._+-]{0,63}); an existing final output is never replaced.
|
||||
@@ -46,10 +55,12 @@ version=
|
||||
output=
|
||||
sign_hook=
|
||||
bootstrap_server_url=
|
||||
windows_compression=none
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case $1 in
|
||||
--version) [ "$#" -ge 2 ] || fail "--version needs a value"; version=$2; shift 2 ;;
|
||||
--bootstrap-server-url) [ "$#" -ge 2 ] || fail "--bootstrap-server-url needs a value"; bootstrap_server_url=$2; shift 2 ;;
|
||||
--windows-compression) [ "$#" -ge 2 ] || fail "--windows-compression needs a value"; windows_compression=$2; shift 2 ;;
|
||||
--output) [ "$#" -ge 2 ] || fail "--output needs a directory"; output=$2; shift 2 ;;
|
||||
--sign-windows-hook) [ "$#" -ge 2 ] || fail "--sign-windows-hook needs an executable file"; sign_hook=$2; shift 2 ;;
|
||||
--help|-h) usage; exit 0 ;;
|
||||
@@ -57,6 +68,11 @@ while [ "$#" -gt 0 ]; do
|
||||
esac
|
||||
done
|
||||
|
||||
case $windows_compression in
|
||||
none|upx) ;;
|
||||
*) fail "--windows-compression must be none or upx" ;;
|
||||
esac
|
||||
|
||||
case $version in
|
||||
''|[!0-9A-Za-z]*|*[!0-9A-Za-z._+-]*|?????????????????????????????????????????????????????????????????*)
|
||||
fail "--version must match [0-9A-Za-z][0-9A-Za-z._+-]{0,63}"
|
||||
@@ -88,6 +104,11 @@ fi
|
||||
|
||||
docker version >/dev/null 2>&1 || fail "Docker is unavailable"
|
||||
docker compose -f "$compose_file" version >/dev/null 2>&1 || fail "Docker Compose is unavailable"
|
||||
if [ "$windows_compression" = upx ]; then
|
||||
if ! docker compose -f "$compose_file" run --rm toolchain sh -ec 'command -v upx >/dev/null' >/dev/null 2>&1; then
|
||||
docker compose -f "$compose_file" build toolchain
|
||||
fi
|
||||
fi
|
||||
|
||||
partial=$parent/.rvbox-$version.partial-$$
|
||||
mkdir "$partial" || fail "could not create private release staging directory"
|
||||
@@ -115,28 +136,49 @@ docker compose -f "$compose_file" run --rm toolchain sh -ec '
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "$flags" -o "$out/rvc-linux-amd64" ./cmd/rvc
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "$flags" -o "$out/rvc-linux-arm64" ./cmd/rvc
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "-H=windowsgui $windows_flags" -o "$out/rvbox-windows-amd64.exe" ./cmd/rvbox
|
||||
' sh "$version" "$container_partial" "$bootstrap_server_url"
|
||||
if [ "$4" = upx ]; then
|
||||
cp "$out/rvbox-windows-amd64.exe" "$out/rvbox-windows-amd64-unpacked.exe"
|
||||
upx --no-env --best --lzma --compress-icons=0 --compress-resources=0 --strip-relocs=0 \
|
||||
-o "$out/.rvbox-packed.exe" "$out/rvbox-windows-amd64.exe"
|
||||
upx --no-env -t "$out/.rvbox-packed.exe"
|
||||
go-winres extract --dir "$out/.resources-original" "$out/rvbox-windows-amd64.exe"
|
||||
go-winres extract --dir "$out/.resources-packed" "$out/.rvbox-packed.exe"
|
||||
diff -r "$out/.resources-original" "$out/.resources-packed"
|
||||
rm -rf -- "$out/.resources-original" "$out/.resources-packed"
|
||||
test "$(wc -c < "$out/.rvbox-packed.exe")" -lt "$(wc -c < "$out/rvbox-windows-amd64.exe")"
|
||||
mv "$out/.rvbox-packed.exe" "$out/rvbox-windows-amd64.exe"
|
||||
fi
|
||||
' sh "$version" "$container_partial" "$bootstrap_server_url" "$windows_compression"
|
||||
|
||||
windows_artifacts=rvbox-windows-amd64.exe
|
||||
if [ "$windows_compression" = upx ]; then
|
||||
windows_artifacts="$windows_artifacts rvbox-windows-amd64-unpacked.exe"
|
||||
fi
|
||||
signed=false
|
||||
if [ -n "$sign_hook" ]; then
|
||||
RVBOX_ARTIFACT=$partial/rvbox-windows-amd64.exe RVBOX_VERSION=$version "$sign_hook" "$partial/rvbox-windows-amd64.exe" "$version"
|
||||
for artifact in $windows_artifacts; do
|
||||
RVBOX_ARTIFACT=$partial/$artifact RVBOX_VERSION=$version "$sign_hook" "$partial/$artifact" "$version"
|
||||
done
|
||||
signed=true
|
||||
fi
|
||||
|
||||
for artifact in rvbox-server-linux-amd64 rvbox-server-linux-arm64 rvc-linux-amd64 rvc-linux-arm64 rvbox-windows-amd64.exe; do
|
||||
for artifact in rvbox-server-linux-amd64 rvbox-server-linux-arm64 rvc-linux-amd64 rvc-linux-arm64 $windows_artifacts; do
|
||||
[ -f "$partial/$artifact" ] && [ ! -L "$partial/$artifact" ] || fail "builder did not create regular $artifact"
|
||||
done
|
||||
(cd "$partial" && sha256sum rvbox-server-linux-amd64 rvbox-server-linux-arm64 rvc-linux-amd64 rvc-linux-arm64 rvbox-windows-amd64.exe) >"$partial/SHA256SUMS"
|
||||
(cd "$partial" && sha256sum rvbox-server-linux-amd64 rvbox-server-linux-arm64 rvc-linux-amd64 rvc-linux-arm64 $windows_artifacts) >"$partial/SHA256SUMS"
|
||||
{
|
||||
printf '{\n'
|
||||
printf ' "schema": 1,\n'
|
||||
printf ' "version": "%s",\n' "$version"
|
||||
printf ' "git_commit": "%s",\n' "$commit"
|
||||
printf ' "windows_signed": %s,\n' "$signed"
|
||||
printf ' "windows_compression": "%s",\n' "$windows_compression"
|
||||
printf ' "artifacts": "SHA256SUMS"\n'
|
||||
printf '}\n'
|
||||
} >"$partial/manifest.json"
|
||||
chmod 0755 "$partial/rvbox-server-linux-amd64" "$partial/rvbox-server-linux-arm64" "$partial/rvc-linux-amd64" "$partial/rvc-linux-arm64" "$partial/rvbox-windows-amd64.exe"
|
||||
for artifact in rvbox-server-linux-amd64 rvbox-server-linux-arm64 rvc-linux-amd64 rvc-linux-arm64 $windows_artifacts; do
|
||||
chmod 0755 "$partial/$artifact"
|
||||
done
|
||||
chmod 0644 "$partial/SHA256SUMS" "$partial/manifest.json"
|
||||
mv -- "$partial" "$output"
|
||||
trap - EXIT HUP INT TERM
|
||||
|
||||
Reference in new issue
Block a user