Skip to content

chore(build): make build.sh generic (macOS + Linux) and configurable #35

@SizzleUnrlsd

Description

@SizzleUnrlsd

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

  • Create scripts/build.sh (or replace build.sh) with set -euo pipefail
  • Add minimal argument parsing (case "$1" in ...) + --help
  • Implement cross-platform JOBS detection
  • Implement LLVM/Clang auto-detection (brew + llvm-config) + fallbacks + clean errors
  • Support Ninja if installed (command -v ninja)
  • Use cmake --build . -j "$JOBS" instead of calling make directly (more portable)
  • Document usage in README.md (Build on macOS/Linux section)
  • Add a quick CI check that validates:
    • the script can configure (at least cmake -S -B)
    • on ubuntu-latest + macos-latest (GitHub Actions)

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):
    • ./build.sh --type Debug
  • Manual override:
    • LLVM_DIR=/opt/llvm/lib/cmake/llvm Clang_DIR=/opt/llvm/lib/cmake/clang ./build.sh --generator Ninja

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationenhancementNew feature or request

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions