BlueGit

golden-age paperdoll-renderer

Files

paperdoll-renderer / scripts / package / windows.sh

windows.sh

windows.sh 1.8 KiB Download Raw
1#!/usr/bin/env bash
2# Cross-compile the foundation shell for Windows x86_64 with MinGW.
3# posprint uses this route and states that BlueGit has no Windows runner.
4# This script packages the .exe in a zip. It does not run the Windows binary.
5set -euo pipefail
6
7root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
8version="$(bash "$root/scripts/ci/package-version.sh")"
9export CARGO_HOME="${CARGO_HOME:-$root/cargo-home}"
10export PATH="$CARGO_HOME/bin:$PATH"
11
12if ! command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1; then
13 echo "x86_64-w64-mingw32-gcc is not installed" >&2
14 exit 1
15fi
16rustup target add x86_64-pc-windows-gnu
17cargo build --release --locked --target x86_64-pc-windows-gnu --manifest-path "$root/Cargo.toml"
18
19exe="$root/target/x86_64-pc-windows-gnu/release/paperdoll-renderer.exe"
20if [[ ! -s "$exe" ]]; then
21 echo "Windows executable was not produced" >&2
22 exit 1
23fi
24# PE magic. Refuse to zip an ELF if the linker targeted the wrong OS.
25if ! od -An -tx1 -N 2 "$exe" | grep -q "4d 5a"; then
26 echo "paperdoll-renderer.exe does not start with MZ" >&2
27 exit 1
28fi
29
30stage="$(mktemp -d)"
31trap 'rm -rf "$stage"' EXIT
32install -m 644 "$exe" "$stage/paperdoll-renderer.exe"
33install -m 644 "$root/LICENSE" "$stage/LICENSE.txt"
34printf '%s\n' "Paperdoll Renderer ${version}" "Foundation shell. Import and render are not included." \
35 > "$stage/README.txt"
36
37mkdir -p "$root/dist"
38rm -f "$root/dist/paperdoll-renderer-${version}-windows-x86_64.zip" \
39 "$root/dist/paperdoll-renderer-windows-x86_64.zip"
40(
41 cd "$stage"
42 zip -r "$root/dist/paperdoll-renderer-${version}-windows-x86_64.zip" \
43 paperdoll-renderer.exe LICENSE.txt README.txt
44)
45cp -f "$root/dist/paperdoll-renderer-${version}-windows-x86_64.zip" \
46 "$root/dist/paperdoll-renderer-windows-x86_64.zip"
47echo "wrote dist/paperdoll-renderer-windows-x86_64.zip"