Skip to content

Commit fce8efa

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 d34d1ba commit fce8efa

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

crates/apollo_compilation_utils/src/build_utils.rs

Lines changed: 28 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,30 @@ 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+
"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 =
82+
version_output.split_whitespace().find(|token| token.contains('.')).unwrap_or("");
83+
if installed_version != required_version {
84+
panic!(
85+
"{binary_name} version {required_version} is required, but found: \
86+
{installed_version}. {install_instructions}"
87+
);
88+
}
89+
}
90+
Err(_) => {
91+
panic!("{binary_name} not found. {install_instructions}");
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)