-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbolt.sh
More file actions
executable file
·235 lines (202 loc) · 6.18 KB
/
bolt.sh
File metadata and controls
executable file
·235 lines (202 loc) · 6.18 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env bash
set -e
RUST_VERSION="1.93.0"
PROTOBUF_VERSION="21.12"
format() {
cargo +nightly fmt;
}
setup_protobuf() {
echo "[INFO] Checking Protobuf installation..."
OS="$(uname -s)"
ARCH="$(uname -m)"
if [ "$OS" = "Linux" ]; then
sudo apt-get update -y
sudo apt-get install -y protobuf-compiler unzip
PROTO_OS="linux"
elif [ "$OS" = "Darwin" ]; then
if ! command -v brew >/dev/null 2>&1; then
echo "[WARN] Homebrew not found. Manual install will proceed but system dependencies might be missing."
fi
PROTO_OS="osx"
else
echo "[ERROR] Unsupported OS: $OS"
exit 1
fi
if [ "$ARCH" = "x86_64" ]; then
PROTO_ARCH="x86_64"
elif [ "$ARCH" = "arm64" ] || [ "$ARCH" = "aarch64" ]; then
if [ "$PROTO_OS" = "osx" ]; then
PROTO_ARCH="aarch_64"
else
PROTO_ARCH="aarch_64"
fi
else
echo "[ERROR] Unsupported architecture: $ARCH"
exit 1
fi
ZIP_FILE="protoc-$PROTOBUF_VERSION-$PROTO_OS-$PROTO_ARCH.zip"
if command -v protoc >/dev/null 2>&1; then
CURRENT_VERSION=$(protoc --version | awk '{print $2}')
echo "[INFO] Found Protobuf version $CURRENT_VERSION"
if [ "$CURRENT_VERSION" != "$PROTOBUF_VERSION" ]; then
echo "[INFO] Updating Protobuf to $PROTOBUF_VERSION..."
curl -L "https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/$ZIP_FILE" -o protoc.zip
unzip -o protoc.zip
SUDO=""
if [ ! -w "/usr/local/bin" ] || [ ! -w "/usr/local/include" ]; then
SUDO="sudo"
fi
$SUDO mv bin/protoc /usr/local/bin/
# Copy contents to avoid nesting and ensure we don't delete existing include dir if it has other things
$SUDO mkdir -p /usr/local/include/google
$SUDO cp -r include/google/* /usr/local/include/google/
rm -rf protoc.zip bin include readme.txt
else
echo "[OK] Protobuf is already $PROTOBUF_VERSION"
fi
else
echo "[INFO] Protobuf not found. Installing Protobuf $PROTOBUF_VERSION..."
curl -L "https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/$ZIP_FILE" -o protoc.zip
unzip -o protoc.zip
SUDO=""
if [ ! -w "/usr/local/bin" ] || [ ! -w "/usr/local/include" ]; then
SUDO="sudo"
fi
$SUDO mv bin/protoc /usr/local/bin/
$SUDO mkdir -p /usr/local/include/google
$SUDO cp -r include/google/* /usr/local/include/google/
rm -rf protoc.zip bin include readme.txt
fi
}
setup_rust(){
echo "[INFO] Checking Rust installation..."
OS="$(uname -s)"
if [ "$OS" = "Linux" ]; then
sudo apt-get update -y
sudo apt-get install -y build-essential curl
fi
if command -v rustc >/dev/null 2>&1; then
CURRENT_VERSION=$(rustc --version | awk '{print $2}')
echo "[INFO] Found Rust version $CURRENT_VERSION"
if [ "$CURRENT_VERSION" != "$RUST_VERSION" ]; then
echo "[INFO] Updating Rust to $RUST_VERSION..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUST_VERSION
else
echo "[OK] Rust is already $RUST_VERSION"
fi
else
echo "[INFO] Rust not found. Installing Rust $RUST_VERSION..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUST_VERSION
fi
export PATH="$HOME/.cargo/bin:$PATH"
source "$HOME/.cargo/env" 2>/dev/null || true
rustc --version
cargo --version
echo "[INFO] Installing cargo-nextest if missing..."
if ! cargo nextest --version >/dev/null 2>&1; then
cargo install cargo-nextest
fi
cargo nextest --version
rustup target add wasm32-unknown-unknown
cargo install --locked trunk
}
setup() {
setup_rust
setup_protobuf
}
clean() {
echo "[INFO] Cleaning workspace..."
cargo clean
echo "[OK] Workspace cleaned!"
}
check() {
echo "[INFO] Running cargo check..."
cargo check
echo "[OK] Cargo check passed!"
echo "[INFO] Checking code formatting..."
cargo fmt -- --check
echo "[OK] Code is properly formatted!"
echo "[INFO] Running clippy lints..."
cargo clippy -- -D warnings
echo "[OK] Clippy checks passed!"
}
build() {
echo "[INFO] Building with native CPU optimizations..."
RUSTFLAGS="-C target-cpu=native" cargo build --release
echo "[OK] Build completed!"
}
test() {
echo "[INFO] Testing workspace..."
cargo nextest run
echo "[OK] Testing completed!"
}
bench() {
echo "[INFO] Running benchmarks..."
cargo bench
echo "[OK] Benchmarks completed!"
}
launch() {
echo "[INFO] Launching application..."
trunk serve --release --public-url / --port 8080
echo "[OK] Application launched!"
}
serve() {
echo "[INFO] Starting server..."
cargo run -p server --release
echo "[OK] Application served!"
}
help() {
echo "Usage: $0 [setup|check|format|clean|build|test|bench|all|help]"
echo
echo "Commands:"
echo " setup - Install Rust and cargo-nextest"
echo " format - Format the code"
echo " check - Run cargo check, fmt, and clippy"
echo " clean - Clean the workspace"
echo " build - Only build the workspace (runs check first)"
echo " test - Only run tests"
echo " bench - Only run benchmarks"
echo " all - Run check, build, and test"
echo " help - Show this help message"
}
main() {
cmd="$1"
case "$cmd" in
setup)
setup
;;
format)
format
;;
check)
check
;;
clean)
clean
;;
build)
build
;;
test)
test
;;
bench)
bench
;;
launch)
launch
;;
serve)
serve
;;
all)
setup
check
build
;;
help|""|*)
help
;;
esac
}
main "$@"