-
Notifications
You must be signed in to change notification settings - Fork 310
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·375 lines (316 loc) · 9.27 KB
/
setup.sh
File metadata and controls
executable file
·375 lines (316 loc) · 9.27 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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#!/usr/bin/env bash
# Io Language Developer Setup Script
# This script helps set up a development environment for contributing to Io
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
# Helper functions
print_header() {
echo -e "${BLUE}===================================${NC}"
echo -e "${BLUE}$1${NC}"
echo -e "${BLUE}===================================${NC}"
}
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠ $1${NC}"
}
print_error() {
echo -e "${RED}✗ $1${NC}"
}
print_info() {
echo -e "${BLUE}ℹ $1${NC}"
}
# Detect OS
detect_os() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux"
if [ -f /etc/debian_version ]; then
DISTRO="debian"
elif [ -f /etc/redhat-release ]; then
DISTRO="redhat"
elif [ -f /etc/arch-release ]; then
DISTRO="arch"
else
DISTRO="unknown"
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
# Check for Apple Silicon
if [[ $(uname -m) == "arm64" ]]; then
ARCH="arm64"
else
ARCH="x86_64"
fi
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
OS="windows"
else
OS="unknown"
fi
}
# Check for required tools
check_requirements() {
print_header "Checking Requirements"
local missing_tools=()
# Check for Git
if command -v git &> /dev/null; then
print_success "Git installed ($(git --version | head -1))"
else
missing_tools+=("git")
fi
# Check for CMake
if command -v cmake &> /dev/null; then
print_success "CMake installed ($(cmake --version | head -1))"
else
missing_tools+=("cmake")
fi
# Check for C compiler
if command -v gcc &> /dev/null; then
print_success "GCC installed ($(gcc --version | head -1))"
elif command -v clang &> /dev/null; then
print_success "Clang installed ($(clang --version | head -1))"
else
missing_tools+=("gcc or clang")
fi
# Check for Make
if command -v make &> /dev/null; then
print_success "Make installed ($(make --version | head -1))"
else
missing_tools+=("make")
fi
if [ ${#missing_tools[@]} -gt 0 ]; then
print_error "Missing required tools: ${missing_tools[*]}"
echo ""
suggest_install
exit 1
fi
echo ""
}
# Suggest installation commands based on OS
suggest_install() {
print_info "Installation suggestions:"
case $OS in
linux)
case $DISTRO in
debian)
echo " sudo apt-get update"
echo " sudo apt-get install -y git cmake build-essential"
;;
redhat)
echo " sudo yum install -y git cmake gcc gcc-c++ make"
;;
arch)
echo " sudo pacman -S git cmake base-devel"
;;
*)
echo " Please install: git, cmake, gcc/clang, make"
;;
esac
;;
macos)
echo " # Install Homebrew if not installed:"
echo " /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
echo ""
echo " # Then install required tools:"
echo " brew install git cmake"
;;
windows)
echo " # Install using MSYS2:"
echo " pacman -S git mingw-w64-x86_64-cmake mingw-w64-x86_64-gcc make"
;;
*)
echo " Please install: git, cmake, gcc/clang, make"
;;
esac
}
# Clone or update repository
setup_repository() {
print_header "Setting Up Repository"
if [ -d ".git" ]; then
print_info "Already in a git repository"
# Check for submodules
if [ -f ".gitmodules" ]; then
print_info "Updating submodules..."
git submodule update --init --recursive
print_success "Submodules updated"
fi
else
print_error "Not in the Io repository directory!"
echo "Please run this script from the root of the Io repository."
exit 1
fi
echo ""
}
# Build Io
build_io() {
print_header "Building Io"
local build_type="${1:-Release}"
local build_dir="build"
print_info "Build type: $build_type"
# Create build directory
if [ ! -d "$build_dir" ]; then
mkdir -p "$build_dir"
print_success "Created build directory"
fi
# Configure with CMake
print_info "Configuring with CMake..."
cd "$build_dir"
local cmake_flags=""
if [[ "$OS" == "macos" && "$ARCH" == "arm64" ]]; then
print_warning "Detected Apple Silicon Mac"
# ARM64 is now supported natively
fi
cmake -DCMAKE_BUILD_TYPE="$build_type" $cmake_flags .. || {
print_error "CMake configuration failed"
cd ..
exit 1
}
print_success "CMake configuration complete"
# Build
print_info "Building Io (this may take a few minutes)..."
local num_cores
if [[ "$OS" == "macos" ]]; then
num_cores=$(sysctl -n hw.ncpu)
else
num_cores=$(nproc 2>/dev/null || echo 4)
fi
make -j"$num_cores" || {
print_error "Build failed"
cd ..
exit 1
}
cd ..
print_success "Build complete!"
echo ""
}
# Run tests
run_tests() {
print_header "Running Tests"
if [ ! -f "build/_build/binaries/io" ]; then
print_error "Io binary not found. Please build first."
return 1
fi
print_info "Running test suite..."
cd build
if ./_build/binaries/io ../libs/iovm/tests/correctness/run.io; then
print_success "All tests passed!"
else
print_warning "Some tests failed. This is normal during development."
fi
cd ..
echo ""
}
# Setup development tools
setup_dev_tools() {
print_header "Setting Up Development Tools"
# Git hooks
if [ -d ".git/hooks" ]; then
print_info "Setting up git hooks..."
# Create pre-commit hook
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/sh
# Pre-commit hook for Io
# Check for trailing whitespace
if git diff --cached --check; then
:
else
echo "Error: Trailing whitespace detected. Please fix before committing."
exit 1
fi
# Run quick tests if Io is built
if [ -f "build/_build/binaries/io" ]; then
echo "Running quick tests..."
build/_build/binaries/io -e "\"Pre-commit tests passed\" println"
fi
exit 0
EOF
chmod +x .git/hooks/pre-commit
print_success "Git hooks installed"
fi
# Optional tools
print_info "Checking optional development tools..."
if command -v clang-format &> /dev/null; then
print_success "clang-format installed (code formatting)"
else
print_info "clang-format not found (optional, for code formatting)"
fi
if command -v cppcheck &> /dev/null; then
print_success "cppcheck installed (static analysis)"
else
print_info "cppcheck not found (optional, for static analysis)"
fi
if command -v valgrind &> /dev/null; then
print_success "valgrind installed (memory debugging)"
else
print_info "valgrind not found (optional, for memory debugging)"
fi
echo ""
}
# Print next steps
print_next_steps() {
print_header "Setup Complete! 🎉"
echo "Your Io development environment is ready!"
echo ""
echo "Quick commands:"
echo " ${GREEN}make build${NC} - Build Io"
echo " ${GREEN}make test${NC} - Run tests"
echo " ${GREEN}make repl${NC} - Start Io REPL"
echo " ${GREEN}make clean${NC} - Clean build artifacts"
echo " ${GREEN}make help${NC} - Show all available commands"
echo ""
echo "Start the REPL:"
echo " ${GREEN}./build/_build/binaries/io${NC}"
echo ""
echo "Read the contribution guide:"
echo " ${GREEN}less CONTRIBUTING.md${NC}"
echo ""
echo "Happy hacking! 🚀"
}
# Main execution
main() {
print_header "Io Language Developer Setup"
echo ""
detect_os
print_info "Detected OS: $OS"
if [[ "$OS" == "linux" ]]; then
print_info "Linux distribution: $DISTRO"
elif [[ "$OS" == "macos" ]]; then
print_info "Architecture: $ARCH"
fi
echo ""
check_requirements
setup_repository
# Ask for build type
echo "Select build type:"
echo " 1) Release (optimized, recommended)"
echo " 2) Debug (with debug symbols)"
echo " 3) Skip build"
read -p "Choice [1]: " choice
case $choice in
2)
build_io "Debug"
;;
3)
print_info "Skipping build"
;;
*)
build_io "Release"
;;
esac
# Ask about running tests
if [ -f "build/_build/binaries/io" ]; then
read -p "Run tests? [Y/n]: " run_tests_choice
if [[ ! "$run_tests_choice" =~ ^[Nn]$ ]]; then
run_tests
fi
fi
setup_dev_tools
print_next_steps
}
# Run main function
main "$@"