Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·163 lines (139 loc) · 3.63 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·163 lines (139 loc) · 3.63 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
#!/usr/bin/env bash
#
# Build script for anyclaude
#
# Usage:
# ./build.sh - Build release binary
# ./build.sh debug - Build debug binary
# ./build.sh clean - Clean build artifacts
# ./build.sh test - Run tests
# ./build.sh install - Build and install to ~/.cargo/bin
# ./build.sh release-tag - Build release without dev version stamp
#
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Project root directory (where this script lives)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Print colored status message
info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
exit 1
}
# Check if Rust toolchain is installed
check_rust() {
if ! command -v cargo &> /dev/null; then
error "Cargo not found. Please install Rust: https://rustup.rs"
fi
info "Rust toolchain found: $(rustc --version)"
}
# --- Version stamping ---
# For non-release builds, stamp the version in Cargo.toml with git info:
# 0.4.0 → 0.4.0-dev.abc1234 (clean tree)
# 0.4.0 → 0.4.0-dev.abc1234.dirty (uncommitted changes)
# The original Cargo.toml is always restored after build.
BASE_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
CARGO_TOML_PATCHED=false
stamp_version() {
local commit dirty suffix
commit=$(git rev-parse --short=7 HEAD 2>/dev/null || echo "unknown")
if git diff --quiet HEAD 2>/dev/null; then
dirty=""
else
dirty=".dirty"
fi
suffix="dev.${commit}${dirty}"
local stamped="${BASE_VERSION}-${suffix}"
info "Version: ${stamped}"
# Backup and patch
cp Cargo.toml Cargo.toml.bak
sed -i '' "s/^version = \"${BASE_VERSION}\"/version = \"${stamped}\"/" Cargo.toml
CARGO_TOML_PATCHED=true
}
restore_version() {
if [ "$CARGO_TOML_PATCHED" = true ] && [ -f Cargo.toml.bak ]; then
mv Cargo.toml.bak Cargo.toml
CARGO_TOML_PATCHED=false
fi
}
# Always restore Cargo.toml on exit (error, signal, etc.)
trap restore_version EXIT
# Build release binary
build_release() {
stamp_version
info "Building release binary..."
cargo build --release
info "Build complete: target/release/anyclaude"
}
# Build tagged release (no dev stamp)
build_release_tag() {
info "Version: ${BASE_VERSION} (release)"
info "Building release binary..."
cargo build --release
info "Build complete: target/release/anyclaude"
}
# Build debug binary
build_debug() {
stamp_version
info "Building debug binary..."
cargo build
info "Build complete: target/debug/anyclaude"
}
# Clean build artifacts
clean() {
info "Cleaning build artifacts..."
cargo clean
info "Clean complete"
}
# Run tests
run_tests() {
info "Running tests..."
cargo test
info "Tests complete"
}
# Install binary to ~/.cargo/bin
install_binary() {
stamp_version
info "Building and installing..."
cargo install --path .
info "Installed to ~/.cargo/bin/anyclaude"
}
# Main entry point
main() {
check_rust
case "${1:-release}" in
release)
build_release
;;
release-tag)
build_release_tag
;;
debug)
build_debug
;;
clean)
clean
;;
test)
run_tests
;;
install)
install_binary
;;
*)
echo "Usage: $0 {release|release-tag|debug|clean|test|install}"
exit 1
;;
esac
}
main "$@"