-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·307 lines (273 loc) · 5.87 KB
/
build.sh
File metadata and controls
executable file
·307 lines (273 loc) · 5.87 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/bin/bash
# Build script for Octomind development
# This script provides common build operations for development workflow
set -e
# Configuration
BINARY_NAME="octomind"
BUILD_MODE="release"
VERBOSE=""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Helper functions
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Show help
show_help() {
echo "Octomind Build Script"
echo ""
echo "Usage: $0 [command] [options]"
echo ""
echo "Commands:"
echo " build Build the project (default)"
echo " test Run tests"
echo " check Run cargo check"
echo " fmt Format code"
echo " clippy Run clippy lints"
echo " clean Clean build artifacts"
echo " run Build and run the binary"
echo " watch Watch for changes and rebuild"
echo " size Show binary size information"
echo " deps Show dependency tree"
echo " audit Run security audit"
echo " all Run fmt, clippy, test, and build"
echo ""
echo "Options:"
echo " --debug Build in debug mode"
echo " --verbose Verbose output"
echo " --help Show this help"
echo ""
echo "Examples:"
echo " $0 build # Build in release mode"
echo " $0 build --debug # Build in debug mode"
echo " $0 test --verbose # Run tests with verbose output"
echo " $0 run -- --help # Build and run with --help flag"
}
# Parse arguments
parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
--debug)
BUILD_MODE="debug"
shift
;;
--verbose)
VERBOSE="--verbose"
shift
;;
--help)
show_help
exit 0
;;
--)
shift
RUN_ARGS="$*"
break
;;
*)
if [ -z "$COMMAND" ]; then
COMMAND="$1"
else
log_error "Unknown option: $1"
exit 1
fi
shift
;;
esac
done
# Default command
if [ -z "$COMMAND" ]; then
COMMAND="build"
fi
}
# Get cargo flags based on build mode
get_cargo_flags() {
if [ "$BUILD_MODE" = "release" ]; then
echo "--release"
else
echo ""
fi
}
# Get binary path based on build mode
get_binary_path() {
if [ "$BUILD_MODE" = "release" ]; then
echo "target/release/$BINARY_NAME"
else
echo "target/debug/$BINARY_NAME"
fi
}
# Build the project
cmd_build() {
log_info "Building $BINARY_NAME in $BUILD_MODE mode..."
cargo build $(get_cargo_flags) $VERBOSE
local binary_path=$(get_binary_path)
if [ -f "$binary_path" ]; then
log_success "Build complete: $binary_path"
# Show binary size
local size=$(du -h "$binary_path" | cut -f1)
log_info "Binary size: $size"
else
log_error "Build failed: binary not found"
exit 1
fi
}
# Run tests
cmd_test() {
log_info "Running tests..."
cargo test $(get_cargo_flags) $VERBOSE
log_success "Tests passed!"
}
# Run cargo check
cmd_check() {
log_info "Running cargo check..."
cargo check $VERBOSE
log_success "Check passed!"
}
# Format code
cmd_fmt() {
log_info "Formatting code..."
cargo fmt --all
log_success "Code formatted!"
}
# Run clippy
cmd_clippy() {
log_info "Running clippy..."
cargo clippy --all-targets --all-features $VERBOSE -- -D warnings
log_success "Clippy passed!"
}
# Clean build artifacts
cmd_clean() {
log_info "Cleaning build artifacts..."
cargo clean $VERBOSE
log_success "Clean complete!"
}
# Build and run
cmd_run() {
cmd_build
local binary_path=$(get_binary_path)
log_info "Running $binary_path $RUN_ARGS"
"$binary_path" $RUN_ARGS
}
# Watch for changes
cmd_watch() {
if ! command -v cargo-watch >/dev/null 2>&1; then
log_warning "cargo-watch not found. Installing..."
cargo install cargo-watch
fi
log_info "Watching for changes..."
cargo watch -x "build $(get_cargo_flags)"
}
# Show binary size information
cmd_size() {
cmd_build
local binary_path=$(get_binary_path)
log_info "Binary size information:"
echo ""
echo "File size:"
ls -lh "$binary_path"
echo ""
if command -v bloaty >/dev/null 2>&1; then
echo "Detailed size breakdown (bloaty):"
bloaty "$binary_path"
elif command -v size >/dev/null 2>&1; then
echo "Size breakdown:"
size "$binary_path"
else
log_warning "Install 'bloaty' or 'binutils' for detailed size analysis"
fi
}
# Show dependency tree
cmd_deps() {
log_info "Dependency tree:"
cargo tree
}
# Run security audit
cmd_audit() {
if ! command -v cargo-audit >/dev/null 2>&1; then
log_warning "cargo-audit not found. Installing..."
cargo install cargo-audit
fi
log_info "Running security audit..."
cargo audit
log_success "Security audit passed!"
}
# Run all checks
cmd_all() {
log_info "Running complete development workflow..."
cmd_fmt
cmd_clippy
cmd_test
cmd_build
log_success "All checks passed!"
}
# Main execution
main() {
parse_args "$@"
# Check if we're in a Rust project
if [ ! -f "Cargo.toml" ]; then
log_error "Not a Rust project (Cargo.toml not found)"
exit 1
fi
# Execute command
case "$COMMAND" in
build)
cmd_build
;;
test)
cmd_test
;;
check)
cmd_check
;;
fmt)
cmd_fmt
;;
clippy)
cmd_clippy
;;
clean)
cmd_clean
;;
run)
cmd_run
;;
watch)
cmd_watch
;;
size)
cmd_size
;;
deps)
cmd_deps
;;
audit)
cmd_audit
;;
all)
cmd_all
;;
help)
show_help
;;
*)
log_error "Unknown command: $COMMAND"
echo "Run '$0 --help' for usage information"
exit 1
;;
esac
}
# Run main function
main "$@"