setup.sh 94 lignes · 4785 octets
#!/usr/bin/env bash
# ChipAi tool setup, idempotent, multi-arch (x86_64 and arm64 Linux).
# Runs the same way on the laptop and inside the Linux VM hosted on the Mac Studio.
# Everything installs in user space; Docker is the only system-level prerequisite.
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
XLSYNTH_VERSION="$(tr -d '[:space:]' < "$ROOT/flows/xlsynth_version.txt")"
ARCH="$(uname -m)"
case "$ARCH" in
  x86_64)          PROTOC_ARCH="x86_64" ;;
  aarch64|arm64)   PROTOC_ARCH="aarch_64" ;;
  *) echo "unsupported architecture: $ARCH" >&2; exit 1 ;;
esac

log() { printf '\033[1;34m[setup]\033[0m %s\n' "$*"; }

# 1. Rust toolchain (pinned by rust-toolchain.toml at the repo root).
if ! command -v cargo >/dev/null 2>&1; then
  log "installing rustup"
  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path
  # shellcheck disable=SC1091
  source "$HOME/.cargo/env"
fi
(cd "$ROOT" && rustup show >/dev/null)   # pulls the pinned channel and components
log "rust: $(rustc --version)"

# 2. protoc (required to build xlsynth crates), user-space install.
mkdir -p "$HOME/.local/bin" "$HOME/.local/protoc"
if ! command -v protoc >/dev/null 2>&1 && [ ! -x "$HOME/.local/bin/protoc" ]; then
  PROTOC_VERSION="$(curl -fsSL https://api.github.com/repos/protocolbuffers/protobuf/releases/latest \
    | grep '"tag_name"' | sed -E 's/.*"v([^"]+)".*/\1/')"
  log "installing protoc $PROTOC_VERSION"
  curl -fsSL -o /tmp/protoc.zip \
    "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-${PROTOC_ARCH}.zip"
  unzip -qo /tmp/protoc.zip -d "$HOME/.local/protoc"
  ln -sf "$HOME/.local/protoc/bin/protoc" "$HOME/.local/bin/protoc"
fi
export PROTOC="${PROTOC:-$(command -v protoc || echo "$HOME/.local/bin/protoc")}"
log "protoc: $("$PROTOC" --version)"

# 3. XLS release binaries, native library and DSLX stdlib (flows/xls_release.txt).
#    The release ships Linux x86_64 (ubuntu2004) and macOS arm64 only: on arm64
#    Linux (VM on Apple Silicon) the x86_64 binaries run through Rosetta.
XLS_RELEASE="$(tr -d '[:space:]' < "$ROOT/flows/xls_release.txt")"
XLS_HOME="$HOME/.local/xlsynth/$XLS_RELEASE"
XLS_URL="https://github.com/xlsynth/xlsynth/releases/download/$XLS_RELEASE"
if [ ! -x "$XLS_HOME/bin/codegen_main" ]; then
  log "installing XLS $XLS_RELEASE into $XLS_HOME"
  mkdir -p "$XLS_HOME/bin" "$XLS_HOME/lib" "$XLS_HOME/stdlib"
  for t in dslx_interpreter_main ir_converter_main opt_main codegen_main \
           check_ir_equivalence_main delay_info_main typecheck_main \
           prove_quickcheck_main dslx_fmt; do
    curl -fsSL -o "$XLS_HOME/bin/$t" "$XLS_URL/$t-ubuntu2004"; chmod +x "$XLS_HOME/bin/$t"
  done
  curl -fsSL "$XLS_URL/libxls-ubuntu2004.so.gz" | gunzip > "$XLS_HOME/lib/libxls-$XLS_RELEASE-ubuntu2004.so"
  curl -fsSL "$XLS_URL/dslx_stdlib.tar.gz" | tar -xz -C "$XLS_HOME/stdlib"
fi
if [ "$ARCH" != "x86_64" ] && ! "$XLS_HOME/bin/typecheck_main" --help >/dev/null 2>&1; then
  log "XLS x86_64 binaries do not run here: enable Rosetta (Lima: rosetta.enabled) or qemu-user binfmt"
fi
log "xls: $XLS_HOME"

# 4. xlsynth-driver (Rust front end over the same library). Needs the nightly
#    channel to build (xlsynth-pir uses #![feature]); the project stays on stable.
if ! LD_LIBRARY_PATH="$XLS_HOME/lib" xlsynth-driver version 2>/dev/null | grep -q "$XLSYNTH_VERSION"; then
  log "installing xlsynth-driver $XLSYNTH_VERSION (nightly build)"
  rustup toolchain install nightly --profile minimal
  cargo +nightly install xlsynth-driver --version "$XLSYNTH_VERSION" --locked
fi
sed "s#__XLS_HOME__#$XLS_HOME#g; s#__ROOT__#$ROOT#g" \
  "$ROOT/flows/xlsynth-toolchain.toml" > "$ROOT/flows/xlsynth-toolchain.local.toml"
log "xlsynth-driver: $(LD_LIBRARY_PATH="$XLS_HOME/lib" xlsynth-driver version 2>&1 | head -1)"

# 5. netlistsvg (gate-level schematics from Yosys JSON), local npm prefix.
if ! command -v netlistsvg >/dev/null 2>&1; then
  log "installing netlistsvg"
  npm install -g --prefix "$HOME/.local" netlistsvg
fi
log "netlistsvg: $(netlistsvg --help 2>&1 | head -1)"

# 6. Docker images: open-source EDA (Yosys, Verilator, OpenROAD) and ORFS (ASAP7).
if command -v docker >/dev/null 2>&1; then
  log "pulling hpretl/iic-osic-tools (native $ARCH)"
  docker pull -q hpretl/iic-osic-tools:latest
  # ORFS images are x86_64 only: on arm64 they run through Rosetta (VM) or qemu.
  log "pulling openroad/orfs (x86_64)"
  docker pull -q --platform linux/amd64 openroad/orfs:latest || \
    log "ORFS image pull failed; ASAP7 synthesis will need the laptop"
else
  log "docker not found: skipping EDA images (simulation and synthesis need them)"
fi

log "done. Run: cargo test && flows/xls.sh driver version && flows/eda.sh yosys -V"