forked from steipete/CodexBar
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·184 lines (155 loc) · 6.21 KB
/
dev.sh
File metadata and controls
executable file
·184 lines (155 loc) · 6.21 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env bash
# Build and run the CodexBar Tauri desktop shell on Linux / WSL.
#
# Usage:
# ./dev.sh # debug build + run
# ./dev.sh --release # optimised build
# ./dev.sh --skip-build # run last build
# ./dev.sh --verbose # enable debug logging when launching desktop shell
# ./dev.sh --cli # run backend CLI instead of the desktop shell
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")" && pwd)"
RUST_DIR="$REPO_ROOT/rust"
TAURI_APP_DIR="$REPO_ROOT/apps/desktop-tauri"
# ── Parse arguments ──────────────────────────────────────────────────────────
RELEASE=0
SKIP_BUILD=0
VERBOSE=0
CLI_MODE=0
for arg in "$@"; do
case "$arg" in
--release) RELEASE=1 ;;
--skip-build) SKIP_BUILD=1 ;;
--verbose) VERBOSE=1 ;;
--cli) CLI_MODE=1 ;;
-h|--help)
echo "Usage: $0 [--release] [--skip-build] [--verbose] [--cli]"
echo ""
echo "Options:"
echo " --release Optimised build"
echo " --skip-build Run last build without rebuilding"
echo " --verbose Enable debug logging"
echo " --cli Run backend CLI usage command instead of the desktop shell"
exit 0
;;
*)
echo "Unknown option: $arg"
echo "Run '$0 --help' for usage."
exit 1
;;
esac
done
# ── Check prerequisites ──────────────────────────────────────────────────────
if ! command -v cargo &>/dev/null; then
echo "ERROR: cargo (Rust) not found."
echo "Install Rust: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
exit 1
fi
# ── Detect native Linux target ────────────────────────────────────────────────
NATIVE_TARGET="$(rustc -vV | awk '/^host:/ { print $2 }')"
TARGET_FLAG=(--target "$NATIVE_TARGET")
# ── WSL detection ─────────────────────────────────────────────────────────────
IS_WSL=0
if grep -qi microsoft /proc/version 2>/dev/null || [ -n "${WSL_DISTRO_NAME:-}" ]; then
IS_WSL=1
echo "Detected WSL environment (${WSL_DISTRO_NAME:-unknown})"
if [ -z "${DISPLAY:-}" ] && [ -z "${WAYLAND_DISPLAY:-}" ]; then
echo ""
echo "No display server detected."
echo "Desktop mode requires WSLg (Windows 11) or an X server."
echo "Use --cli to run CLI commands instead."
echo ""
if [ "$CLI_MODE" -eq 0 ]; then
echo "Tip: 'codexbar usage -p claude' works without a display."
echo ""
CLI_MODE=1
echo "Auto-switching to CLI mode."
fi
fi
fi
if [ "$CLI_MODE" -eq 0 ] && ! command -v pnpm &>/dev/null; then
echo "ERROR: pnpm not found."
echo "Install pnpm to build apps/desktop-tauri before running desktop mode."
exit 1
fi
find_binary() {
local binary_name="$1"
local profile="$2"
shift 2 || true
local candidates=(
"$REPO_ROOT/target/$profile/$binary_name"
)
if [ -n "${CARGO_BUILD_TARGET:-}" ]; then
candidates+=("$REPO_ROOT/target/$CARGO_BUILD_TARGET/$profile/$binary_name")
fi
if [ -n "$NATIVE_TARGET" ]; then
candidates+=("$REPO_ROOT/target/$NATIVE_TARGET/$profile/$binary_name")
fi
local candidate
for candidate in "${candidates[@]}"; do
if [ -f "$candidate" ]; then
printf '%s\n' "$candidate"
return 0
fi
done
return 1
}
# ── Build ─────────────────────────────────────────────────────────────────────
if [ "$SKIP_BUILD" -eq 0 ]; then
if [ "$CLI_MODE" -eq 1 ]; then
if [ "$RELEASE" -eq 1 ]; then
echo "Building CodexBar CLI (release, target=$NATIVE_TARGET)..."
cargo build --manifest-path "$RUST_DIR/Cargo.toml" --bin codexbar --release "${TARGET_FLAG[@]}"
else
echo "Building CodexBar CLI (debug, target=$NATIVE_TARGET)..."
cargo build --manifest-path "$RUST_DIR/Cargo.toml" --bin codexbar "${TARGET_FLAG[@]}"
fi
else
cd "$TAURI_APP_DIR"
if [ "$RELEASE" -eq 1 ]; then
echo "Building CodexBar Desktop (release, no bundle)..."
pnpm run tauri:build
else
echo "Building CodexBar Desktop (debug, no bundle)..."
pnpm run tauri:build:debug
fi
cd "$REPO_ROOT"
fi
fi
# ── Locate binary ─────────────────────────────────────────────────────────────
PROFILE="debug"
[ "$RELEASE" -eq 1 ] && PROFILE="release"
if [ "$CLI_MODE" -eq 1 ]; then
BINARY_NAME="codexbar"
else
BINARY_NAME="codexbar-desktop-tauri"
fi
if ! BINARY="$(find_binary "$BINARY_NAME" "$PROFILE")"; then
echo "ERROR: Binary not found for $BINARY_NAME ($PROFILE)"
echo "Run without --skip-build to build first."
exit 1
fi
# ── Run ───────────────────────────────────────────────────────────────────────
echo ""
if [ "$CLI_MODE" -eq 1 ]; then
echo "Running: codexbar usage -p all"
RUN_ARGS=(usage -p all)
else
echo "Running: CodexBar Desktop"
fi
if [ "$VERBOSE" -eq 1 ]; then
if [ "$CLI_MODE" -eq 1 ]; then
RUN_ARGS=(-v "${RUN_ARGS[@]}")
else
export RUST_LOG="${RUST_LOG:-debug}"
echo "Verbose logging enabled via RUST_LOG=$RUST_LOG"
fi
fi
if [ "$CLI_MODE" -eq 0 ] && [ -z "${TAURI_DEV:-}" ]; then
export TAURI_DEV=0
fi
if [ "$CLI_MODE" -eq 1 ]; then
"$BINARY" "${RUN_ARGS[@]}"
else
"$BINARY"
fi