Skip to content

Commit c0feab1

Browse files
starknet_os_runner: add install script for stwo_run_and_prove (#11437)
Add a shell script to download and install the stwo_run_and_prove binary from GitHub releases to target/tools/.
1 parent 8900446 commit c0feab1

File tree

1 file changed

+193
-0
lines changed

1 file changed

+193
-0
lines changed
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
#!/bin/bash
2+
#
3+
# Installs the stwo_run_and_prove binary from the starkware-libs/proving-utils repo.
4+
#
5+
# This script:
6+
# 1. Clones proving-utils to a build cache directory under target/third_party/
7+
# 2. Checks out the pinned revision
8+
# 3. Builds stwo_run_and_prove in release mode
9+
# 4. Copies the binary to target/tools/
10+
# 5. Prints instructions for adding to PATH or configuring STWO_RUN_AND_PROVE_PATH
11+
#
12+
# Usage:
13+
# ./scripts/install_stwo_run_and_prove.sh
14+
#
15+
# Environment Variables:
16+
# PROVING_UTILS_REV - Override the default pinned revision (default: b788938fde9e)
17+
# SKIP_BUILD_IF_EXISTS - If set to "1", skip building if binary already exists
18+
#
19+
# The binary will be installed to: <repo_root>/target/tools/stwo_run_and_prove
20+
21+
# If any command fails, exit immediately.
22+
set -euo pipefail
23+
24+
# Configuration.
25+
PROVING_UTILS_REPO="https://github.com/starkware-libs/proving-utils"
26+
PROVING_UTILS_REV="${PROVING_UTILS_REV:-b788938fde9e}"
27+
PACKAGE_NAME="stwo_run_and_prove"
28+
BINARY_NAME="stwo_run_and_prove"
29+
30+
# Determine repository root.
31+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
32+
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
33+
34+
# Build and install directories.
35+
THIRD_PARTY_DIR="${REPO_ROOT}/target/third_party"
36+
BUILD_DIR="${THIRD_PARTY_DIR}/proving-utils-${PROVING_UTILS_REV}"
37+
TOOLS_DIR="${REPO_ROOT}/target/tools"
38+
BINARY_PATH="${TOOLS_DIR}/${BINARY_NAME}"
39+
40+
# Colors for output.
41+
RED='\033[0;31m'
42+
GREEN='\033[0;32m'
43+
YELLOW='\033[1;33m'
44+
BLUE='\033[0;34m'
45+
NC='\033[0m' # No Color
46+
47+
info() {
48+
echo -e "${BLUE}[INFO]${NC} $1"
49+
}
50+
51+
success() {
52+
echo -e "${GREEN}[SUCCESS]${NC} $1"
53+
}
54+
55+
warn() {
56+
echo -e "${YELLOW}[WARN]${NC} $1"
57+
}
58+
59+
error() {
60+
echo -e "${RED}[ERROR]${NC} $1" >&2
61+
}
62+
63+
# Check for required tools.
64+
check_requirements() {
65+
local missing=()
66+
67+
if ! command -v git &> /dev/null; then
68+
missing+=("git")
69+
fi
70+
71+
if ! command -v cargo &> /dev/null; then
72+
missing+=("cargo (Rust toolchain)")
73+
fi
74+
75+
if ! command -v rustup &> /dev/null; then
76+
missing+=("rustup")
77+
fi
78+
79+
if [ ${#missing[@]} -ne 0 ]; then
80+
error "Missing required tools: ${missing[*]}"
81+
error "Please install them and try again."
82+
exit 1
83+
fi
84+
}
85+
86+
# Clone or update the proving-utils repository (only if needed).
87+
clone_or_update_repo() {
88+
mkdir -p "${THIRD_PARTY_DIR}"
89+
90+
if [ -d "${BUILD_DIR}/.git" ]; then
91+
info "Proving-utils already cloned at ${BUILD_DIR}"
92+
cd "${BUILD_DIR}"
93+
94+
# Check if we're at the right revision.
95+
local current_rev
96+
current_rev=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
97+
98+
if [[ "${current_rev}" == "${PROVING_UTILS_REV}"* ]]; then
99+
info "Already at revision ${PROVING_UTILS_REV}"
100+
return 0
101+
fi
102+
103+
info "Fetching and checking out revision ${PROVING_UTILS_REV}..."
104+
git fetch origin
105+
git checkout "${PROVING_UTILS_REV}"
106+
else
107+
info "Cloning proving-utils to ${BUILD_DIR}..."
108+
rm -rf "${BUILD_DIR}"
109+
git clone "${PROVING_UTILS_REPO}" "${BUILD_DIR}"
110+
cd "${BUILD_DIR}"
111+
git checkout "${PROVING_UTILS_REV}"
112+
fi
113+
}
114+
115+
# Build the binary
116+
build_binary() {
117+
cd "${BUILD_DIR}"
118+
119+
# The proving-utils repo has its own rust-toolchain.toml, which rustup will use automatically.
120+
# Log the toolchain being used.
121+
local toolchain
122+
toolchain=$(cat rust-toolchain.toml 2>/dev/null | grep 'channel' | sed 's/.*= *"\(.*\)"/\1/' || echo "default")
123+
info "Building with toolchain: ${toolchain}"
124+
info "This may take several minutes on first build..."
125+
126+
cargo build --release -p "${PACKAGE_NAME}" --bin "${BINARY_NAME}"
127+
128+
if [ ! -f "target/release/${BINARY_NAME}" ]; then
129+
error "Build succeeded but binary not found at target/release/${BINARY_NAME}"
130+
exit 1
131+
fi
132+
133+
success "Build completed successfully"
134+
}
135+
136+
# Install the binary.
137+
install_binary() {
138+
mkdir -p "${TOOLS_DIR}"
139+
140+
info "Installing ${BINARY_NAME} to ${BINARY_PATH}..."
141+
cp "${BUILD_DIR}/target/release/${BINARY_NAME}" "${BINARY_PATH}"
142+
chmod +x "${BINARY_PATH}"
143+
144+
success "Binary installed to ${BINARY_PATH}"
145+
}
146+
147+
# Print usage instructions.
148+
print_instructions() {
149+
echo ""
150+
echo "=============================================="
151+
success "${BINARY_NAME} has been installed successfully!"
152+
echo "=============================================="
153+
echo ""
154+
echo "Binary location: ${BINARY_PATH}"
155+
echo ""
156+
echo "The starknet_os_runner crate will automatically find this binary."
157+
echo "No PATH modification is required for development."
158+
echo ""
159+
echo "Optional: To use from command line directly, add to PATH:"
160+
echo " export PATH=\"${TOOLS_DIR}:\$PATH\""
161+
echo ""
162+
echo "Verify installation:"
163+
echo " ${BINARY_PATH} --help"
164+
echo ""
165+
}
166+
167+
# Check if binary already exists and skip if requested.
168+
check_existing() {
169+
if [ -f "${BINARY_PATH}" ]; then
170+
if [ "${SKIP_BUILD_IF_EXISTS:-0}" = "1" ]; then
171+
info "Binary already exists at ${BINARY_PATH}, skipping build (SKIP_BUILD_IF_EXISTS=1)"
172+
print_instructions
173+
exit 0
174+
fi
175+
176+
warn "Binary already exists at ${BINARY_PATH}, will rebuild"
177+
fi
178+
}
179+
180+
main() {
181+
echo ""
182+
info "Installing ${BINARY_NAME} from proving-utils @ ${PROVING_UTILS_REV}"
183+
echo ""
184+
185+
check_requirements
186+
check_existing
187+
clone_or_update_repo
188+
build_binary
189+
install_binary
190+
print_instructions
191+
}
192+
193+
main "$@"

0 commit comments

Comments
 (0)