-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·339 lines (291 loc) · 8.46 KB
/
install.sh
File metadata and controls
executable file
·339 lines (291 loc) · 8.46 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#!/bin/bash
#
# rusty-cpp installer
#
# This script installs system dependencies and builds rusty-cpp from source.
# Z3 is automatically downloaded during build (no manual installation needed).
#
# Supported platforms:
# - macOS (via Homebrew)
# - Debian/Ubuntu (apt)
# - Fedora/CentOS/RHEL (dnf/yum)
# - Arch Linux (pacman)
#
# Usage:
# curl -sSL https://raw.githubusercontent.com/shuaimu/rusty-cpp/main/install.sh | bash
#
# Or clone and run locally:
# git clone https://github.com/shuaimu/rusty-cpp
# cd rusty-cpp
# ./install.sh
#
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_banner() {
echo -e "${BLUE}"
echo "╔═══════════════════════════════════════════════════════════════╗"
echo "║ rusty-cpp installer ║"
echo "║ Rust's borrow checker rules applied to C++ code ║"
echo "╚═══════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
}
info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
success() {
echo -e "${GREEN}[OK]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
exit 1
}
# Detect OS and distribution
detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
return
fi
if [[ -f /etc/os-release ]]; then
. /etc/os-release
case "$ID" in
ubuntu|debian|linuxmint|pop)
OS="debian"
;;
fedora)
OS="fedora"
;;
centos|rhel|rocky|almalinux)
OS="centos"
;;
arch|manjaro|endeavouros)
OS="arch"
;;
*)
# Check for derivatives
if [[ "$ID_LIKE" == *"debian"* ]]; then
OS="debian"
elif [[ "$ID_LIKE" == *"fedora"* ]] || [[ "$ID_LIKE" == *"rhel"* ]]; then
OS="fedora"
elif [[ "$ID_LIKE" == *"arch"* ]]; then
OS="arch"
else
OS="unknown"
fi
;;
esac
else
OS="unknown"
fi
}
# Check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check if running as root (for package installation)
check_sudo() {
if [[ $EUID -eq 0 ]]; then
SUDO=""
elif command_exists sudo; then
SUDO="sudo"
else
error "This script requires sudo privileges to install packages"
fi
}
# Install dependencies on macOS
install_macos() {
info "Detected macOS"
if ! command_exists brew; then
error "Homebrew is required. Install it from https://brew.sh"
fi
info "Installing LLVM and Z3 via Homebrew..."
brew install llvm z3
# Set up environment for clang
LLVM_PREFIX=$(brew --prefix llvm)
export LLVM_CONFIG_PATH="$LLVM_PREFIX/bin/llvm-config"
export LIBCLANG_PATH="$LLVM_PREFIX/lib"
success "Dependencies installed"
echo ""
warn "Add these to your shell profile (~/.zshrc or ~/.bashrc):"
echo " export LLVM_CONFIG_PATH=\"$LLVM_PREFIX/bin/llvm-config\""
echo " export LIBCLANG_PATH=\"$LLVM_PREFIX/lib\""
echo ""
}
# Install dependencies on Debian/Ubuntu
install_debian() {
info "Detected Debian/Ubuntu-based system"
check_sudo
info "Updating package lists..."
$SUDO apt-get update -qq
# Try to find the best available LLVM version (minimum 16)
LLVM_VERSION=""
for v in 19 18 17 16; do
if apt-cache show "libclang-${v}-dev" >/dev/null 2>&1; then
LLVM_VERSION=$v
break
fi
done
if [[ -z "$LLVM_VERSION" ]]; then
error "Could not find a suitable LLVM version (16+). Please install LLVM 16 or later manually.
On Ubuntu 22.04+, you can add the LLVM apt repository:
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 16"
fi
info "Installing LLVM $LLVM_VERSION and Z3..."
$SUDO apt-get install -y \
llvm-${LLVM_VERSION}-dev \
libclang-${LLVM_VERSION}-dev \
clang-${LLVM_VERSION} \
libz3-dev \
pkg-config \
build-essential
# Set up environment
export LLVM_CONFIG_PATH="/usr/bin/llvm-config-${LLVM_VERSION}"
export LIBCLANG_PATH="/usr/lib/llvm-${LLVM_VERSION}/lib"
success "Dependencies installed (LLVM $LLVM_VERSION)"
}
# Install dependencies on Fedora
install_fedora() {
info "Detected Fedora"
check_sudo
info "Installing LLVM and Z3..."
$SUDO dnf install -y \
llvm-devel \
clang-devel \
clang-libs \
z3-devel \
pkg-config \
gcc \
gcc-c++
success "Dependencies installed"
}
# Install dependencies on CentOS/RHEL
install_centos() {
info "Detected CentOS/RHEL"
check_sudo
# Check CentOS version
if [[ -f /etc/centos-release ]]; then
CENTOS_VERSION=$(rpm -E %{rhel})
else
CENTOS_VERSION=$(rpm -E %{rhel} 2>/dev/null || echo "8")
fi
if [[ "$CENTOS_VERSION" -ge 8 ]]; then
info "Enabling PowerTools/CRB repository..."
$SUDO dnf install -y epel-release
# CentOS 8 Stream / RHEL 8
$SUDO dnf config-manager --set-enabled powertools 2>/dev/null || \
$SUDO dnf config-manager --set-enabled crb 2>/dev/null || \
warn "Could not enable PowerTools/CRB repo"
info "Installing LLVM and Z3..."
$SUDO dnf install -y \
llvm-devel \
clang-devel \
clang-libs \
z3-devel \
pkg-config \
gcc \
gcc-c++
else
error "CentOS/RHEL 7 or earlier is not supported. Please upgrade to version 8+."
fi
success "Dependencies installed"
}
# Install dependencies on Arch Linux
install_arch() {
info "Detected Arch Linux"
check_sudo
info "Installing LLVM and Z3..."
$SUDO pacman -Sy --needed --noconfirm \
llvm \
clang \
z3 \
pkgconf \
base-devel
success "Dependencies installed"
}
# Check if Rust/Cargo is installed
check_rust() {
if ! command_exists cargo; then
warn "Rust/Cargo not found. Installing via rustup..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
success "Rust installed"
else
success "Rust/Cargo found: $(cargo --version)"
fi
}
# Build and install rusty-cpp
install_rusty_cpp() {
info "Building and installing rusty-cpp..."
# Check if we're in the rusty-cpp directory
if [[ -f "Cargo.toml" ]] && grep -q "rusty-cpp" Cargo.toml 2>/dev/null; then
info "Installing from local directory..."
cargo install --path .
else
info "Installing from crates.io..."
cargo install rusty-cpp
fi
success "rusty-cpp installed successfully!"
}
# Verify installation
verify_installation() {
echo ""
info "Verifying installation..."
if command_exists rusty-cpp-checker; then
success "rusty-cpp-checker is available in PATH"
echo ""
echo -e "${GREEN}Installation complete!${NC}"
echo ""
echo "Usage:"
echo " rusty-cpp-checker your_file.cpp"
echo ""
echo "For more information:"
echo " rusty-cpp-checker --help"
else
warn "rusty-cpp-checker not found in PATH"
echo "Make sure ~/.cargo/bin is in your PATH:"
echo " export PATH=\"\$HOME/.cargo/bin:\$PATH\""
fi
}
# Main installation flow
main() {
print_banner
detect_os
info "Detected OS: $OS"
case "$OS" in
macos)
install_macos
;;
debian)
install_debian
;;
fedora)
install_fedora
;;
centos)
install_centos
;;
arch)
install_arch
;;
unknown)
error "Unsupported operating system. Please install dependencies manually:
- LLVM/Clang 16+ with development headers
- Rust toolchain
Then run: cargo install rusty-cpp"
;;
esac
check_rust
install_rusty_cpp
verify_installation
}
# Run main function
main "$@"