|
| 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