Skip to content

Commit 6e3fb3e

Browse files
star-gaclaude
andcommitted
Add GLIBC detection with source build fallback
- Detect GLIBC version on Linux systems - Fall back to source build if GLIBC < 2.31 - Add --source flag to force source build Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e870016 commit 6e3fb3e

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

scripts/install.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ LOCAL_MODE=false
1616
CUDA_SUPPORT=false
1717
METAL_SUPPORT=false
1818
ROCM_SUPPORT=false
19+
SOURCE_BUILD=false
20+
21+
# Minimum GLIBC version for prebuilt binaries
22+
MIN_GLIBC_MAJOR=2
23+
MIN_GLIBC_MINOR=31
1924

2025
# Colors
2126
RED='\033[0;31m'
@@ -90,6 +95,34 @@ detect_platform() {
9095
log "Detected platform: ${PLATFORM}"
9196
}
9297

98+
detect_glibc() {
99+
# Only check GLIBC on Linux
100+
if [ "$OS" != "linux" ]; then
101+
return 0
102+
fi
103+
104+
# Get GLIBC version
105+
if command -v ldd &>/dev/null; then
106+
GLIBC_VERSION=$(ldd --version 2>&1 | head -1 | grep -oE '[0-9]+\.[0-9]+' | head -1)
107+
if [ -n "$GLIBC_VERSION" ]; then
108+
GLIBC_MAJOR=$(echo "$GLIBC_VERSION" | cut -d. -f1)
109+
GLIBC_MINOR=$(echo "$GLIBC_VERSION" | cut -d. -f2)
110+
111+
log "Detected GLIBC: ${GLIBC_VERSION}"
112+
113+
# Check if GLIBC is too old
114+
if [ "$GLIBC_MAJOR" -lt "$MIN_GLIBC_MAJOR" ] || \
115+
([ "$GLIBC_MAJOR" -eq "$MIN_GLIBC_MAJOR" ] && [ "$GLIBC_MINOR" -lt "$MIN_GLIBC_MINOR" ]); then
116+
warn "GLIBC ${GLIBC_VERSION} is older than required ${MIN_GLIBC_MAJOR}.${MIN_GLIBC_MINOR}"
117+
warn "Falling back to source build..."
118+
SOURCE_BUILD=true
119+
fi
120+
fi
121+
else
122+
warn "Cannot detect GLIBC version, assuming compatible"
123+
fi
124+
}
125+
93126
detect_gpu() {
94127
# NVIDIA CUDA
95128
if command -v nvidia-smi &>/dev/null; then
@@ -133,6 +166,10 @@ parse_args() {
133166
ROCM_SUPPORT=true
134167
shift
135168
;;
169+
--source)
170+
SOURCE_BUILD=true
171+
shift
172+
;;
136173
--version)
137174
VERSION="$2"
138175
shift 2
@@ -144,6 +181,7 @@ parse_args() {
144181
echo ""
145182
echo "Options:"
146183
echo " --local Install from local build (development)"
184+
echo " --source Build from source (for old GLIBC systems)"
147185
echo " --cuda Enable NVIDIA CUDA support"
148186
echo " --metal Enable Apple Metal support"
149187
echo " --rocm Enable AMD ROCm support"
@@ -168,6 +206,67 @@ create_directories() {
168206
mkdir -p "${INSTALL_DIR}/syzygy"
169207
}
170208

209+
install_from_source() {
210+
log "Building from source (GLIBC compatibility mode)..."
211+
212+
# Check for build dependencies
213+
if ! command -v git &>/dev/null; then
214+
error "git is required for source build. Install with: sudo apt install git"
215+
fi
216+
217+
# Clone NikolaChess source
218+
NIKOLACHESS_SRC="${INSTALL_DIR}/src/NikolaChess"
219+
if [ ! -d "$NIKOLACHESS_SRC" ]; then
220+
log "Cloning NikolaChess source..."
221+
mkdir -p "${INSTALL_DIR}/src"
222+
git clone --depth 1 https://github.com/star-ga/NikolaChess.git "$NIKOLACHESS_SRC" || \
223+
error "Failed to clone NikolaChess"
224+
fi
225+
226+
# Download mindc compiler (still needs compatible GLIBC, try anyway)
227+
log "Downloading mindc compiler..."
228+
MINDC_TAR="https://github.com/star-ga/mind/releases/download/v0.1.9/mindc-${PLATFORM}.tar.gz"
229+
if curl -fsSL "$MINDC_TAR" -o "/tmp/mindc-${PLATFORM}.tar.gz" 2>/dev/null; then
230+
tar -xzf "/tmp/mindc-${PLATFORM}.tar.gz" -C "${INSTALL_DIR}/bin/"
231+
chmod +x "${INSTALL_DIR}/bin/mindc"
232+
rm -f "/tmp/mindc-${PLATFORM}.tar.gz"
233+
log "Downloaded mindc"
234+
else
235+
warn "Could not download mindc - may need to build from source"
236+
warn "Visit https://github.com/star-ga/mind for build instructions"
237+
return 1
238+
fi
239+
240+
# Download runtime libraries
241+
log "Downloading runtime libraries..."
242+
RUNTIME_URL="https://github.com/star-ga/NikolaChess/releases/download/v${VERSION}/libmind_cpu_${PLATFORM}.${LIB_EXT}"
243+
if curl -fsSL "$RUNTIME_URL" -o "${INSTALL_DIR}/lib/libmind_cpu_${PLATFORM}.${LIB_EXT}" 2>/dev/null; then
244+
log "Downloaded CPU runtime"
245+
else
246+
warn "Could not download runtime library"
247+
fi
248+
249+
# Build NikolaChess from source
250+
log "Building NikolaChess..."
251+
cd "$NIKOLACHESS_SRC"
252+
export MIND_LIB_PATH="${INSTALL_DIR}/lib"
253+
export PATH="${INSTALL_DIR}/bin:$PATH"
254+
255+
if "${INSTALL_DIR}/bin/mindc" build --release --target cpu 2>/dev/null; then
256+
if [ -f "target/release/nikola-cpu" ]; then
257+
cp "target/release/nikola-cpu" "${INSTALL_DIR}/bin/nikola"
258+
chmod +x "${INSTALL_DIR}/bin/nikola"
259+
log "Built and installed nikola"
260+
elif [ -f "target/release/nikola" ]; then
261+
cp "target/release/nikola" "${INSTALL_DIR}/bin/nikola"
262+
chmod +x "${INSTALL_DIR}/bin/nikola"
263+
log "Built and installed nikola"
264+
fi
265+
else
266+
error "Failed to build NikolaChess from source"
267+
fi
268+
}
269+
171270
install_local() {
172271
log "Installing from local build..."
173272

@@ -337,11 +436,14 @@ main() {
337436
print_banner
338437
parse_args "$@"
339438
detect_platform
439+
detect_glibc
340440
detect_gpu
341441
create_directories
342442

343443
if [ "$LOCAL_MODE" = true ]; then
344444
install_local
445+
elif [ "$SOURCE_BUILD" = true ]; then
446+
install_from_source
345447
else
346448
install_remote
347449
fi

0 commit comments

Comments
 (0)