Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

Use cc (Apple Clang) on macOS, gcc on Linux — unified CI/local parity

Martin Vogel8f225a37ddb7
diff --git a/.github/workflows/dry-run.yml b/.github/workflows/dry-run.yml
index 4491a0250..56a333aa0 100644
--- a/.github/workflows/dry-run.yml
+++ b/.github/workflows/dry-run.yml
@@ -44,6 +44,8 @@ jobs:
run: scripts/lint.sh CLANG_FORMAT=clang-format-20
# ── Step 2: Unit tests (ASan + UBSan) ───────────────────────
+ # macOS: use cc (Apple Clang) — GCC on macOS doesn't ship ASan runtime
+ # Linux: use system gcc — full ASan/UBSan support
test:
needs: [lint]
strategy:
@@ -60,12 +62,12 @@ jobs:
cxx: g++
- os: macos-14
arch: arm64
- cc: gcc-14
- cxx: g++-14
+ cc: cc
+ cxx: c++
- os: macos-15-intel
arch: amd64
- cc: gcc-14
- cxx: g++-14
+ cc: cc
+ cxx: c++
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
@@ -96,13 +98,13 @@ jobs:
- os: macos-14
goos: darwin
goarch: arm64
- cc: gcc-14
- cxx: g++-14
+ cc: cc
+ cxx: c++
- os: macos-15-intel
goos: darwin
goarch: amd64
- cc: gcc-14
- cxx: g++-14
+ cc: cc
+ cxx: c++
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 6e49d2c8b..45ab60825 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -58,6 +58,8 @@ jobs:
run: scripts/lint.sh CLANG_FORMAT=clang-format-20
# ── Step 2: Unit tests (ASan + UBSan) ───────────────────────
+ # macOS: use cc (Apple Clang) — GCC on macOS doesn't ship ASan runtime
+ # Linux: use system gcc — full ASan/UBSan support
test:
needs: [lint]
strategy:
@@ -74,12 +76,12 @@ jobs:
cxx: g++
- os: macos-14
arch: arm64
- cc: gcc-14
- cxx: g++-14
+ cc: cc
+ cxx: c++
- os: macos-15-intel
arch: amd64
- cc: gcc-14
- cxx: g++-14
+ cc: cc
+ cxx: c++
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
@@ -110,13 +112,13 @@ jobs:
- os: macos-14
goos: darwin
goarch: arm64
- cc: gcc-14
- cxx: g++-14
+ cc: cc
+ cxx: c++
- os: macos-15-intel
goos: darwin
goarch: amd64
- cc: gcc-14
- cxx: g++-14
+ cc: cc
+ cxx: c++
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
diff --git a/Makefile.cbm b/Makefile.cbm
index b4752f4ee..ab136cf65 100644
--- a/Makefile.cbm
+++ b/Makefile.cbm
@@ -7,11 +7,10 @@
# make -f Makefile.cbm cbm # Production binary
# make -f Makefile.cbm clean-c # Remove build artifacts
-# Pin GCC for consistent behavior across macOS, Linux, and CI.
-# macOS: brew install gcc → gcc-14/g++-14. Linux: system gcc/g++.
-# Override with: make CC=gcc-14 CXX=g++-14
-CC ?= gcc-14
-CXX ?= g++-14
+# Compiler selection — override via: make CC=gcc CXX=g++
+# macOS: cc (Apple Clang) — universal binary with ASan support
+# Linux: gcc/g++ — system default with full sanitizer support
+# CI scripts pass CC/CXX explicitly; don't rely on defaults here
# ── Common flags ─────────────────────────────────────────────────
diff --git a/scripts/build.sh b/scripts/build.sh
index e949eec47..4c7448552 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -2,9 +2,11 @@
# build.sh — Clean build of production binary (standard or with UI).
#
# Usage:
-# scripts/build.sh # Standard binary
-# scripts/build.sh --with-ui # Binary with embedded UI
-# scripts/build.sh --version v0.8.0 # With version stamp
+# scripts/build.sh # Standard binary
+# scripts/build.sh --with-ui # Binary with embedded UI
+# scripts/build.sh --version v0.8.0 # With version stamp
+# scripts/build.sh --arch x86_64 # Force x86_64 build
+# scripts/build.sh CC=gcc-14 CXX=g++-14 # Override compiler
#
# This script is the SINGLE source of truth for building release binaries.
# Used identically in local development and CI workflows.
@@ -14,34 +16,59 @@ set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
-# Detect parallelism
-NPROC=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
+# Pre-parse --arch flag before sourcing env.sh
+for arg in "$@"; do
+ case "$arg" in
+ --arch=*) export CBM_ARCH="${arg#--arch=}" ;;
+ esac
+done
+prev_arg=""
+for arg in "$@"; do
+ if [[ "${prev_arg:-}" == "--arch" ]]; then
+ export CBM_ARCH="$arg"
+ fi
+ prev_arg="$arg"
+done
-# Parse arguments
+# shellcheck source=env.sh
+source "$ROOT/scripts/env.sh"
+
+# Parse remaining arguments
WITH_UI=false
VERSION=""
EXTRA_MAKE_ARGS=()
-while [[ $# -gt 0 ]]; do
- case "$1" in
+prev_arg=""
+for arg in "$@"; do
+ # Skip --arch and its value (already handled)
+ if [[ "${prev_arg:-}" == "--arch" ]]; then
+ prev_arg="$arg"
+ continue
+ fi
+ case "$arg" in
--with-ui)
WITH_UI=true
- shift
;;
--version)
- VERSION="$2"
- shift 2
+ prev_arg="$arg"
+ continue
;;
+ --arch|--arch=*)
+ ;; # already handled
CC=*|CXX=*)
- export "${1?}"
- EXTRA_MAKE_ARGS+=("$1")
- shift
+ export "${arg}"
+ EXTRA_MAKE_ARGS+=("$arg")
;;
*)
- EXTRA_MAKE_ARGS+=("$1")
- shift
+ # Check if this is the value for --version
+ if [[ "${prev_arg:-}" == "--version" ]]; then
+ VERSION="$arg"
+ else
+ EXTRA_MAKE_ARGS+=("$arg")
+ fi
;;
esac
+ prev_arg="$arg"
done
# Version flag
@@ -51,17 +78,21 @@ if [[ -n "$VERSION" ]]; then
CFLAGS_EXTRA="-DCBM_VERSION=\"\\\"$CLEAN_VERSION\\\"\""
fi
-echo "=== build.sh: compiler=${CC:-default} ui=$WITH_UI version=${VERSION:-dev} cores=$NPROC ==="
+print_env "build.sh"
+echo " ui=$WITH_UI version=${VERSION:-dev}"
+
+# Verify compiler supports target arch
+verify_compiler "${CC:-gcc-14}"
# Step 1: Clean C build artifacts only (not node_modules — npm ci handles that)
rm -rf "$ROOT/build/c"
-# Step 2: Build
+# Step 2: Build (with arch prefix on macOS)
if $WITH_UI; then
- make -j"$NPROC" -f Makefile.cbm cbm-with-ui \
+ $ARCH_PREFIX make -j"$NPROC" -f Makefile.cbm cbm-with-ui \
CFLAGS_EXTRA="$CFLAGS_EXTRA" "${EXTRA_MAKE_ARGS[@]+"${EXTRA_MAKE_ARGS[@]}"}"
else
- make -j"$NPROC" -f Makefile.cbm cbm \
+ $ARCH_PREFIX make -j"$NPROC" -f Makefile.cbm cbm \
CFLAGS_EXTRA="$CFLAGS_EXTRA" "${EXTRA_MAKE_ARGS[@]+"${EXTRA_MAKE_ARGS[@]}"}"
fi
diff --git a/scripts/env.sh b/scripts/env.sh
new file mode 100755
index 000000000..74b968a3e
--- /dev/null
+++ b/scripts/env.sh
@@ -0,0 +1,81 @@
+#!/bin/bash
+# env.sh — Shared environment detection for all build scripts.
+#
+# Sourced by test.sh, build.sh, lint.sh. Not meant to run standalone.
+#
+# Exports:
+# ARCH — target architecture (arm64 / x86_64)
+# ARCH_PREFIX — "arch -arm64" on macOS, empty on Linux/Windows
+# NPROC — number of CPU cores
+# OS — darwin / linux / windows
+
+set -euo pipefail
+
+# ── Detect OS ──────────────────────────────────────────────────
+OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
+case "$OS" in
+ darwin) OS="darwin" ;;
+ linux) OS="linux" ;;
+ mingw*|msys*|cygwin*) OS="windows" ;;
+ *) OS="unknown" ;;
+esac
+
+# ── Detect / override architecture ─────────────────────────────
+# Default: native HARDWARE architecture (not Rosetta-translated).
+# On macOS under Rosetta, uname -m returns x86_64 even on Apple Silicon.
+# We use sysctl to detect the true hardware.
+HW_ARCH="$(uname -m)"
+if [[ "$(uname -s)" == "Darwin" ]] && sysctl -n hw.optional.arm64 2>/dev/null | grep -q 1; then
+ HW_ARCH="arm64"
+fi
+case "$HW_ARCH" in
+ aarch64|arm64) HW_ARCH="arm64" ;;
+ x86_64|amd64) HW_ARCH="x86_64" ;;
+esac
+
+# CBM_ARCH env var or --arch flag override (parsed by calling script)
+ARCH="${CBM_ARCH:-$HW_ARCH}"
+
+# ── Build arch prefix (macOS only) ─────────────────────────────
+ARCH_PREFIX=""
+if [[ "$OS" == "darwin" ]]; then
+ ARCH_PREFIX="arch -${ARCH}"
+fi
+
+# ── Detect parallelism ─────────────────────────────────────────
+NPROC=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
+
+# ── Verify compiler is available for target arch ───────────────
+verify_compiler() {
+ local compiler="$1"
+ local bin
+ bin="$(command -v "$compiler" 2>/dev/null || true)"
+
+ if [[ -z "$bin" ]]; then
+ echo "ERROR: compiler '$compiler' not found in PATH" >&2
+ exit 1
+ fi
+
+ if [[ "$OS" == "darwin" ]]; then
+ local file_info
+ file_info="$(file "$bin" 2>/dev/null)"
+
+ if [[ "$ARCH" == "arm64" ]] && ! echo "$file_info" | grep -qE "arm64|universal"; then
+ echo "WARNING: $compiler ($bin) is x86_64 only — cannot build native arm64" >&2
+ echo " Install arm64 GCC: arch -arm64 /opt/homebrew/bin/brew install gcc" >&2
+ echo " Or override: scripts/test.sh --arch x86_64" >&2
+ exit 1
+ fi
+
+ if [[ "$ARCH" == "x86_64" ]] && ! echo "$file_info" | grep -qE "x86_64|universal"; then
+ echo "WARNING: $compiler ($bin) is arm64 only — cannot build x86_64" >&2
+ exit 1
+ fi
+ fi
+}
+
+# ── Print environment summary ──────────────────────────────────
+print_env() {
+ local context="$1"
+ echo "=== $context: os=$OS arch=$ARCH cores=$NPROC cc=${CC:-default} cxx=${CXX:-default} ==="
+}
diff --git a/scripts/lint.sh b/scripts/lint.sh
index 4a123d29f..a6c7aba75 100755
--- a/scripts/lint.sh
+++ b/scripts/lint.sh
@@ -13,13 +13,16 @@ set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
-# Forward overrides from args (e.g. CLANG_FORMAT=clang-format-20)
+# shellcheck source=env.sh
+source "$ROOT/scripts/env.sh"
+
+# Forward overrides from args
MAKE_ARGS=()
for arg in "$@"; do
MAKE_ARGS+=("$arg")
done
-echo "=== lint.sh: running clang-format + cppcheck ==="
+print_env "lint.sh"
# Run format and cppcheck in parallel
make -j2 -f Makefile.cbm lint-ci "${MAKE_ARGS[@]+"${MAKE_ARGS[@]}"}"
diff --git a/scripts/test.sh b/scripts/test.sh
index c5e9ecb9b..7cb4a070f 100755
--- a/scripts/test.sh
+++ b/scripts/test.sh
@@ -1,35 +1,61 @@
#!/bin/bash
# test.sh — Clean build + run all C tests with ASan + UBSan.
#
-# Usage: scripts/test.sh [CC=gcc-14] [CXX=g++-14]
+# Usage:
+# scripts/test.sh # Auto-detect everything
+# scripts/test.sh --arch x86_64 # Force x86_64 build
+# scripts/test.sh CC=gcc-14 CXX=g++-14 # Override compiler
#
# This script is the SINGLE source of truth for running tests.
# Used identically in local development and CI workflows.
-#
-# Steps:
-# 1. Clean all build artifacts (forced fresh compile)
-# 2. Build test-runner with sanitizers
-# 3. Run all test suites
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
-# Detect parallelism
-NPROC=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
+# Parse --arch flag before sourcing env.sh
+for arg in "$@"; do
+ case "$arg" in
+ --arch) :;; # next arg is the value, handled below
+ arm64|x86_64)
+ # Check if previous arg was --arch
+ if [[ "${prev_arg:-}" == "--arch" ]]; then
+ export CBM_ARCH="$arg"
+ fi
+ ;;
+ esac
+ prev_arg="$arg"
+done
+
+# Also support --arch=value
+for arg in "$@"; do
+ case "$arg" in
+ --arch=*) export CBM_ARCH="${arg#--arch=}" ;;
+ esac
+done
-# Forward CC/CXX from env or args (e.g. scripts/test.sh CC=gcc-14)
+# shellcheck source=env.sh
+source "$ROOT/scripts/env.sh"
+
+# Forward CC/CXX from args
for arg in "$@"; do
- export "${arg?}"
+ case "$arg" in
+ CC=*|CXX=*) export "${arg}" ;;
+ --arch|--arch=*) ;; # already handled
+ arm64|x86_64) ;; # already handled
+ esac
done
-echo "=== test.sh: compiler=${CC:-default} cores=$NPROC ==="
+print_env "test.sh"
+
+# Verify compiler supports target arch
+verify_compiler "${CC:-gcc-14}"
# Step 1: Clean
scripts/clean.sh
-# Step 2 + 3: Build and run tests
-make -j"$NPROC" -f Makefile.cbm test
+# Step 2 + 3: Build and run tests (with arch prefix on macOS)
+$ARCH_PREFIX make -j"$NPROC" -f Makefile.cbm test
echo "=== All tests passed ==="