-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild-cli.sh
More file actions
executable file
·68 lines (55 loc) · 1.81 KB
/
build-cli.sh
File metadata and controls
executable file
·68 lines (55 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
BUILD_DIR="$ROOT_DIR/build"
OUTPUT="$BUILD_DIR/simdeck"
OUTPUT_BIN="$BUILD_DIR/simdeck-bin"
MANIFEST_PATH="$ROOT_DIR/server/Cargo.toml"
SERVER_TARGET_DIR="$ROOT_DIR/server/target"
# SimDeck's full iOS bridge is macOS-only. Non-macOS builds compile a native
# stub so Android-only integration tests can run on Linux CI.
# Optionally pin the build to an explicit Rust target triple via
# SIMDECK_BUILD_TARGET (the release workflow uses aarch64-apple-darwin); when
# unset we use the host triple so local dev stays fast.
mkdir -p "$BUILD_DIR"
TMP_OUTPUT_BIN="$OUTPUT_BIN.tmp.$$"
trap 'rm -f "$TMP_OUTPUT_BIN"' EXIT
if [[ -n "${SIMDECK_BUILD_TARGET:-}" ]]; then
TARGET="$SIMDECK_BUILD_TARGET"
if ! rustup target list --installed | grep -qx "$TARGET"; then
echo "Installing missing Rust target: $TARGET"
rustup target add "$TARGET"
fi
cargo build --release --manifest-path "$MANIFEST_PATH" --target "$TARGET"
SERVER_BIN="$SERVER_TARGET_DIR/$TARGET/release/simdeck-server"
else
cargo build --release --manifest-path "$MANIFEST_PATH"
SERVER_BIN="$SERVER_TARGET_DIR/release/simdeck-server"
fi
cp "$SERVER_BIN" "$TMP_OUTPUT_BIN"
chmod +x "$TMP_OUTPUT_BIN"
mv -f "$TMP_OUTPUT_BIN" "$OUTPUT_BIN"
trap - EXIT
echo "Built $OUTPUT_BIN"
file "$OUTPUT_BIN"
cat > "$OUTPUT" <<EOF
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="\$(cd "\$(dirname "\$0")" && pwd)"
if [[ "\${1:-}" == "daemon" && "\${2:-}" == "run" ]]; then
while true; do
set +e
"\$SCRIPT_DIR/$(basename "$OUTPUT_BIN")" "\$@"
child_status=\$?
set -e
if [[ "\$child_status" == "75" ]]; then
sleep 0.5
continue
fi
exit "\$child_status"
done
fi
exec "\$SCRIPT_DIR/$(basename "$OUTPUT_BIN")" "\$@"
EOF
chmod +x "$OUTPUT"
echo "Built $OUTPUT"