| 1 | #!/usr/bin/env bash |
| 2 | # Cross-compile 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. |
| 5 | set -euo pipefail |
| 6 | |
| 7 | root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 8 | version="$(bash "$root/scripts/ci/package-version.sh")" |
| 9 | export CARGO_HOME="${CARGO_HOME:-$root/cargo-home}" |
| 10 | export PATH="$CARGO_HOME/bin:$PATH" |
| 11 | |
| 12 | if ! 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 |
| 15 | fi |
| 16 | rustup target add x86_64-pc-windows-gnu |
| 17 | cargo build --release --locked --target x86_64-pc-windows-gnu --manifest-path "$root/Cargo.toml" |
| 18 | |
| 19 | exe="$root/target/x86_64-pc-windows-gnu/release/paperdoll-renderer.exe" |
| 20 | if [[ ! -s "$exe" ]]; then |
| 21 | echo "Windows executable was not produced" >&2 |
| 22 | exit 1 |
| 23 | fi |
| 24 | # PE magic. Refuse to zip an ELF if the linker targeted the wrong OS. |
| 25 | if ! 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 |
| 28 | fi |
| 29 | |
| 30 | stage="$(mktemp -d)" |
| 31 | trap 'rm -rf "$stage"' EXIT |
| 32 | install -m 644 "$exe" "$stage/paperdoll-renderer.exe" |
| 33 | install -m 644 "$root/LICENSE" "$stage/LICENSE.txt" |
| 34 | install -m 644 "$root/THIRD_PARTY_NOTICES.md" "$stage/THIRD_PARTY_NOTICES.txt" |
| 35 | printf '%s\n' "Paperdoll Renderer ${version}" \ |
| 36 | "Projectbestanden, modelimport en een live glTF-preview." \ |
| 37 | > "$stage/README.txt" |
| 38 | |
| 39 | mkdir -p "$root/dist" |
| 40 | rm -f "$root/dist/paperdoll-renderer-${version}-windows-x86_64.zip" \ |
| 41 | "$root/dist/paperdoll-renderer-windows-x86_64.zip" |
| 42 | ( |
| 43 | cd "$stage" |
| 44 | zip -r "$root/dist/paperdoll-renderer-${version}-windows-x86_64.zip" \ |
| 45 | paperdoll-renderer.exe LICENSE.txt THIRD_PARTY_NOTICES.txt README.txt |
| 46 | ) |
| 47 | cp -f "$root/dist/paperdoll-renderer-${version}-windows-x86_64.zip" \ |
| 48 | "$root/dist/paperdoll-renderer-windows-x86_64.zip" |
| 49 | python3 "$root/scripts/package/pe_has_icon.py" "$exe" |
| 50 | python3 "$root/scripts/package/pe_has_icon.py" \ |
| 51 | "$root/dist/paperdoll-renderer-windows-x86_64.zip" |
| 52 | echo "wrote dist/paperdoll-renderer-windows-x86_64.zip" |