Skip to content

Commit a529b9e

Browse files
avi-starkwareclaude
andcommitted
apollo_compile_to_casm,apollo_compile_to_native: switch to script-based compiler installation
Remove build.rs from both compiler crates — compiler binaries are now installed by scripts/install_compiler_binaries.sh (called from install_cargo_tools.sh) instead of as a cargo build side effect. - Delete build.rs and [build-dependencies] from both crates - Compiler constructors use verify_compiler_binary + PATH-based lookup (skip version check for custom paths in SierraToNativeCompiler) - install_cargo_tools.sh calls install_compiler_binaries.sh - Dockerfiles use cargo install with versions from .txt files - Base Dockerfile copies new scripts and version files Old install_compiler_binary() and legacy path functions are left for removal in a follow-up cleanup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7cc069b commit a529b9e

16 files changed

Lines changed: 67 additions & 111 deletions

File tree

.github/workflows/upload_artifacts_workflow.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,12 @@ jobs:
144144
path: "target/release/native_blockifier.pypy39-pp73-x86_64-linux-gnu.so"
145145
destination: "native_blockifier_artifacts/${{ env.SHORT_HASH }}/release/"
146146

147+
- name: Resolve starknet-native-compile path
148+
run: echo "SNC_PATH=$(which starknet-native-compile)" >> $GITHUB_ENV
149+
147150
- name: Upload starknet-native-compile to GCP
148151
id: upload_snc_file
149152
uses: "google-github-actions/upload-cloud-storage@v2"
150153
with:
151-
path: "target/release/shared_executables/starknet-native-compile"
154+
path: ${{ env.SNC_PATH }}
152155
destination: "native_blockifier_artifacts/${{ env.SHORT_HASH }}/release/"

BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Export the built artifact to allow local builds.
22
exports_files([
33
"target/release/libnative_blockifier.so",
4-
"target/release/shared_executables/starknet-native-compile",
4+
"target/release/starknet-native-compile",
55
"target/debug/starknet_committer_and_os_cli",
66
"target/release/starknet_committer_and_os_cli",
77
"target/x86_64-unknown-linux-musl/debug/starknet_committer_and_os_cli",

crates/apollo_compilation_utils/src/build_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use std::process::Command;
33

44
use tempfile::TempDir;
55

6-
use crate::paths::{binary_path, shared_folder_dir};
6+
use crate::paths::{legacy_binary_path, shared_folder_dir};
77

88
pub fn install_compiler_binary(
99
binary_name: &str,
1010
required_version: &str,
1111
cargo_install_args: &[&str],
1212
out_dir: &std::path::Path,
1313
) {
14-
let binary_path = binary_path(out_dir, binary_name);
14+
let binary_path = legacy_binary_path(out_dir, binary_name);
1515
match Command::new(&binary_path).args(["--version"]).output() {
1616
Ok(binary_version) => {
1717
let binary_version = String::from_utf8(binary_version.stdout)

crates/apollo_compilation_utils/src/paths.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ pub fn shared_folder_dir(out_dir: &std::path::Path) -> std::path::PathBuf {
1414
target_dir(out_dir).join("shared_executables")
1515
}
1616

17-
pub fn binary_path(out_dir: &std::path::Path, binary_name: &str) -> std::path::PathBuf {
17+
/// Returns the binary name as a PathBuf. `Command::new` will find it in PATH.
18+
pub fn binary_path(binary_name: &str) -> std::path::PathBuf {
19+
std::path::PathBuf::from(binary_name)
20+
}
21+
22+
// TODO(Avi): Remove once build.rs callers are gone.
23+
pub fn legacy_binary_path(out_dir: &std::path::Path, binary_name: &str) -> std::path::PathBuf {
1824
shared_folder_dir(out_dir).join(binary_name)
1925
}

crates/apollo_compile_to_casm/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ workspace = true
1616
apollo_compilation_utils.workspace = true
1717
apollo_compile_to_casm_types.workspace = true
1818
apollo_infra.workspace = true
19+
apollo_infra_utils.workspace = true
1920
apollo_metrics.workspace = true
2021
apollo_proc_macros.workspace = true
2122
apollo_sierra_compilation_config.workspace = true
@@ -29,12 +30,7 @@ tracing.workspace = true
2930

3031
[dev-dependencies]
3132
apollo_compilation_utils = { workspace = true, features = ["testing"] }
32-
apollo_infra_utils.workspace = true
3333
assert_matches.workspace = true
3434
expect-test.workspace = true
3535
mempool_test_utils.workspace = true
3636
regex.workspace = true
37-
38-
[build-dependencies]
39-
apollo_compilation_utils.workspace = true
40-
apollo_infra_utils.workspace = true

crates/apollo_compile_to_casm/build.rs

Lines changed: 0 additions & 36 deletions
This file was deleted.

crates/apollo_compile_to_casm/src/compiler.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use std::path::PathBuf;
22

3+
use apollo_compilation_utils::build_utils::verify_compiler_binary;
34
use apollo_compilation_utils::compiler_utils::compile_with_args;
45
use apollo_compilation_utils::errors::CompilationUtilError;
56
use apollo_compilation_utils::paths::binary_path;
67
use apollo_compilation_utils::resource_limits::ResourceLimits;
8+
use apollo_infra_utils::cairo_compiler_version::CAIRO1_COMPILER_VERSION;
79
use apollo_sierra_compilation_config::config::SierraCompilationConfig;
810
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
911
use cairo_lang_starknet_classes::contract_class::ContractClass;
@@ -19,7 +21,8 @@ pub struct SierraToCasmCompiler {
1921

2022
impl SierraToCasmCompiler {
2123
pub fn new(config: SierraCompilationConfig) -> Self {
22-
let path_to_binary = binary_path(&out_dir(), CAIRO_LANG_BINARY_NAME);
24+
let path_to_binary = binary_path(CAIRO_LANG_BINARY_NAME);
25+
verify_compiler_binary(&path_to_binary, CAIRO1_COMPILER_VERSION);
2326
info!("Using Sierra compiler binary at: {:?}", path_to_binary);
2427
Self { config, path_to_binary }
2528
}
@@ -51,8 +54,3 @@ impl SierraToCasmCompiler {
5154
Ok(serde_json::from_slice::<CasmContractClass>(&stdout)?)
5255
}
5356
}
54-
55-
// Returns the OUT_DIR. This function is only operable at run time.
56-
fn out_dir() -> PathBuf {
57-
env!("RUNTIME_ACCESSIBLE_OUT_DIR").into()
58-
}

crates/apollo_compile_to_native/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,3 @@ assert_matches.workspace = true
2323
mempool_test_utils.workspace = true
2424
rstest.workspace = true
2525
toml_test_utils.workspace = true
26-
27-
[build-dependencies]
28-
apollo_compilation_utils.workspace = true
29-
apollo_infra_utils.workspace = true

crates/apollo_compile_to_native/build.rs

Lines changed: 0 additions & 35 deletions
This file was deleted.

crates/apollo_compile_to_native/src/compiler.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use std::path::{Path, PathBuf};
1+
use std::path::PathBuf;
22

3+
use apollo_compilation_utils::build_utils::verify_compiler_binary;
34
use apollo_compilation_utils::compiler_utils::compile_with_args;
45
use apollo_compilation_utils::errors::CompilationUtilError;
56
use apollo_compilation_utils::paths::binary_path;
@@ -9,7 +10,7 @@ use cairo_lang_starknet_classes::contract_class::ContractClass;
910
use cairo_native::executor::AotContractExecutor;
1011
use tempfile::NamedTempFile;
1112

12-
use crate::constants::CAIRO_NATIVE_BINARY_NAME;
13+
use crate::constants::{CAIRO_NATIVE_BINARY_NAME, REQUIRED_CAIRO_NATIVE_VERSION};
1314

1415
#[derive(Clone)]
1516
pub struct SierraToNativeCompiler {
@@ -21,7 +22,11 @@ impl SierraToNativeCompiler {
2122
pub fn new(config: SierraCompilationConfig) -> Self {
2223
let path_to_binary = match &config.compiler_binary_path {
2324
Some(path) => path.clone(),
24-
None => binary_path(&out_dir(), CAIRO_NATIVE_BINARY_NAME),
25+
None => {
26+
let path = binary_path(CAIRO_NATIVE_BINARY_NAME);
27+
verify_compiler_binary(&path, REQUIRED_CAIRO_NATIVE_VERSION);
28+
path
29+
}
2530
};
2631
Self { config, path_to_binary }
2732
}
@@ -50,13 +55,8 @@ impl SierraToNativeCompiler {
5055
resource_limits,
5156
)?;
5257

53-
Ok(AotContractExecutor::from_path(Path::new(&output_file_path))
58+
Ok(AotContractExecutor::from_path(output_file.path())
5459
.map_err(|e| CompilationUtilError::CompilationError(e.to_string()))?
5560
.unwrap())
5661
}
5762
}
58-
59-
// Returns the OUT_DIR. This function is only operable at run time.
60-
fn out_dir() -> PathBuf {
61-
env!("RUNTIME_ACCESSIBLE_OUT_DIR").into()
62-
}

0 commit comments

Comments
 (0)