Skip to main content

max / audiofiles

2.2 KB · 78 lines History Blame Raw
1 #!/usr/bin/env bash
2 set -euo pipefail
3
4 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
5 PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
6 DIST_DIR="$SCRIPT_DIR"
7 TARGET="x86_64-pc-windows-msvc"
8
9 # Read version from Cargo.toml
10 VERSION=$(grep '^version' "$PROJECT_DIR/crates/audiofiles-app/Cargo.toml" | head -1 | sed 's/.*"\(.*\)".*/\1/')
11 echo "Building AudioFiles v${VERSION} MSI (${TARGET})"
12
13 # Prerequisites check
14 if ! command -v cargo-xwin &>/dev/null; then
15 echo "Error: cargo-xwin not found. Install with: cargo install cargo-xwin"
16 exit 1
17 fi
18
19 if ! command -v wixl &>/dev/null; then
20 echo "Error: wixl not found. Install with: brew install msitools"
21 exit 1
22 fi
23
24 if ! rustup target list --installed | grep -q "$TARGET"; then
25 echo "Error: Rust target $TARGET not installed. Add with: rustup target add $TARGET"
26 exit 1
27 fi
28
29 # Step 1: Build release binary
30 echo "==> Building release binary..."
31 cd "$PROJECT_DIR"
32 cargo xwin build --release -p audiofiles-app --target "$TARGET"
33
34 EXE_SRC="$PROJECT_DIR/target/$TARGET/release/audiofiles-app.exe"
35 if [ ! -f "$EXE_SRC" ]; then
36 echo "Error: Build artifact not found at $EXE_SRC"
37 exit 1
38 fi
39
40 # Step 2: Stage files
41 echo "==> Staging files..."
42 STAGING="$DIST_DIR/.msi-staging"
43 rm -rf "$STAGING"
44 mkdir -p "$STAGING"
45 cp "$EXE_SRC" "$STAGING/AudioFiles.exe"
46 cp "$DIST_DIR/audiofiles.png" "$STAGING/audiofiles.png"
47
48 # Step 3: Generate WiX source from the shared template
49 # (canonical builder is dist/build-msi-native.ps1 on windows-x86; this script
50 # is a macOS/Linux cross-compile fallback)
51 WXS_TEMPLATE="$DIST_DIR/audiofiles.wxs.in"
52 if [ ! -f "$WXS_TEMPLATE" ]; then
53 echo "Error: WiX template missing: $WXS_TEMPLATE"
54 exit 1
55 fi
56 WXS="$STAGING/audiofiles.wxs"
57 sed "s/@VERSION@/${VERSION}.0/g" "$WXS_TEMPLATE" > "$WXS"
58
59 # Step 4: Build MSI
60 echo "==> Building MSI..."
61 MSI_NAME="AudioFiles_${VERSION}_x86_64.msi"
62 MSI_PATH="$DIST_DIR/$MSI_NAME"
63 rm -f "$MSI_PATH"
64
65 wixl -v -o "$MSI_PATH" "$WXS" -D SourceDir="$STAGING"
66
67 # Cleanup
68 rm -rf "$STAGING"
69
70 # Also copy standalone exe
71 EXE_DEST="$DIST_DIR/AudioFiles_${VERSION}_x86_64.exe"
72 cp "$EXE_SRC" "$EXE_DEST"
73
74 echo ""
75 echo "Done:"
76 echo " MSI: $MSI_PATH ($(du -h "$MSI_PATH" | cut -f1))"
77 echo " EXE: $EXE_DEST ($(du -h "$EXE_DEST" | cut -f1))"
78