Skip to content

Commit

Permalink
Add runtime check for Core library and Cairo compiler versions
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDenkoV authored and MrDenkoV committed Aug 2, 2023
1 parent b3b8647 commit 963a063
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions scarb/src/sources/standard_lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::fmt;

use anyhow::{Context, Result};
use anyhow::{anyhow, ensure, Context, Result};
use async_trait::async_trait;
use camino::Utf8Path;
use include_dir::{include_dir, Dir, DirEntry};
use tokio::sync::OnceCell;
use tracing::trace;

use crate::core::config::Config;
use crate::core::manifest::{ManifestDependency, Summary};
use crate::core::manifest::{ManifestDependency, Summary, TomlManifest};
use crate::core::package::{Package, PackageId};
use crate::core::source::Source;
use crate::core::SourceId;
Expand Down Expand Up @@ -76,6 +76,8 @@ impl<'c> StandardLibSource<'c> {
}
}

check_corelib_version(&tag_fs.path_existent()?.join("core").join("Scarb.toml"))?;

Ok(PathSource::recursive_at(
tag_path,
SourceId::for_std(),
Expand Down Expand Up @@ -146,3 +148,17 @@ fn expand_meta_variables(contents: &[u8]) -> Vec<u8> {
let contents = contents.replace("{{ CAIRO_VERSION }}", crate::version::get().cairo.version);
contents.into_bytes()
}

fn check_corelib_version(core_scarb_toml: &Utf8Path) -> Result<()> {
let comp_ver = crate::version::get().cairo.version;
let core_ver = TomlManifest::read_from_path(core_scarb_toml)?
.package
.ok_or_else(|| anyhow!("could not get package section from `core` Scarb.toml"))?
.version
.to_string();
ensure!(
comp_ver == core_ver,
"`core` version does not match Cairo compiler version"
);
Ok(())
}

0 comments on commit 963a063

Please sign in to comment.