-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·240 lines (198 loc) · 6.01 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·240 lines (198 loc) · 6.01 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
#!/bin/bash
# Build script for grepgrep
# Supports native builds for Linux, macOS, and Windows,
# plus Windows cross-compilation when the toolchain is available.
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Detect current platform
detect_platform() {
case "$(uname -s)" in
Linux*) echo "linux";;
Darwin*) echo "macos";;
CYGWIN*|MINGW*|MSYS*) echo "windows";;
*) echo "unknown";;
esac
}
# Build for Linux
build_linux() {
print_info "Building for Linux..."
# Check for Linux toolchain
if ! rustup target list | grep -q "x86_64-unknown-linux-gnu (installed)"; then
print_info "Installing Linux target..."
rustup target add x86_64-unknown-linux-gnu
fi
# Build
cargo build --release --target x86_64-unknown-linux-gnu
# Create output directory
mkdir -p dist/linux
# Copy binary
cp target/x86_64-unknown-linux-gnu/release/grepgrep dist/linux/
print_success "Linux build complete: dist/linux/grepgrep"
}
# Build for macOS
build_macos() {
print_info "Building for macOS..."
local current_platform=$(detect_platform)
if [ "$current_platform" != "macos" ]; then
print_error "macOS builds must be run on a macOS host. Cross-compilation is not configured in this script."
exit 1
fi
cargo build --release
mkdir -p dist/macos
cp target/release/grepgrep dist/macos/
print_success "macOS build complete: dist/macos/grepgrep"
}
# Build for Windows (requires mingw-w64 or cross-compilation setup)
build_windows() {
print_info "Building for Windows..."
local current_platform=$(detect_platform)
if [ "$current_platform" = "windows" ]; then
# Native Windows build
cargo build --release
mkdir -p dist/windows
cp target/release/grepgrep.exe dist/windows/ 2>/dev/null || \
cp target/release/grepgrep dist/windows/grepgrep.exe
print_success "Windows build complete: dist/windows/grepgrep.exe"
else
# Cross-compilation from Linux/macOS
print_info "Cross-compiling for Windows..."
# Check for Windows target
if ! rustup target list | grep -q "x86_64-pc-windows-gnu (installed)"; then
print_info "Installing Windows target..."
rustup target add x86_64-pc-windows-gnu
fi
# Check for mingw-w64
if ! command -v x86_64-w64-mingw32-gcc &> /dev/null; then
print_warning "mingw-w64 not found. Installing..."
if command -v apt-get &> /dev/null; then
sudo apt-get install -y mingw-w64
elif command -v dnf &> /dev/null; then
sudo dnf install -y mingw64-gcc
elif command -v pacman &> /dev/null; then
sudo pacman -S --noconfirm mingw-w64-gcc
else
print_error "Please install mingw-w64 manually for cross-compilation"
exit 1
fi
fi
# Build with Windows target
cargo build --release --target x86_64-pc-windows-gnu
# Create output directory
mkdir -p dist/windows
# Copy binary
cp target/x86_64-pc-windows-gnu/release/grepgrep.exe dist/windows/
print_success "Windows build complete: dist/windows/grepgrep.exe"
fi
}
# Build for current platform
build_current() {
local platform=$(detect_platform)
print_info "Building for current platform: $platform"
cargo build --release
mkdir -p dist/$platform
case $platform in
linux|macos)
cp target/release/grepgrep dist/$platform/
;;
windows)
cp target/release/grepgrep.exe dist/$platform/ 2>/dev/null || \
cp target/release/grepgrep dist/$platform/grepgrep.exe
;;
esac
print_success "Build complete: dist/$platform/"
}
# Build for all platforms
build_all() {
print_info "Building for all platforms..."
build_linux
build_windows
if [ "$(detect_platform)" = "macos" ]; then
build_macos
else
print_warning "Skipping macOS build because it requires a macOS host"
fi
print_success "All builds complete!"
}
# Clean build artifacts
clean() {
print_info "Cleaning build artifacts..."
cargo clean
rm -rf dist/
print_success "Clean complete"
}
# Show help
show_help() {
echo "grepgrep Build Script"
echo ""
echo "Usage: $0 [command]"
echo ""
echo "Commands:"
echo " linux Build for Linux (x86_64)"
echo " macos Build for macOS (native macOS host only)"
echo " windows Build for Windows (x86_64)"
echo " current Build for current platform"
echo " all Build for all platforms"
echo " clean Remove build artifacts"
echo " help Show this help message"
echo ""
echo "Examples:"
echo " $0 linux # Build for Linux"
echo " $0 macos # Build for macOS"
echo " $0 windows # Build for Windows"
echo " $0 --platform linux # Alternative syntax"
echo ""
echo "Current platform: $(detect_platform)"
}
# Main entry point
main() {
local command=${1:-"help"}
# Handle --platform flag
if [ "$1" = "--platform" ] && [ -n "$2" ]; then
command="$2"
fi
case $command in
linux)
build_linux
;;
macos)
build_macos
;;
windows)
build_windows
;;
current)
build_current
;;
all)
build_all
;;
clean)
clean
;;
help|--help|-h)
show_help
;;
*)
print_error "Unknown command: $command"
show_help
exit 1
;;
esac
}
main "$@"