Skip to content

Commit 041ed51

Browse files
avi-starkwareclaude
andcommitted
scripts: add install_compiler_binaries.sh
New script to install Sierra compiler binaries (starknet-sierra-compile, starknet-native-compile). Reads versions from .txt files, handles LLVM env vars for native compile, and skips gracefully when LLVM 19 is missing. Includes compiler_versions.sh helper that reads version .txt files. Not yet called from install_cargo_tools.sh — wired up in a follow-up. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1c9cbc1 commit 041ed51

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

scripts/compiler_versions.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/env bash
2+
# Reads compiler binary versions from version files (the single source of truth).
3+
# Source this script to get $SIERRA_COMPILE_VERSION and $NATIVE_COMPILE_VERSION.
4+
5+
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)")"
6+
7+
SIERRA_COMPILE_VERSION=$(cat "$REPO_ROOT/crates/apollo_infra_utils/src/cairo_compiler_version.txt")
8+
NATIVE_COMPILE_VERSION=$(cat "$REPO_ROOT/crates/apollo_compile_to_native/src/native_compiler_version.txt")
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/env bash
2+
# Installs Sierra compiler binaries (starknet-sierra-compile, starknet-native-compile).
3+
# Versions are read from plain text files that are the single source of truth for both
4+
# Rust code and this script.
5+
#
6+
# Called from install_cargo_tools.sh. Can also be run standalone after LLVM 19 is installed.
7+
8+
set -e
9+
10+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
11+
12+
# Source version files and shared utilities.
13+
source "${SCRIPT_DIR}/compiler_versions.sh"
14+
if [ -f "${SCRIPT_DIR}/apt_utils.sh" ]; then
15+
source "${SCRIPT_DIR}/apt_utils.sh"
16+
elif [ -f "./apt_utils.sh" ]; then
17+
source "./apt_utils.sh"
18+
fi
19+
20+
# Install a compiler binary only if needed (not installed or different version).
21+
function install_compiler_if_needed() {
22+
local binary_name=$1
23+
local version=$2
24+
local current
25+
current=$($binary_name --version 2>/dev/null | grep -oP '\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?' | head -1) || true
26+
if [ "$current" = "$version" ]; then
27+
log_step "install_build_tools" "$binary_name $version already installed, skipping"
28+
else
29+
if [ -n "$current" ]; then
30+
log_step "install_build_tools" "Replacing $binary_name $current with $version..."
31+
else
32+
log_step "install_build_tools" "Installing $binary_name $version..."
33+
fi
34+
cargo install "$binary_name" --version "$version" --force
35+
log_step "install_build_tools" "$binary_name installed successfully"
36+
fi
37+
}
38+
39+
# LLVM/MLIR env vars are normally set by .cargo/config.toml, but cargo install runs
40+
# outside the workspace so they must be set explicitly.
41+
if [ -f "$REPO_ROOT/.cargo/config.toml" ]; then
42+
eval "$(grep -E '(LLVM_SYS|MLIR_SYS|TABLEGEN)' "$REPO_ROOT/.cargo/config.toml" | sed 's/ = /=/' | tr -d '"')"
43+
export LLVM_SYS_191_PREFIX MLIR_SYS_190_PREFIX TABLEGEN_190_PREFIX
44+
fi
45+
46+
# RUSTC_WRAPPER="" avoids sccache circular dependency during installation.
47+
RUSTC_WRAPPER="" install_compiler_if_needed "starknet-sierra-compile" "$SIERRA_COMPILE_VERSION"
48+
49+
# starknet-native-compile requires LLVM 19. If LLVM is not installed, print instructions
50+
# instead of failing with a cryptic tblgen build error.
51+
if command -v llvm-config-19 &>/dev/null; then
52+
RUSTC_WRAPPER="" install_compiler_if_needed "starknet-native-compile" "$NATIVE_COMPILE_VERSION"
53+
else
54+
log_step "install_build_tools" "Skipping starknet-native-compile (LLVM 19 not found)."
55+
log_step "install_build_tools" "To install it: run 'scripts/dependencies.sh' first, then re-run this script."
56+
fi

0 commit comments

Comments
 (0)