-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·208 lines (173 loc) · 5.6 KB
/
build.sh
File metadata and controls
executable file
·208 lines (173 loc) · 5.6 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
#!/usr/bin/env bash
# =============================================================================
# BlueOS — Unified Build Script
# =============================================================================
#
# Builds both the C++ sovereign runtime (llama.cpp + custom kernels)
# and the Rust BlueOS workspace in the correct order.
#
# Usage:
# ./build.sh # Build everything (release)
# ./build.sh debug # Build with debug symbols
# ./build.sh rust-only # Build only Rust crates (mock mode)
# ./build.sh cpp-only # Build only C++ sovereign runtime
# ./build.sh clean # Clean all build artifacts
# ./build.sh test # Run all tests
#
# Prerequisites:
# - Rust toolchain (rustup)
# - CMake 3.18+
# - C++17 compiler (gcc/clang)
# - CUDA toolkit (optional — for GPU kernels)
# - NASM assembler (optional — for Blue-IR)
#
# =============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SOVEREIGN_DIR="${SCRIPT_DIR}/sovereign"
BLUEOS_DIR="${SCRIPT_DIR}/blueos"
BUILD_DIR="${SOVEREIGN_DIR}/build"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log() { echo -e "${BLUE}[BlueOS]${NC} $*"; }
ok() { echo -e "${GREEN}[BlueOS]${NC} $*"; }
warn() { echo -e "${YELLOW}[BlueOS]${NC} $*"; }
err() { echo -e "${RED}[BlueOS]${NC} $*" >&2; }
# =============================================================================
# Detect capabilities
# =============================================================================
detect_cuda() {
if command -v nvcc &>/dev/null; then
CUDA_AVAILABLE=1
CUDA_VERSION=$(nvcc --version | grep -oP 'release \K[\d.]+')
log "CUDA detected: ${CUDA_VERSION}"
else
CUDA_AVAILABLE=0
warn "CUDA not found — building without GPU kernel support"
fi
}
detect_llama_cpp() {
if [ -f "${SOVEREIGN_DIR}/llama.cpp/CMakeLists.txt" ]; then
LLAMA_AVAILABLE=1
log "llama.cpp submodule found"
else
LLAMA_AVAILABLE=0
warn "llama.cpp submodule not found — CMake will fetch it"
warn "Run: cd sovereign && git submodule update --init llama.cpp"
fi
}
# =============================================================================
# Build C++ sovereign runtime
# =============================================================================
build_cpp() {
log "Building C++ sovereign runtime..."
mkdir -p "${BUILD_DIR}"
cd "${BUILD_DIR}"
local cmake_args=(
-DCMAKE_BUILD_TYPE="${BUILD_TYPE:-Release}"
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
)
if [ "${CUDA_AVAILABLE}" -eq 1 ]; then
cmake_args+=(-DBLUE_CUDA=ON)
else
cmake_args+=(-DBLUE_CUDA=OFF)
fi
cmake "${cmake_args[@]}" ..
local nproc
nproc=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
cmake --build . --parallel "${nproc}"
ok "C++ build complete: ${BUILD_DIR}/libblueruntime.a"
cd "${SCRIPT_DIR}"
}
# =============================================================================
# Build Rust workspace
# =============================================================================
build_rust() {
log "Building Rust workspace..."
cd "${BLUEOS_DIR}"
local cargo_args=(--workspace)
local features=""
if [ "${BUILD_TYPE:-Release}" = "Release" ]; then
cargo_args+=(--release)
fi
# If C++ library was built, enable native feature
if [ -f "${BUILD_DIR}/libblueruntime.a" ]; then
features="native"
log "Linking against libblueruntime.a (native mode)"
else
warn "libblueruntime.a not found — building in mock mode"
fi
if [ -n "${features}" ]; then
cargo build "${cargo_args[@]}" --features "${features}"
else
cargo build "${cargo_args[@]}"
fi
ok "Rust build complete"
cd "${SCRIPT_DIR}"
}
# =============================================================================
# Test
# =============================================================================
run_tests() {
log "Running Rust tests..."
cd "${BLUEOS_DIR}"
cargo test --workspace -- --test-threads=1
ok "All Rust tests passed"
if [ -f "${BUILD_DIR}/test_kernels" ]; then
log "Running CUDA kernel correctness tests..."
"${BUILD_DIR}/test_kernels"
ok "CUDA kernel tests passed"
fi
cd "${SCRIPT_DIR}"
}
# =============================================================================
# Clean
# =============================================================================
clean() {
log "Cleaning build artifacts..."
rm -rf "${BUILD_DIR}"
cd "${BLUEOS_DIR}" && cargo clean
ok "Clean complete"
}
# =============================================================================
# Main
# =============================================================================
main() {
local mode="${1:-all}"
BUILD_TYPE="${2:-Release}"
if [ "${mode}" = "debug" ]; then
BUILD_TYPE="Debug"
mode="all"
fi
detect_cuda
detect_llama_cpp
case "${mode}" in
all)
build_cpp
build_rust
ok "Full build complete!"
;;
cpp-only)
build_cpp
;;
rust-only)
build_rust
;;
test)
run_tests
;;
clean)
clean
;;
*)
err "Unknown mode: ${mode}"
echo "Usage: $0 [all|debug|rust-only|cpp-only|test|clean]"
exit 1
;;
esac
}
main "$@"