igneum/tools/workers-remote.sh
igneum-josh 07172f5292 workers-remote.sh: the host's /usr/include stays out of the zig build (the OpenCL headers through a CL-only symlink dir); both workers proven at glibc 2.36
The previous commit's 'the workers at 2.36' was not yet true: the first zig build died on __isoc23_strtol because -I /usr/include
for CL/cl.h put Ubuntu's glibc 2.39 stdlib.h in front of zig's bundled 2.36 headers. Fixed; proof on the box (6 s):
igneum-worker-cuda 6,759,272 B sha256 690c8e91..., igneum-worker-opencl 307,264 B sha256 329fb6a9..., each needing GLIBC_2.34
and libc only, the ceiling check passing. The two static flags zig ignores are dropped on the zig path (zig links its libc++ in).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-07 00:40:14 +01:00

56 lines
5.8 KiB
Bash
Executable file

#!/usr/bin/env bash
# shellcheck disable=SC2034 # the BS_* context variables are read by lib.sh
# Build the two Linux GPU workers (igneum-worker-cuda from proto-cuda/nvrtc/worker.cpp, igneum-worker-opencl from
# proto-opencl/host.c) on igneum-build-1 instead of the Mac's zig cross-build (infra/cross/build-workers-linux.sh). Same sources
# and defines as that script; the box's clang++ and the CUDA 12.8 headers that provision.sh installs (no nvcc: both workers
# dlopen libcuda, libnvrtc and libOpenCL at run time). libstdc++ and libgcc are linked statically so a fleet box with an older
# libstdc++ (Ubuntu 22.04) runs them; the glibc ceiling of each binary is printed (a native Ubuntu 24.04 build; the HiveOS
# package keeps the Mac's zig build at glibc 2.36 until zig is on the box).
#
# tools/workers-remote.sh [--out <dir>] from any worktree of the igneum repo; artefacts in <worktree>/infra/cross/out-workers-box/
#
# Sources travel as HEAD through the mirror plus the overlay of proto-cuda and proto-opencl (lib.sh); the build takes a remote
# slot like every other build. Asked for by main on 6 October 2026 for the class v4 rehearsal (the fleet agent's generator-4 worker).
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC2034
BS_TOOL=workers-remote
# shellcheck source=../infra/build-server/lib.sh
. "$HERE/../infra/build-server/lib.sh"
OUT=""; while [ $# -gt 0 ]; do case "$1" in --out) OUT="$2"; shift 2 ;; *) bs_die "unknown argument $1" ;; esac; done
bs_host
# the context by hand (bs_context wants a Cargo.toml): the igneum worktree root is the repo; lib.sh reads these
BS_TOP=$(git -C "$HERE" rev-parse --show-toplevel); BS_WT_ROOT="$BS_TOP"; BS_KIND=repo; BS_MIRROR="$BS_MIRROR_REPO"; BS_TOP_REL=.
BS_WT=$(basename "$BS_WT_ROOT"); BS_CRATE_REL=proto-cuda; BS_REMOTE_WT="$BS_ROOT_REMOTE/$BS_WT"; BS_REMOTE_CRATE="$BS_REMOTE_WT"
BS_BRANCH=$(git -C "$BS_TOP" branch --show-current 2>/dev/null || true); BS_SHA=$(git -C "$BS_TOP" rev-parse HEAD); [ -n "$BS_BRANCH" ] || BS_BRANCH="detached-$(git -C "$BS_TOP" rev-parse --short HEAD)"
BS_LOCAL_DIRS="proto-cuda proto-opencl"; BS_VENDOR_REPOS=""
[ -n "$OUT" ] || OUT="$BS_WT_ROOT/infra/cross/out-workers-box"
bs_log "workers from $BS_WT at $BS_SHA ($BS_BRANCH) -> $BS_HOST:$BS_REMOTE_WT (proto-cuda, proto-opencl)"
bs_sync_sources
PLACEHOLDER=proto-cuda/packs/igneum-devnet-v4-epoch0 # the OpenCL worker's compile-time pack, as build-workers-linux.sh
GLIBC="${GLIBC:-2.36}" # the workers ship to HiveOS rigs and Debian 12 seeds: zig targets glibc 2.36 as the Mac's build-workers-linux.sh does; GLIBC=native uses clang (2.39: the box, Ubuntu 24.04 hosts)
# zig brings its own libc and libc++ headers and links them statically; the host's /usr/include must stay OUT of the search path
# (7 Oct 2026: `-I /usr/include` for CL/cl.h pulled Ubuntu's glibc 2.39 stdlib.h in front of zig's 2.36 one and the link died on
# __isoc23_strtol), so the OpenCL headers are reached through a directory that holds only CL/ (a symlink made on the box)
if [ "$GLIBC" = native ]; then CXX='clang++ -std=c++17 -static-libstdc++ -static-libgcc'; CC='clang -std=gnu99 -static-libgcc'; else CXX="zig c++ -target x86_64-linux-gnu.$GLIBC -std=c++17"; CC="zig cc -target x86_64-linux-gnu.$GLIBC -std=gnu99"; fi
cmd="$(bs_repro_env)"'. /etc/profile.d/igneum-build.sh
CUDA=$(ls -d /usr/local/cuda-12.* 2>/dev/null | sort -V | tail -1); [ -n "$CUDA" ] || { echo "no CUDA headers under /usr/local/cuda-12.*: provision.sh step_cuda"; exit 2; }
[ -f /usr/include/CL/cl.h ] || { echo "no /usr/include/CL/cl.h: apt opencl-c-headers"; exit 2; }
mkdir -p out-workers-box "$HOME/.cache/igneum-cl"; ln -sfn /usr/include/CL "$HOME/.cache/igneum-cl/CL"
echo "workers-remote: '"$CXX"' ($(zig version 2>/dev/null || clang++ --version | head -1)); CUDA headers $CUDA/include; $(git rev-parse --short HEAD)"
'"$CXX"' -O2 -Wall -Wextra -I proto-cuda/nvrtc -I "$CUDA/include" -o out-workers-box/igneum-worker-cuda proto-cuda/nvrtc/worker.cpp -ldl -lpthread || exit 1
'"$CC"' -D_GNU_SOURCE -O2 -Wall -Wextra -Wno-format-truncation -DIGNEUM_CL_DYNAMIC -DCL_TARGET_OPENCL_VERSION=120 -I "$HOME/.cache/igneum-cl" -I '"$PLACEHOLDER"' -DIGNEUM_KERNEL_PATH='"'"'"kernel_bound.cl"'"'"' -o out-workers-box/igneum-worker-opencl proto-opencl/host.c -ldl -lm -lpthread || exit 1
for b in igneum-worker-cuda igneum-worker-opencl; do printf "workers-remote: %s glibc ceiling %s, needs %s\n" "$b" "$(objdump -T out-workers-box/$b | grep -oE "GLIBC_[0-9.]+" | sort -V | tail -1)" "$(readelf -d out-workers-box/$b | grep -oE "\[lib[^]]+\]" | tr -d "[]" | tr "\n" " ")"; done'
BR_KIND=other BR_COMMAND="clang++ worker.cpp; clang host.c" BR_TARGET=x86_64-unknown-linux-gnu BR_ARTEFACTS="out-workers-box/igneum-worker-cuda out-workers-box/igneum-worker-opencl"; export BR_KIND BR_COMMAND BR_TARGET BR_ARTEFACTS
t0=$(date +%s); set +e; bs_remote_run "$BS_REMOTE_WT" "$BS_WT/proto-cuda workers" "$cmd" 2>&1 | tee "/tmp/workers-remote-$$.log"; rc=${PIPESTATUS[0]}; set -e
grep -E '^workers-remote:' "/tmp/workers-remote-$$.log" | sed 's/^/ /' >&2; rm -f "/tmp/workers-remote-$$.log"
[ "$rc" = 0 ] || bs_die "the worker build failed (rc $rc)"
bs_log "built in $(bs_fmt_secs $(( $(date +%s) - t0 )))"
mkdir -p "$OUT"
for b in igneum-worker-cuda igneum-worker-opencl; do
bs_rsync -p "$BS_HOST:$BS_REMOTE_WT/out-workers-box/$b" "$OUT/$b" || bs_die "no $b on the box"
bs_log "artefact $OUT/$b: $(bs_size "$OUT/$b") bytes, sha256 $(bs_sha256 "$OUT/$b"), $(file -b "$OUT/$b" | cut -c1-50)"
[ "$GLIBC" = native ] || "$HERE/ci/glibc-ceiling-check.sh" "$OUT/$b" "$GLIBC" || bs_die "glibc ceiling gate failed for $b"
done
{ printf 'igneum workers, linux x86_64, built on igneum-build-1 (glibc %s, static libstdc++) on %s from %s (%s); run-time libraries dlopen-ed\n' "$GLIBC" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$BS_SHA" "$BS_BRANCH"; } > "$OUT/version.txt"
bs_wt_unlock