Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(cairo_native): compare the required starknet-native-compile version to workspace version #3975

Open
wants to merge 1 commit into
base: avi/fix-native-compiler-binary-crate
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ members = [
"crates/starknet_state_sync",
"crates/starknet_state_sync_types",
"crates/starknet_task_executor",
"toml_test_utils",
"workspace_tests",
]

Expand Down Expand Up @@ -255,6 +256,7 @@ tokio-stream = "0.1.8"
tokio-test = "0.4.4"
tokio-util = "0.7.13"
toml = "0.8"
toml_test_utils = { path = "toml_test_utils", version = "0.14.0-rc.0" }
tower = "0.4.13"
tracing = "0.1.37"
tracing-subscriber = "0.3.16"
Expand Down
1 change: 1 addition & 0 deletions crates/starknet_sierra_multicompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ assert_matches.workspace = true
mempool_test_utils.path = "../mempool_test_utils"
rstest.workspace = true
starknet_infra_utils.path = "../starknet_infra_utils"
toml_test_utils.path = "../../toml_test_utils"

[build-dependencies]
# NOTE: This dependency is not necessary for the code to work. It is added to make the implicit
Expand Down
7 changes: 2 additions & 5 deletions crates/starknet_sierra_multicompile/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ fn main() {
}

const REQUIRED_CAIRO_LANG_VERSION: &str = "2.10.0-rc.1";
#[cfg(feature = "cairo_native")]
// TODO(Avi, 15/2/2025): Add test that checks the version of this constant is the workspace version.
const REQUIRED_CAIRO_NATIVE_VERSION: &str = "v0.14.0-rc.0";

