|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 5 | +env_file="${repo_root}/.bolt-dev-env" |
| 6 | + |
| 7 | +usage() { |
| 8 | + cat <<'USAGE' |
| 9 | +Usage: scripts/setup-bolt-dev.sh |
| 10 | +
|
| 11 | +Installs/configures the local dependencies needed by Bolt MLIR/codegen checks |
| 12 | +on macOS: |
| 13 | +
|
| 14 | + - Homebrew llvm |
| 15 | + - rustup components: rust-src, rustfmt, clippy |
| 16 | + - cargo-nextest |
| 17 | + - jolt CLI installed from this checkout |
| 18 | + - .bolt-dev-env with MLIR_SYS_220_PREFIX, PATH, SDKROOT, and bindgen flags |
| 19 | +
|
| 20 | +After it finishes, run: |
| 21 | +
|
| 22 | + source .bolt-dev-env |
| 23 | +USAGE |
| 24 | +} |
| 25 | + |
| 26 | +if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then |
| 27 | + usage |
| 28 | + exit 0 |
| 29 | +fi |
| 30 | + |
| 31 | +if [[ "$(uname -s)" != "Darwin" ]]; then |
| 32 | + cat >&2 <<'EOF' |
| 33 | +scripts/setup-bolt-dev.sh currently supports macOS/Homebrew. |
| 34 | +
|
| 35 | +Bolt's MLIR path needs LLVM/MLIR 22 visible through llvm-config. On non-macOS |
| 36 | +hosts, install an LLVM 22 toolchain and export: |
| 37 | +
|
| 38 | + MLIR_SYS_220_PREFIX=<llvm-prefix> |
| 39 | + PATH=<llvm-prefix>/bin:$PATH |
| 40 | +
|
| 41 | +EOF |
| 42 | + exit 1 |
| 43 | +fi |
| 44 | + |
| 45 | +if ! command -v brew >/dev/null 2>&1; then |
| 46 | + cat >&2 <<'EOF' |
| 47 | +Homebrew is required to install the LLVM toolchain for this helper. |
| 48 | +Install Homebrew first: https://brew.sh |
| 49 | +EOF |
| 50 | + exit 1 |
| 51 | +fi |
| 52 | + |
| 53 | +if ! command -v xcrun >/dev/null 2>&1; then |
| 54 | + cat >&2 <<'EOF' |
| 55 | +xcrun is missing. Install the Xcode command line tools first: |
| 56 | +
|
| 57 | + xcode-select --install |
| 58 | +EOF |
| 59 | + exit 1 |
| 60 | +fi |
| 61 | + |
| 62 | +if ! brew list llvm >/dev/null 2>&1; then |
| 63 | + brew install llvm |
| 64 | +fi |
| 65 | + |
| 66 | +if command -v rustup >/dev/null 2>&1; then |
| 67 | + rustup component add rust-src rustfmt clippy |
| 68 | +else |
| 69 | + cat >&2 <<'EOF' |
| 70 | +rustup is not installed. Install Rust from https://rustup.rs, then rerun this |
| 71 | +script so it can add rust-src, rustfmt, and clippy. |
| 72 | +EOF |
| 73 | + exit 1 |
| 74 | +fi |
| 75 | + |
| 76 | +if ! cargo nextest --version >/dev/null 2>&1; then |
| 77 | + cargo install cargo-nextest --locked |
| 78 | +fi |
| 79 | + |
| 80 | +cargo install --path "${repo_root}" --locked --force |
| 81 | + |
| 82 | +llvm_prefix="$(brew --prefix llvm)" |
| 83 | +sdkroot="$(xcrun --show-sdk-path)" |
| 84 | + |
| 85 | +cat >"${env_file}" <<EOF |
| 86 | +# Generated by scripts/setup-bolt-dev.sh. Source this before Bolt MLIR checks. |
| 87 | +export MLIR_SYS_220_PREFIX="${llvm_prefix}" |
| 88 | +export PATH="${llvm_prefix}/bin:\${PATH}" |
| 89 | +export SDKROOT="${sdkroot}" |
| 90 | +export BINDGEN_EXTRA_CLANG_ARGS="-isysroot${sdkroot}" |
| 91 | +EOF |
| 92 | + |
| 93 | +"${llvm_prefix}/bin/llvm-config" --version >/dev/null |
| 94 | + |
| 95 | +cat <<EOF |
| 96 | +Wrote ${env_file} |
| 97 | +
|
| 98 | +Run: |
| 99 | + source .bolt-dev-env |
| 100 | +
|
| 101 | +Then Bolt checks can find llvm-config and MLIR_SYS_220_PREFIX. |
| 102 | +EOF |
0 commit comments