Skip to content

Commit 5340959

Browse files
avi-starkwareclaude
andcommitted
apollo_compilation_utils: add verify_compiler_binary
New function that checks a compiler binary's version at runtime and panics with installation instructions if missing or wrong version. Added alongside the existing install_compiler_binary — no callers yet. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0b06643 commit 5340959

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

crates/apollo_compilation_utils/src/build_utils.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::path::Path;
12
use std::process::Command;
23

34
use tempfile::TempDir;
@@ -64,3 +65,32 @@ pub fn install_compiler_binary(
6465

6566
println!("Successfully set executable file: {:?}", binary_path.display());
6667
}
68+
69+
/// Verifies that a compiler binary is installed and has the required version.
70+
/// Panics with installation instructions if the binary is missing or has the wrong version.
71+
pub fn verify_compiler_binary(binary_path: &Path, required_version: &str) {
72+
let binary_name = binary_path.display();
73+
let install_instructions =
74+
format!("Run 'scripts/install_compiler_binaries.sh' to install the correct version.");
75+
match Command::new(binary_path).arg("--version").output() {
76+
Ok(output) => {
77+
let version_output = String::from_utf8_lossy(&output.stdout);
78+
// Extract the version token (e.g. "2.17.0-rc.4") from output like
79+
// "starknet-sierra-compile 2.17.0-rc.4". Using exact token match avoids
80+
// false positives (e.g. "1.0.1" matching "1.0.10").
81+
let installed_version = version_output
82+
.split_whitespace()
83+
.find(|token| token.contains('.'))
84+
.unwrap_or("");
85+
if installed_version != required_version {
86+
panic!(
87+
"{binary_name} version {required_version} is required, but found: \
88+
{installed_version}. {install_instructions}"
89+
);
90+
}
91+
}
92+
Err(_) => {
93+
panic!("{binary_name} not found. {install_instructions}");
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)