chore(build): make build.sh generic (macOS + Linux) and configurable
Context
The current build.sh is macOS/Homebrew-specific:
mkdir -p build && cd build
cmake .. \
-DLLVM_DIR=$(brew --prefix llvm)/lib/cmake/llvm \
-DClang_DIR=$(brew --prefix llvm)/lib/cmake/clang \
-DCMAKE_BUILD_TYPE=Release \
&& make -j$(sysctl -n hw.logicalcpu)
Issues:
brew --prefix llvm does not exist on Linux (or not necessarily).
sysctl -n hw.logicalcpu is macOS-only.
- No configurability (build type, Ninja generator, build directory, LLVM/Clang overrides, etc.).
Goal
Have a single script that:
- works on macOS and Linux
- auto-detects a sensible parallel build jobs count
- can be configured for:
BUILD_TYPE (Release/Debug/RelWithDebInfo)
BUILD_DIR
GENERATOR (Makefiles/Ninja)
LLVM_DIR and Clang_DIR via environment variables or auto-detection
- keeps a simple UX (
./build.sh, ./build.sh --clean, etc.)
Proposal (spec)
Inputs (CLI or env)
--build-dir <dir> (default: build)
--type <Release|Debug|RelWithDebInfo> (default: Release)
--generator <Ninja|Unix Makefiles> (optional)
--clean (delete the build directory)
--llvm-dir <path> / LLVM_DIR=...
--clang-dir <path> / Clang_DIR=...
--jobs <n> (override)
Expected detections
- OS via
uname -s
jobs:
- macOS:
sysctl -n hw.logicalcpu
- Linux:
nproc (fallback: getconf _NPROCESSORS_ONLN)
- LLVM/Clang CMake dirs:
- macOS: if
brew is present, try brew --prefix llvm
- Linux:
- if
llvm-config is present: use llvm-config --cmakedir (often reliable)
- otherwise fallback to common paths (
/usr/lib/llvm-*/lib/cmake/llvm, etc.) if found
- Otherwise: fail with a clear message explaining how to provide
LLVM_DIR/Clang_DIR.
Tasks
Acceptance criteria
./build.sh works on macOS with LLVM installed via Homebrew.
./build.sh works on Linux with LLVM/Clang installed via packages/llvm-config or via LLVM_DIR/Clang_DIR.
./build.sh --clean cleans and rebuilds.
- The script does not rely on OS-specific commands without fallback.
- Error messages are actionable (e.g., “export LLVM_DIR=… and re-run”).
Notes / usage examples
- macOS (brew):
./build.sh --type Release
- Linux (packages):
- Manual override:
LLVM_DIR=/opt/llvm/lib/cmake/llvm Clang_DIR=/opt/llvm/lib/cmake/clang ./build.sh --generator Ninja
chore(build): make build.sh generic (macOS + Linux) and configurable
Context
The current
build.shis macOS/Homebrew-specific:Issues:
brew --prefix llvmdoes not exist on Linux (or not necessarily).sysctl -n hw.logicalcpuis macOS-only.Goal
Have a single script that:
BUILD_TYPE(Release/Debug/RelWithDebInfo)BUILD_DIRGENERATOR(Makefiles/Ninja)LLVM_DIRandClang_DIRvia environment variables or auto-detection./build.sh,./build.sh --clean, etc.)Proposal (spec)
Inputs (CLI or env)
--build-dir <dir>(default:build)--type <Release|Debug|RelWithDebInfo>(default:Release)--generator <Ninja|Unix Makefiles>(optional)--clean(delete the build directory)--llvm-dir <path>/LLVM_DIR=...--clang-dir <path>/Clang_DIR=...--jobs <n>(override)Expected detections
uname -sjobs:sysctl -n hw.logicalcpunproc(fallback:getconf _NPROCESSORS_ONLN)brewis present, trybrew --prefix llvmllvm-configis present: usellvm-config --cmakedir(often reliable)/usr/lib/llvm-*/lib/cmake/llvm, etc.) if foundLLVM_DIR/Clang_DIR.Tasks
scripts/build.sh(or replacebuild.sh) withset -euo pipefailcase "$1" in ...) +--helpJOBSdetectioncommand -v ninja)cmake --build . -j "$JOBS"instead of callingmakedirectly (more portable)README.md(Build on macOS/Linux section)cmake -S -B)ubuntu-latest+macos-latest(GitHub Actions)Acceptance criteria
./build.shworks on macOS with LLVM installed via Homebrew../build.shworks on Linux with LLVM/Clang installed via packages/llvm-config or viaLLVM_DIR/Clang_DIR../build.sh --cleancleans and rebuilds.Notes / usage examples
./build.sh --type Release./build.sh --type DebugLLVM_DIR=/opt/llvm/lib/cmake/llvm Clang_DIR=/opt/llvm/lib/cmake/clang ./build.sh --generator Ninja