Skip to content

Commit

Permalink
Compare the required starknet-native-compile version to workspace ver…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
avi-starkware committed Feb 5, 2025
1 parent 902b823 commit 933de4a
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 32 deletions.
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
5 changes: 5 additions & 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 All @@ -40,3 +41,7 @@ starknet_infra_utils.path = "../starknet_infra_utils"
starknet-native-compile.path = "../bin/starknet-native-compile"
starknet_infra_utils.workspace = true
tempfile.workspace = true

[[test]]
name = "cairo_native_version_test"
path = "tests/cairo_native_version_test.rs"
3 changes: 0 additions & 3 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 Down
3 changes: 3 additions & 0 deletions crates/starknet_sierra_multicompile/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
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";

#[cfg(feature = "cairo_native")]
pub const REQUIRED_CAIRO_NATIVE_VERSION: &str = "0.14.0-rc.0";
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use starknet_sierra_multicompile::constants::REQUIRED_CAIRO_NATIVE_VERSION;
use toml_test_utils::ROOT_TOML;

#[test]
fn cairo_native_version_test() {
let workspace_version = ROOT_TOML.workspace_version();
assert_eq!(REQUIRED_CAIRO_NATIVE_VERSION, workspace_version);
}
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

0 comments on commit 933de4a

Please sign in to comment.