Skip to content

Commit

Permalink
chore(blockifier): fetch compiler repo version
Browse files Browse the repository at this point in the history
  • Loading branch information
dorimedini-starkware committed Aug 7, 2024
1 parent 73757fe commit c6d68f7
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ tokio = { version = "1.37.0", features = ["full"] }
tokio-retry = "0.3"
tokio-stream = "0.1.8"
tokio-test = "0.4.4"
toml = "0.8"
tower = "0.4.13"
tracing = "0.1.37"
tracing-subscriber = "0.3.16"
Expand Down
1 change: 1 addition & 0 deletions crates/blockifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ strum.workspace = true
strum_macros.workspace = true
thiserror.workspace = true
tikv-jemallocator = { workspace = true, optional = true }
toml.workspace = true

[dev-dependencies]
assert_matches.workspace = true
Expand Down
51 changes: 51 additions & 0 deletions crates/blockifier/src/test_utils/cairo_compile.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
use std::process::Command;

use cached::proc_macro::cached;
use serde::{Deserialize, Serialize};

/// Objects for simple deserialization of Cargo.toml to fetch the Cairo1 compiler version.
/// The compiler itself isn't actually a dependency, so we compile by using the version of the
/// cairo-lang-casm crate.
/// The choice of cairo-lang-casm is arbitrary, as all compiler crate dependencies should have the
/// same version.
/// Deserializes:
/// """
/// ...
/// [workspace.dependencies]
/// ...
/// cairo-lang-casm = VERSION
/// ...
/// """
/// where `VERSION` can be a simple "x.y.z" version string or an object with a "version" field.
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
enum DependencyValue {
// cairo-lang-casm = "x.y.z".
String(String),
// cairo-lang-casm = { version = "x.y.z", .. }.
Object { version: String },
}

#[derive(Debug, Serialize, Deserialize)]
struct CairoLangCasmDependency {
#[serde(rename = "cairo-lang-casm")]
cairo_lang_casm: DependencyValue,
}

#[derive(Debug, Serialize, Deserialize)]
struct WorkspaceFields {
dependencies: CairoLangCasmDependency,
}

#[derive(Debug, Serialize, Deserialize)]
struct CargoToml {
workspace: WorkspaceFields,
}

#[cached]
/// Returns the version of the Cairo1 compiler* defined in the root Cargo.toml.
pub fn cairo1_compiler_version() -> String {
let cargo_toml: CargoToml = toml::from_str(include_str!("../../../../Cargo.toml")).unwrap();
match cargo_toml.workspace.dependencies.cairo_lang_casm {
DependencyValue::String(version) | DependencyValue::Object { version } => version.clone(),
}
}

/// Compiles a Cairo0 program using the deprecated compiler.
pub fn cairo0_compile(path: String, extra_arg: Option<String>, debug_info: bool) -> Vec<u8> {
let mut command = Command::new("starknet-compile-deprecated");
Expand Down

0 comments on commit c6d68f7

Please sign in to comment.