Skip to content

Commit 5ee741b

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 7e79823 commit 5ee741b

14 files changed

Lines changed: 70 additions & 109 deletions

File tree

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

crates/blockifier_reexecution/replay/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ RUN cargo chef cook --release -p blockifier_reexecution --features cairo_native
8282
COPY . .
8383
RUN cargo build --release -p blockifier_reexecution --features cairo_native
8484

85+
# Install compiler binaries used for Sierra compilation at runtime.
86+
RUN scripts/install_compiler_binaries.sh --dest /usr/local/bin
87+
8588
# =============================================================================
8689
# Stage 4: Final runtime image
8790
# =============================================================================
@@ -100,8 +103,8 @@ WORKDIR /app
100103

101104
# Copy the binary and both compilers (Sierra-to-CASM and Sierra-to-Native).
102105
COPY --from=builder /app/target/release/blockifier_reexecution ./target/release/blockifier_reexecution
103-
COPY --from=builder /app/target/release/shared_executables/starknet-sierra-compile ./target/release/shared_executables/starknet-sierra-compile
104-
COPY --from=builder /app/target/release/shared_executables/starknet-native-compile ./target/release/shared_executables/starknet-native-compile
106+
COPY --from=builder /usr/local/bin/starknet-sierra-compile /usr/local/bin/starknet-sierra-compile
107+
COPY --from=builder /usr/local/bin/starknet-native-compile /usr/local/bin/starknet-native-compile
105108
COPY --from=builder /usr/bin/tini /usr/bin/tini
106109

107110
RUN set -ex; \

crates/starknet_transaction_prover/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ RUN BUILD_FLAGS=$([ "$BUILD_MODE" = "release" ] && echo "--release" || true); \
135135
cargo build $BUILD_FLAGS -p starknet_transaction_prover --features stwo_proving; \
136136
fi
137137

138+
# Install compiler binary used for Sierra to CASM compilation at runtime.
139+
RUN scripts/install_compiler_binaries.sh --sierra --dest /usr/local/bin
140+
138141
# =============================================================================
139142
# Stage 4: Final runtime image
140143
# =============================================================================
@@ -158,7 +161,7 @@ COPY --from=builder /app/target/${BUILD_MODE}/starknet_transaction_prover ./targ
158161
COPY --from=builder /app/crates/starknet_transaction_prover/resources ./crates/starknet_transaction_prover/resources
159162

160163
# Copy starknet-sierra-compile binary required for Sierra to Casm compilation.
161-
COPY --from=builder /app/target/${BUILD_MODE}/shared_executables/starknet-sierra-compile ./target/${BUILD_MODE}/shared_executables/starknet-sierra-compile
164+
COPY --from=builder /usr/local/bin/starknet-sierra-compile /usr/local/bin/starknet-sierra-compile
162165

163166
# Copy tini for proper init handling.
164167
COPY --from=builder /usr/bin/tini /usr/bin/tini

0 commit comments

Comments
 (0)