/// Downloads the Cairo crate from StarkWare's release page and extracts its contents into the
/// `target` directory. This crate includes the `starknet-sierra-compile` binary, which is used to
Expand All @@ -38,8 +35,8 @@ fn install_starknet_sierra_compile() {
/// compilation is required.
#[cfg(feature = "cairo_native")]
fn install_starknet_native_compile() {
let binary_name = CAIRO_NATIVE_BINARY_NAME;
let required_version = REQUIRED_CAIRO_NATIVE_VERSION;
let binary_name = NATIVE_COMPILE_BINARY_NAME;
let required_version = REQUIRED_NATIVE_COMPILE_VERSION;

let repo_root_dir =
starknet_infra_utils::path::project_path().expect("Should be able to get the project path");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tempfile::NamedTempFile;
use crate::config::SierraCompilationConfig;
use crate::constants::CAIRO_LANG_BINARY_NAME;
#[cfg(feature = "cairo_native")]
use crate::constants::CAIRO_NATIVE_BINARY_NAME;
use crate::constants::NATIVE_COMPILE_BINARY_NAME;
use crate::errors::CompilationUtilError;
use crate::paths::binary_path;
use crate::resource_limits::ResourceLimits;
Expand All @@ -33,7 +33,7 @@ impl CommandLineCompiler {
#[cfg(feature = "cairo_native")]
let path_to_starknet_native_compile_binary = match &config.sierra_to_native_compiler_path {
Some(path) => path.clone(),
None => binary_path(out_dir(), CAIRO_NATIVE_BINARY_NAME),
None => binary_path(out_dir(), NATIVE_COMPILE_BINARY_NAME),
};
Self {
config,
Expand Down
1 change: 0 additions & 1 deletion crates/starknet_sierra_multicompile/src/compile_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ fn test_compile_sierra_to_native() {
let compiler = command_line_compiler();
let contract_class = get_test_contract();

// TODO(Avi, 1/1/2025): Check size/memory/time limits.
let _native_contract_executor = compiler.compile_to_native(contract_class).unwrap();
}

Expand Down
5 changes: 4 additions & 1 deletion crates/starknet_sierra_multicompile/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@

pub(crate) const CAIRO_LANG_BINARY_NAME: &str = "starknet-sierra-compile";
#[cfg(feature = "cairo_native")]
pub(crate) const CAIRO_NATIVE_BINARY_NAME: &str = "starknet-native-compile";
pub(crate) const NATIVE_COMPILE_BINARY_NAME: &str = "starknet-native-compile";

#[cfg(feature = "cairo_native")]
pub const REQUIRED_NATIVE_COMPILE_VERSION: &str = "0.14.0-rc.0";
10 changes: 10 additions & 0 deletions crates/starknet_sierra_multicompile/src/constants_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![cfg(feature = "cairo_native")]
use toml_test_utils::ROOT_TOML;

use crate::constants::REQUIRED_NATIVE_COMPILE_VERSION;

#[test]
fn native_compile_version_test() {
let workspace_version = ROOT_TOML.workspace_version();
assert_eq!(REQUIRED_NATIVE_COMPILE_VERSION, workspace_version);
}
4 changes: 4 additions & 0 deletions crates/starknet_sierra_multicompile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ pub mod test_utils;
#[path = "compile_test.rs"]
pub mod compile_test;

#[cfg(test)]
#[path = "constants_test.rs"]
pub mod constants_test;

pub trait SierraToCasmCompiler: Send + Sync {
fn compile(
&self,
Expand Down
14 changes: 14 additions & 0 deletions toml_test_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "toml_test_utils"
version.workspace = true
edition.workspace = true
repository.workspace = true
license.workspace = true
description = "Utilities for working with TOML files in tests."

[lints]
workspace = true

[dependencies]
serde = { workspace = true, features = ["derive"] }
toml.workspace = true
42 changes: 21 additions & 21 deletions workspace_tests/toml_utils.rs → toml_test_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,53 @@ use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub(crate) enum LintValue {
pub enum LintValue {
Bool(bool),
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub(crate) enum DependencyValue {
pub enum DependencyValue {
String(String),
Object { version: Option<String>, path: Option<String>, features: Option<Vec<String>> },
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub(crate) struct Package {
pub struct Package {
version: String,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub(crate) struct WorkspaceFields {
pub struct WorkspaceFields {
package: Package,
members: Vec<String>,
dependencies: HashMap<String, DependencyValue>,
}

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

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub(crate) enum PackageEntryValue {
pub enum PackageEntryValue {
String(String),
Object { workspace: bool },
Other(toml::Value),
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub(crate) struct CrateCargoToml {
pub(crate) package: HashMap<String, PackageEntryValue>,
pub struct CrateCargoToml {
pub package: HashMap<String, PackageEntryValue>,
dependencies: Option<HashMap<String, DependencyValue>>,
#[serde(rename = "dev-dependencies")]
pub(crate) dev_dependencies: Option<HashMap<String, DependencyValue>>,
pub(crate) lints: Option<HashMap<String, LintValue>>,
pub dev_dependencies: Option<HashMap<String, DependencyValue>>,
pub lints: Option<HashMap<String, LintValue>>,
}

impl CrateCargoToml {
pub(crate) fn package_name(&self) -> &String {
pub fn package_name(&self) -> &String {
match self.package.get("name") {
Some(PackageEntryValue::String(name)) => name,
_ => panic!("No name found in crate toml {self:?}."),
Expand All @@ -62,32 +62,32 @@ impl CrateCargoToml {
}

#[derive(Debug)]
pub(crate) struct LocalCrate {
pub(crate) path: String,
pub(crate) version: String,
pub struct LocalCrate {
pub path: String,
pub version: String,
}

pub(crate) static ROOT_TOML: LazyLock<CargoToml> = LazyLock::new(|| {
pub static ROOT_TOML: LazyLock<CargoToml> = LazyLock::new(|| {
let root_toml: CargoToml =
toml::from_str(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../Cargo.toml")))
.unwrap();
root_toml
});

impl CargoToml {
pub(crate) fn members(&self) -> &Vec<String> {
pub fn members(&self) -> &Vec<String> {
&self.workspace.members
}

pub(crate) fn workspace_version(&self) -> &str {
pub fn workspace_version(&self) -> &str {
&self.workspace.package.version
}

pub(crate) fn dependencies(&self) -> impl Iterator<Item = (&String, &DependencyValue)> + '_ {
pub fn dependencies(&self) -> impl Iterator<Item = (&String, &DependencyValue)> + '_ {
self.workspace.dependencies.iter()
}

pub(crate) fn path_dependencies(&self) -> impl Iterator<Item = LocalCrate> + '_ {
pub fn path_dependencies(&self) -> impl Iterator<Item = LocalCrate> + '_ {
self.dependencies().filter_map(|(_name, value)| {
if let DependencyValue::Object { path: Some(path), version: Some(version), .. } = value
{
Expand All @@ -98,7 +98,7 @@ impl CargoToml {
})
}

pub(crate) fn member_cargo_tomls(&self) -> HashMap<String, CrateCargoToml> {
pub fn member_cargo_tomls(&self) -> HashMap<String, CrateCargoToml> {
let crates_dir = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/../"));
self.members()
.iter()
Expand All @@ -116,7 +116,7 @@ impl CargoToml {
}

impl CrateCargoToml {
pub(crate) fn path_dependencies(&self) -> impl Iterator<Item = String> + '_ {
pub fn path_dependencies(&self) -> impl Iterator<Item = String> + '_ {
self.dependencies.iter().flatten().filter_map(|(_name, value)| {
if let DependencyValue::Object { path: Some(path), .. } = value {
Some(path.to_string())
Expand Down
3 changes: 1 addition & 2 deletions workspace_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ license-file.workspace = true
description = "Workspace-level tests."

[dev-dependencies]
serde = { workspace = true, features = ["derive"] }
toml.workspace = true
toml_test_utils = { path = "../toml_test_utils" }

[[test]]
name = "workspace_tests"
Expand Down
2 changes: 1 addition & 1 deletion workspace_tests/lints_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use crate::toml_utils::{CrateCargoToml, LintValue, ROOT_TOML};
use toml_test_utils::{CrateCargoToml, LintValue, ROOT_TOML};

#[test]
fn test_lints_section_exists() {
Expand Down
1 change: 0 additions & 1 deletion workspace_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

pub mod lints_test;
pub mod package_integrity_test;
pub mod toml_utils;
pub mod version_integrity_test;
2 changes: 1 addition & 1 deletion workspace_tests/package_integrity_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::PathBuf;

use crate::toml_utils::{CrateCargoToml, DependencyValue, PackageEntryValue, ROOT_TOML};
use toml_test_utils::{CrateCargoToml, DependencyValue, PackageEntryValue, ROOT_TOML};

#[test]
fn test_package_names_match_directory() {
Expand Down
2 changes: 1 addition & 1 deletion workspace_tests/version_integrity_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::toml_utils::{DependencyValue, LocalCrate, PackageEntryValue, ROOT_TOML};
use toml_test_utils::{DependencyValue, LocalCrate, PackageEntryValue, ROOT_TOML};

#[test]
fn test_path_dependencies_are_members() {
Expand Down
Loading