diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 3987359ff..23788e4fe 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -31,6 +31,12 @@ jobs: - name: Build xtasks run: cargo build -p xtask + - name: Upgrade Cairo to latest main commit + run: cargo xtask set-cairo-version --rev $(git ls-remote --refs "https://github.com/starkware-libs/cairo" main | awk '{print $1}') + + - name: Rebuild xtasks after Cargo.toml changes + run: cargo build -p xtask + - name: Determine nightly version id: version shell: bash @@ -47,11 +53,11 @@ jobs: echo "nightly_version=$NIGHTLY_VERSION" >> $GITHUB_OUTPUT echo "nightly_branch=$NIGHTLY_BRANCH" >> $GITHUB_OUTPUT - - name: Upgrade Cairo to latest main commit - run: cargo xtask set-cairo-version --rev $(git ls-remote --refs "https://github.com/starkware-libs/cairo" main | awk '{print $1}') + - name: Set Scarb version build metadata + run: cargo xtask set-scarb-version --build ${{ env.NIGHTLY_TAG }} - - name: Set Scarb version - run: cargo xtask set-scarb-version ${{ env.NIGHTLY_VERSION }} + - name: Rebuild xtasks after Cargo.toml changes + run: cargo build -p xtask - name: Compose release notes run: cargo xtask nightly-release-notes > NIGHTLY_RELEASE_NOTES.md diff --git a/Cargo.lock b/Cargo.lock index 3417c0991..f658a9454 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -457,7 +457,7 @@ dependencies = [ [[package]] name = "cairo-lang-casm" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-utils", "indoc", @@ -473,7 +473,7 @@ dependencies = [ [[package]] name = "cairo-lang-compiler" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "anyhow", "cairo-lang-defs", @@ -498,7 +498,7 @@ dependencies = [ [[package]] name = "cairo-lang-debug" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-utils", ] @@ -506,7 +506,7 @@ dependencies = [ [[package]] name = "cairo-lang-defs" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-debug", "cairo-lang-diagnostics", @@ -523,7 +523,7 @@ dependencies = [ [[package]] name = "cairo-lang-diagnostics" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -535,7 +535,7 @@ dependencies = [ [[package]] name = "cairo-lang-eq-solver" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-utils", "good_lp", @@ -546,7 +546,7 @@ dependencies = [ [[package]] name = "cairo-lang-filesystem" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-debug", "cairo-lang-utils", @@ -559,7 +559,7 @@ dependencies = [ [[package]] name = "cairo-lang-formatter" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "anyhow", "cairo-lang-diagnostics", @@ -580,7 +580,7 @@ dependencies = [ [[package]] name = "cairo-lang-language-server" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -612,7 +612,7 @@ dependencies = [ [[package]] name = "cairo-lang-lowering" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -637,7 +637,7 @@ dependencies = [ [[package]] name = "cairo-lang-parser" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-diagnostics", "cairo-lang-filesystem", @@ -657,7 +657,7 @@ dependencies = [ [[package]] name = "cairo-lang-plugins" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-defs", "cairo-lang-diagnostics", @@ -676,7 +676,7 @@ dependencies = [ [[package]] name = "cairo-lang-proc-macros" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-debug", "quote", @@ -686,7 +686,7 @@ dependencies = [ [[package]] name = "cairo-lang-project" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-filesystem", "cairo-lang-utils", @@ -699,7 +699,7 @@ dependencies = [ [[package]] name = "cairo-lang-runner" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "anyhow", "ark-ff", @@ -735,7 +735,7 @@ dependencies = [ [[package]] name = "cairo-lang-semantic" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -758,7 +758,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "anyhow", "cairo-lang-utils", @@ -781,7 +781,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-ap-change" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -794,7 +794,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-gas" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -807,7 +807,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-generator" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -832,7 +832,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-to-casm" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "assert_matches", "cairo-felt", @@ -853,7 +853,7 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-type-size" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-sierra", "cairo-lang-utils", @@ -862,7 +862,7 @@ dependencies = [ [[package]] name = "cairo-lang-starknet" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "anyhow", "cairo-felt", @@ -903,7 +903,7 @@ dependencies = [ [[package]] name = "cairo-lang-syntax" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -919,7 +919,7 @@ dependencies = [ [[package]] name = "cairo-lang-syntax-codegen" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "genco", "xshell", @@ -928,7 +928,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-plugin" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "anyhow", "cairo-felt", @@ -952,7 +952,7 @@ dependencies = [ [[package]] name = "cairo-lang-test-runner" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "anyhow", "cairo-felt", @@ -976,7 +976,7 @@ dependencies = [ [[package]] name = "cairo-lang-utils" version = "2.2.0" -source = "git+https://github.com/starkware-libs/cairo?branch=main#1953687e242964f25c2ceeb45f5cf1a0119ccecd" +source = "git+https://github.com/starkware-libs/cairo?rev=70e67af#70e67af9a578899123fcbfd37b186aee15416eef" dependencies = [ "env_logger", "indexmap 2.0.0", @@ -3828,7 +3828,7 @@ dependencies = [ [[package]] name = "scarb" -version = "0.7.0" +version = "2.2.0" dependencies = [ "anyhow", "assert_fs", @@ -3900,14 +3900,15 @@ dependencies = [ [[package]] name = "scarb-build-metadata" -version = "0.7.0" +version = "2.2.0" dependencies = [ "cargo_metadata", + "semver", ] [[package]] name = "scarb-cairo-language-server" -version = "0.7.0" +version = "2.2.0" dependencies = [ "cairo-lang-language-server", "cairo-lang-utils", @@ -3917,7 +3918,7 @@ dependencies = [ [[package]] name = "scarb-cairo-run" -version = "0.7.0" +version = "2.2.0" dependencies = [ "anyhow", "assert_fs", @@ -3936,7 +3937,7 @@ dependencies = [ [[package]] name = "scarb-cairo-test" -version = "0.7.0" +version = "2.2.0" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -4004,7 +4005,7 @@ dependencies = [ [[package]] name = "scarb-ui" -version = "0.7.0" +version = "2.2.0" dependencies = [ "anyhow", "camino", @@ -5237,7 +5238,7 @@ checksum = "7e2c411759b501fb9501aac2b1b2d287a6e93e5bdcf13c25306b23e1b716dd0e" [[package]] name = "xtask" -version = "0.7.0" +version = "1.0.0" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index f4705265e..6a46adbfb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ members = [ "resolver" = "2" [workspace.package] -version = "0.7.0" +version = "2.2.0" edition = "2021" authors = ["Software Mansion "] @@ -28,19 +28,19 @@ repository = "https://github.com/software-mansion/scarb" anyhow = "1.0.75" assert_fs = "1.0.13" async-trait = "0.1.73" -cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", branch = "main" } -cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", branch = "main" } -cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", branch = "main" } -cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", branch = "main" } -cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", branch = "main" } -cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", branch = "main" } -cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", branch = "main" } -cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", branch = "main" } -cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", branch = "main" } -cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", branch = "main" } -cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", branch = "main" } -cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", branch = "main" } -cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", branch = "main", features = ["env_logger"] } +cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "70e67af" } +cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "70e67af" } +cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "70e67af" } +cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "70e67af" } +cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "70e67af" } +cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "70e67af" } +cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "70e67af" } +cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "70e67af" } +cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "70e67af" } +cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "70e67af" } +cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "70e67af" } +cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "70e67af" } +cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "70e67af", features = ["env_logger"] } camino = { version = "1.1.6", features = ["serde1"] } cargo_metadata = "0.17.0" clap = { version = "4.4.3", features = ["derive", "env", "string"] } diff --git a/scarb/tests/internal.rs b/scarb/tests/internal.rs deleted file mode 100644 index 4a513ec67..000000000 --- a/scarb/tests/internal.rs +++ /dev/null @@ -1,50 +0,0 @@ -//! Tests for internal code checks. - -use std::fs; - -use semver::{BuildMetadata, Prerelease, Version}; -use toml_edit::Document; - -/// Checks that package version in [`Cairo.toml`] is exactly the same as the version of `Cairo` -/// dependency, because this project is tightly coupled with it. -#[test] -#[ignore = "Scarb is not ready to be version synced with Cairo"] -fn project_version_is_bound_to_cairo_version() { - let cargo_toml: Document = fs::read_to_string("../Cargo.toml") - .unwrap() - .parse() - .unwrap(); - let cargo_lock: Document = fs::read_to_string("../Cargo.lock") - .unwrap() - .parse() - .unwrap(); - - let mut package_version: Version = cargo_toml["workspace"]["package"]["version"] - .as_value() - .unwrap() - .as_str() - .unwrap() - .parse() - .unwrap(); - - let mut cairo_version: Version = cargo_lock["package"] - .as_array_of_tables() - .unwrap() - .iter() - .find(|t| t["name"].as_value().unwrap().as_str().unwrap() == "cairo-lang-compiler") - .unwrap()["version"] - .as_value() - .unwrap() - .as_str() - .unwrap() - .parse() - .unwrap(); - - // Allow differences in prerelease and build metadata - package_version.pre = Prerelease::EMPTY; - package_version.build = BuildMetadata::EMPTY; - cairo_version.pre = Prerelease::EMPTY; - cairo_version.build = BuildMetadata::EMPTY; - - assert_eq!(package_version, cairo_version); -} diff --git a/utils/scarb-build-metadata/Cargo.toml b/utils/scarb-build-metadata/Cargo.toml index 8eff8e68f..cd2e2cf8c 100644 --- a/utils/scarb-build-metadata/Cargo.toml +++ b/utils/scarb-build-metadata/Cargo.toml @@ -7,3 +7,6 @@ publish = false [build-dependencies] cargo_metadata.workspace = true + +[dev-dependencies] +semver.workspace = true diff --git a/utils/scarb-build-metadata/src/lib.rs b/utils/scarb-build-metadata/src/lib.rs index e576aca46..3072a80aa 100644 --- a/utils/scarb-build-metadata/src/lib.rs +++ b/utils/scarb-build-metadata/src/lib.rs @@ -26,3 +26,23 @@ pub const CAIRO_COMMIT_HASH: Option = match ( _ => panic!("Either SCARB_CAIRO_COMMIT_HASH or SCARB_CAIRO_SHORT_COMMIT_HASH is missing."), }; pub const CAIRO_COMMIT_REV: &str = env!("SCARB_CAIRO_COMMIT_REV"); + +#[cfg(test)] +mod tests { + use semver::{BuildMetadata, Version}; + + /// Checks that package version in [`Scarb.toml`] is exactly the same as the version of Cairo, + /// because this project is tightly coupled with it. + #[test] + fn scarb_version_is_bound_to_cairo_version() { + let normalize = |v| { + let mut v = Version::parse(v).unwrap(); + v.build = BuildMetadata::EMPTY; + v.to_string() + }; + + let scarb_version = normalize(crate::SCARB_VERSION); + let cairo_version = normalize(crate::CAIRO_VERSION); + assert_eq!(scarb_version, cairo_version); + } +} diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 16bb6600d..64829682c 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "xtask" -# Do not diverge this from Scarb's version. For simplicity we assume that both have same version in several commands. -version.workspace = true +version = "1.0.0" edition.workspace = true publish = false diff --git a/xtask/src/get_nightly_version.rs b/xtask/src/get_nightly_version.rs index 9ae7eb01b..b7c78f72a 100644 --- a/xtask/src/get_nightly_version.rs +++ b/xtask/src/get_nightly_version.rs @@ -3,6 +3,8 @@ use clap::Parser; use semver::{BuildMetadata, Prerelease, Version}; use time::OffsetDateTime; +use crate::set_scarb_version::expected_scarb_version; + #[derive(Parser)] pub struct Args { #[arg(short, long)] @@ -14,18 +16,17 @@ pub fn main(args: Args) -> Result<()> { if args.tag { println!("{tag}"); } else { - let version = nightly_version(); + let version = nightly_version()?; println!("{version}"); } Ok(()) } -pub fn nightly_version() -> Version { - // NOTE: We are not using scarb-build-metadata here to reduce compilation times of xtask crate. - let mut version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); +pub fn nightly_version() -> Result { + let mut version = expected_scarb_version()?; version.pre = Prerelease::EMPTY; version.build = BuildMetadata::new(&nightly_tag()).unwrap(); - version + Ok(version) } pub fn nightly_tag() -> String { diff --git a/xtask/src/nightly_release_notes.rs b/xtask/src/nightly_release_notes.rs index 160c195d2..f41d62d51 100644 --- a/xtask/src/nightly_release_notes.rs +++ b/xtask/src/nightly_release_notes.rs @@ -12,7 +12,7 @@ pub fn main(_: Args) -> Result<()> { let sh = Shell::new()?; - let version = nightly_version(); + let version = nightly_version()?; let scarb_commit = cmd!(sh, "git log -1 --date=short --format=%H").read()?; diff --git a/xtask/src/set_cairo_version.rs b/xtask/src/set_cairo_version.rs index 3de3f4bee..f2e2d7092 100644 --- a/xtask/src/set_cairo_version.rs +++ b/xtask/src/set_cairo_version.rs @@ -4,6 +4,8 @@ use semver::Version; use toml_edit::{Document, InlineTable, Value}; use xshell::{cmd, Shell}; +use crate::set_scarb_version; + #[derive(Parser)] pub struct Args { #[command(flatten)] @@ -87,6 +89,9 @@ pub fn main(args: Args) -> Result<()> { sh.write_file("Cargo.toml", cargo_toml.to_string())?; cmd!(sh, "cargo fetch").run()?; + + eprintln!("$ cargo xtask set-scarb-version"); + set_scarb_version::main(Default::default())?; } Ok(()) diff --git a/xtask/src/set_scarb_version.rs b/xtask/src/set_scarb_version.rs index dd78830b4..c2e2c13cf 100644 --- a/xtask/src/set_scarb_version.rs +++ b/xtask/src/set_scarb_version.rs @@ -1,14 +1,39 @@ -use anyhow::Result; +use anyhow::{ensure, Result}; use clap::Parser; use semver::Version; use toml_edit::{value, Document}; use xshell::{cmd, Shell}; -#[derive(Parser)] +pub fn expected_scarb_version() -> Result { + // NOTE: We are reading lockfile manually here, so that we are not dependent on when this + // program was built (that would be the case when using scarb-build-metadata). We are also + // deliberately not using cargo_metadata, to reduce build times of xtasks. + + let sh = Shell::new()?; + let cargo_lock = sh.read_file("Cargo.lock")?.parse::()?; + let packages = cargo_lock["package"].as_array_of_tables().unwrap(); + let compiler = { + let pkgs = packages + .into_iter() + .filter(|pkg| pkg["name"].as_str().unwrap() == "cairo-lang-compiler") + .collect::>(); + ensure!( + pkgs.len() == 1, + "expected exactly one cairo-lang-compiler package in Cargo.lock, found: {}", + pkgs.len() + ); + pkgs.into_iter().next().unwrap() + }; + let compiler_version = compiler["version"].as_str().unwrap(); + Ok(compiler_version.parse()?) +} + +#[derive(Default, Parser)] pub struct Args { - version: Version, + #[arg(long)] + pub build: Option, #[arg(long, default_value_t = false)] - dry_run: bool, + pub dry_run: bool, } pub fn main(args: Args) -> Result<()> { @@ -17,7 +42,13 @@ pub fn main(args: Args) -> Result<()> { let mut cargo_toml = sh.read_file("Cargo.toml")?.parse::()?; let package = cargo_toml["workspace"]["package"].as_table_mut().unwrap(); - package["version"] = value(args.version.to_string()); + let mut version = expected_scarb_version()?; + + if let Some(build) = args.build { + version.build = build.parse()?; + } + + package["version"] = value(version.to_string()); eprintln!("[workspace.package]\n{package}");