-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·97 lines (86 loc) · 3.23 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·97 lines (86 loc) · 3.23 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
# Fast local build: release core (all cargo features) + TUI, optional install + --run
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$ROOT_DIR"
# shellcheck source=scripts/cargo-local-env.sh
source "$ROOT_DIR/scripts/cargo-local-env.sh"
case "${1:-}" in
""|--run)
;;
--help|-h)
printf 'usage: %s [--run [TUI_ARGS...]]\n' "$(basename "$0")"
printf '\nBuilds the release core (--all-features) and development TUI in\n'
printf 'parallel, then replaces the current catcode installation when it is\n'
printf 'available on PATH. Incremental links skip thin-LTO (use release-*.sh\n'
printf 'for dist binaries). --run starts the TUI with that exact core, even\n'
printf 'when CATCODE_CORE points at an installed binary.\n'
exit 0
;;
*)
printf 'error: unknown option %s\n' "$1" >&2
printf 'usage: %s [--run [TUI_ARGS...]]\n' "$(basename "$0")" >&2
exit 2
;;
esac
echo "[1/3] building core + tui in parallel (all-features, ${JOBS} jobs, ${CARGO_LINKER})..."
core_err=0
tui_err=0
cargo build --release -j"$JOBS" --all-features --manifest-path core/Cargo.toml &
core_pid=$!
( cd tui && CGO_ENABLED=0 go build -o tui . ) &
tui_pid=$!
wait "$core_pid" || core_err=$?
wait "$tui_pid" || tui_err=$?
if ((core_err)); then
echo "error: cargo build failed" >&2
exit "$core_err"
fi
if ((tui_err)); then
echo "error: go build failed" >&2
exit "$tui_err"
fi
echo "[2/3] artifacts ready"
LOCAL_CORE="$ROOT_DIR/core/target/release/core"
INSTALLED_TUI="$(type -P catcode || true)"
# Replace the binaries used by the current installation, rather than leaving
# the freshly-built artifacts stranded in the repository. The TUI and core
# must be updated together: a source-built TUI can speak protocol changes that
# an older installed core may not understand.
install_binary() {
local source="$1" destination="$2"
local destination_dir
destination_dir="$(dirname "$destination")"
if [[ $EUID -eq 0 || -w "$destination_dir" ]]; then
install -m 0755 "$source" "$destination"
elif command -v sudo >/dev/null 2>&1; then
sudo install -m 0755 "$source" "$destination"
else
echo "error: cannot replace $destination (directory is not writable and sudo is unavailable)" >&2
return 1
fi
}
if [[ -n "$INSTALLED_TUI" ]]; then
echo "[3/3] replacing installed catcode"
INSTALLED_DIR="$(dirname "$INSTALLED_TUI")"
case "$INSTALLED_TUI" in
*.exe|*.EXE) INSTALLED_CORE="$INSTALLED_DIR/catcode-core.exe" ;;
*) INSTALLED_CORE="$INSTALLED_DIR/catcode-core" ;;
esac
echo "installing tui -> $INSTALLED_TUI"
install_binary "$ROOT_DIR/tui/tui" "$INSTALLED_TUI"
echo "installing core -> $INSTALLED_CORE"
install_binary "$LOCAL_CORE" "$INSTALLED_CORE"
else
echo "[3/3] installed catcode not found on PATH; skipping installation"
fi
echo "done: core -> core/target/release/core, tui -> tui/tui"
if [[ -n "${CATCODE_CORE:-}" && "$CATCODE_CORE" != "$LOCAL_CORE" ]]; then
echo "warning: CATCODE_CORE=$CATCODE_CORE overrides this source build"
echo " run locally with: CATCODE_CORE=$LOCAL_CORE $ROOT_DIR/tui/tui"
fi
if [[ "${1:-}" == "--run" ]]; then
shift
echo "starting local TUI (core=$LOCAL_CORE)"
exec env CATCODE_CORE="$LOCAL_CORE" "$ROOT_DIR/tui/tui" "$@"
fi