|
1 | 1 | #!/usr/bin/env bash |
2 | | -# Builds the tsr binary and copies it to binaries/tsr-{triple}. |
3 | | -# Run once before `pnpm tauri dev`, and automatically via beforeBundleCommand. |
| 2 | +# Builds the tsr binary and copies it to binaries/tsr-{triple}[.exe]. |
| 3 | +# |
| 4 | +# When called by Tauri's beforeBundleCommand, TAURI_ENV_TARGET_TRIPLE is set |
| 5 | +# automatically for cross-compilation targets. Falls back to host triple otherwise. |
4 | 6 | # |
5 | 7 | # Usage: |
6 | 8 | # bash scripts/prepare-sidecar.sh # debug (default) |
7 | 9 | # bash scripts/prepare-sidecar.sh release # release |
8 | 10 |
|
9 | 11 | set -e |
10 | 12 |
|
11 | | -TRIPLE=$(rustc -vV | sed -n 's/host: //p') |
| 13 | +HOST_TRIPLE=$(rustc -vV | sed -n 's/host: //p') |
| 14 | +TRIPLE="${TAURI_ENV_TARGET_TRIPLE:-$HOST_TRIPLE}" |
12 | 15 | PROFILE="${1:-debug}" |
13 | 16 |
|
| 17 | +# Windows binaries have .exe extension |
| 18 | +if [[ "$TRIPLE" == *"windows"* ]]; then |
| 19 | + EXT=".exe" |
| 20 | +else |
| 21 | + EXT="" |
| 22 | +fi |
| 23 | + |
14 | 24 | mkdir -p binaries |
15 | 25 |
|
16 | | -# Tauri's build.rs validates that the sidecar file exists before compiling. |
17 | | -# Touch a placeholder so the check passes, then overwrite with the real binary. |
18 | | -touch "binaries/tsr-$TRIPLE" |
| 26 | +# Touch placeholder so Tauri's build.rs validation passes before compilation |
| 27 | +touch "binaries/tsr-$TRIPLE$EXT" |
19 | 28 |
|
20 | 29 | echo "Building tsr ($PROFILE) for $TRIPLE..." |
21 | 30 |
|
| 31 | +# Use --target flag when cross-compiling |
| 32 | +if [ "$TRIPLE" != "$HOST_TRIPLE" ]; then |
| 33 | + TARGET_FLAG="--target $TRIPLE" |
| 34 | +else |
| 35 | + TARGET_FLAG="" |
| 36 | +fi |
| 37 | + |
22 | 38 | if [ "$PROFILE" = "release" ]; then |
23 | | - cargo build --release --bin tsr |
24 | | - cp "target/release/tsr" "binaries/tsr-$TRIPLE" |
| 39 | + cargo build --release --bin tsr $TARGET_FLAG |
| 40 | + SRC="target/${TRIPLE}/release/tsr${EXT}" |
| 41 | + [ -f "$SRC" ] || SRC="target/release/tsr${EXT}" |
25 | 42 | else |
26 | | - cargo build --bin tsr |
27 | | - cp "target/debug/tsr" "binaries/tsr-$TRIPLE" |
| 43 | + cargo build --bin tsr $TARGET_FLAG |
| 44 | + SRC="target/${TRIPLE}/debug/tsr${EXT}" |
| 45 | + [ -f "$SRC" ] || SRC="target/debug/tsr${EXT}" |
28 | 46 | fi |
29 | 47 |
|
30 | | -chmod +x "binaries/tsr-$TRIPLE" |
31 | | -echo "✓ binaries/tsr-$TRIPLE ready" |
| 48 | +cp "$SRC" "binaries/tsr-$TRIPLE$EXT" |
| 49 | +chmod +x "binaries/tsr-$TRIPLE$EXT" 2>/dev/null || true |
| 50 | +echo "✓ binaries/tsr-$TRIPLE$EXT ready" |
0 commit comments