Skip to content

Commit

Permalink
Prepare release 2.6.0 (#1171)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciektr authored Mar 4, 2024
1 parent 781df2a commit 850b938
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 107 deletions.
159 changes: 94 additions & 65 deletions Cargo.lock

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ members = [
"resolver" = "2"

[workspace.package]
version = "2.5.4"
version = "2.6.0"
edition = "2021"

authors = ["Software Mansion <[email protected]>"]
Expand All @@ -34,28 +34,28 @@ assert_fs = "1"
async-trait = "0.1"
axum = { version = "0.6", features = ["http2"] }
cairo-felt = "0.9.1"
cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-project = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-sierra-type-size = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-starknet-classes = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d" }
cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "bd7cca1c3332daddc738682de0fea26da1b1973d", version = "2.5.3", features = ["env_logger"] }
cairo-lang-casm = "2.6.0"
cairo-lang-compiler = "2.6.0"
cairo-lang-debug = "2.6.0"
cairo-lang-defs = "2.6.0"
cairo-lang-diagnostics = "2.6.0"
cairo-lang-filesystem = "2.6.0"
cairo-lang-formatter = "2.6.0"
cairo-lang-language-server = "2.6.0"
cairo-lang-lowering = "2.6.0"
cairo-lang-project = "2.6.0"
cairo-lang-runner = "2.6.0"
cairo-lang-semantic = "2.6.0"
cairo-lang-sierra = "2.6.0"
cairo-lang-sierra-generator = "2.6.0"
cairo-lang-sierra-to-casm = "2.6.0"
cairo-lang-sierra-type-size = "2.6.0"
cairo-lang-starknet = "2.6.0"
cairo-lang-starknet-classes = "2.6.0"
cairo-lang-syntax = "2.6.0"
cairo-lang-test-plugin = "2.6.0"
cairo-lang-test-runner = "2.6.0"
cairo-lang-utils = { version = "2.6.0", features = ["env_logger"] }
camino = { version = "1", features = ["serde1"] }
cargo_metadata = ">=0.18"
clap = { version = "4", features = ["derive", "env", "string"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/starknet_hello_world/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ version = "0.1.0"
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
starknet = "2.5.0"
starknet = "2.6.0"

[[target.starknet-contract]]
2 changes: 1 addition & 1 deletion examples/starknet_multiple_contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ version = "0.1.0"
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
starknet = "2.5.0"
starknet = "2.6.0"

[[target.starknet-contract]]
2 changes: 1 addition & 1 deletion examples/workspaces/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test = "snforge"
exit_first = true

[workspace.dependencies]
starknet = "2.5.0"
starknet = "2.6.0"

[workspace.package]
version = "0.1.0"
Expand Down
2 changes: 1 addition & 1 deletion extensions/scarb-cairo-run/tests/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn can_limit_gas() {
Finished release target(s) in [..]
Running hello_world
Run completed successfully, returning [987]
Remaining gas: 50760
Remaining gas: 58060
"#});
}

Expand Down
3 changes: 3 additions & 0 deletions extensions/scarb-snforge-test-collector/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ fn get_crate_settings_for_package(
negative_impls: package
.experimental_features
.contains(&String::from("negative_impls")),
coupons: package
.experimental_features
.contains(&String::from("coupons")),
};

CrateSettings {
Expand Down
9 changes: 6 additions & 3 deletions scarb/src/compiler/compilers/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{Context, Result};
use cairo_lang_compiler::db::RootDatabase;
use cairo_lang_sierra_to_casm::compiler::SierraToCasmConfig;
use cairo_lang_sierra_to_casm::metadata::calc_metadata;
use serde::{Deserialize, Serialize};
use tracing::trace_span;
Expand Down Expand Up @@ -87,8 +88,6 @@ impl Compiler for LibCompiler {
if props.casm {
let program = sierra_program.into_v1().unwrap().program;

let gas_usage_check = true;

let metadata = {
let _ = trace_span!("casm_calc_metadata").enter();
calc_metadata(&program, Default::default())
Expand All @@ -97,7 +96,11 @@ impl Compiler for LibCompiler {

let cairo_program = {
let _ = trace_span!("compile_casm").enter();
cairo_lang_sierra_to_casm::compiler::compile(&program, &metadata, gas_usage_check)?
let sierra_to_casm = SierraToCasmConfig {
gas_usage_check: unit.compiler_config.enable_gas,
max_bytecode_size: usize::MAX,
};
cairo_lang_sierra_to_casm::compiler::compile(&program, &metadata, sierra_to_casm)?
};

write_string(
Expand Down
6 changes: 6 additions & 0 deletions scarb/src/compiler/compilers/starknet_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ impl Compiler for StarknetContractCompiler {
);
}

ensure!(
unit.compiler_config.enable_gas,
"the target starknet contract compilation requires gas to be enabled"
);

if let Some(external_contracts) = props.build_external_contracts.clone() {
for path in external_contracts.iter() {
ensure!(path.0.matches(GLOB_PATH_SELECTOR).count() <= 1,
Expand Down Expand Up @@ -254,6 +259,7 @@ impl Compiler for StarknetContractCompiler {
let casm_class = CasmContractClass::from_contract_class(
class.clone(),
props.casm_add_pythonic_hints,
usize::MAX,
)
.with_context(|| {
format!("{contract_name}: failed to compile Sierra contract to CASM")
Expand Down
6 changes: 5 additions & 1 deletion scarb/src/compiler/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pub(crate) fn build_scarb_root_database(
b.with_project_config(build_project_config(unit)?);
b.with_cfg(unit.cfg_set.clone());
load_plugins(unit, ws, &mut b)?;
if !unit.compiler_config.enable_gas {
b.skip_auto_withdraw_gas();
}
let mut db = b.build()?;
inject_virtual_wrapper_lib(&mut db, unit)?;
Ok(db)
Expand Down Expand Up @@ -108,6 +111,7 @@ fn build_project_config(unit: &CairoCompilationUnit) -> Result<ProjectConfig> {
.iter()
.map(|component| {
let experimental_features = component.package.manifest.experimental_features.clone();
let experimental_features = experimental_features.unwrap_or_default();
(
component.cairo_package_name(),
CrateSettings {
Expand All @@ -116,8 +120,8 @@ fn build_project_config(unit: &CairoCompilationUnit) -> Result<ProjectConfig> {
// TODO (#1040): replace this with a macro
experimental_features: cairo_lang_filesystem::db::ExperimentalFeaturesConfig {
negative_impls: experimental_features
.unwrap_or_default()
.contains(&SmolStr::new_inline("negative_impls")),
coupons: experimental_features.contains(&SmolStr::new_inline("coupons")),
},
},
)
Expand Down
6 changes: 5 additions & 1 deletion scarb/src/core/manifest/compiler_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ pub struct ManifestCompilerConfig {
pub sierra_replace_ids: bool,
/// Do not exit with error on compiler warnings.
pub allow_warnings: bool,
/// Enable auto gas withdrawal and gas usage check.
pub enable_gas: bool,
}

impl DefaultForProfile for ManifestCompilerConfig {
fn default_for_profile(profile: &Profile) -> Self {
Self {
sierra_replace_ids: profile.is_dev(),
allow_warnings: true,
enable_gas: true,
}
}
}
Expand All @@ -32,7 +35,8 @@ impl From<ManifestCompilerConfig> for TomlCairo {
fn from(config: ManifestCompilerConfig) -> Self {
Self {
sierra_replace_ids: Some(config.sierra_replace_ids),
allow_warnings: Some(true),
allow_warnings: Some(config.allow_warnings),
enable_gas: Some(config.enable_gas),
}
}
}
5 changes: 5 additions & 0 deletions scarb/src/core/manifest/toml_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ pub struct TomlCairo {
pub sierra_replace_ids: Option<bool>,
/// Do not exit with error on compiler warnings.
pub allow_warnings: Option<bool>,
/// Enable auto gas withdrawal and gas usage check.
pub enable_gas: Option<bool>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
Expand Down Expand Up @@ -816,6 +818,9 @@ impl TomlManifest {
if let Some(allow_warnings) = cairo.allow_warnings {
compiler_config.allow_warnings = allow_warnings;
}
if let Some(enable_gas) = cairo.enable_gas {
compiler_config.enable_gas = enable_gas;
}
}
Ok(compiler_config)
}
Expand Down
110 changes: 100 additions & 10 deletions scarb/tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use predicates::prelude::*;
use scarb_build_metadata::CAIRO_VERSION;
use scarb_metadata::Metadata;
use scarb_test_support::command::{CommandExt, Scarb};
use scarb_test_support::contracts::BALANCE_CONTRACT;
use scarb_test_support::fsx::ChildPathEx;
use scarb_test_support::project_builder::{Dep, DepBuilder, ProjectBuilder};
use scarb_test_support::workspace_builder::WorkspaceBuilder;
Expand Down Expand Up @@ -534,7 +535,7 @@ fn sierra_replace_ids() {
t.child("target/dev/hello.sierra.json").assert(
predicates::str::contains(r#""debug_name":"hello::example""#)
.and(predicates::str::contains(
r#""debug_name":"felt252_const<42>""#,
r#""debug_name":"Const<felt252, 42>""#,
))
.and(predicates::str::contains(
r#""debug_name":"store_temp<felt252>""#,
Expand Down Expand Up @@ -625,16 +626,11 @@ fn workspace_as_dep() {
);
second_t.child("target/dev/third.sierra.json").assert(
predicates::str::contains(r#""debug_name":"third::example""#)
.and(predicates::str::contains(r#""debug_name":"third::hello""#))
.and(predicates::str::contains(
r#""debug_name":"withdraw_gas_all""#,
)),
);
second_t.child("target/dev/third.sierra.json").assert(
predicates::str::contains(r#""debug_name":"second::fib""#).and(predicates::str::contains(
r#""debug_name":"get_builtin_costs""#,
)),
.and(predicates::str::contains(r#""debug_name":"third::hello""#)),
);
second_t
.child("target/dev/third.sierra.json")
.assert(predicates::str::contains(r#""debug_name":"second::fib""#));
}

#[test]
Expand Down Expand Up @@ -881,3 +877,97 @@ fn can_compile_no_core_package() {
.assert()
.success();
}

#[test]
fn gas_enabled_by_default() {
let t = TempDir::new().unwrap();
ProjectBuilder::start()
.name("hello")
.lib_cairo(indoc! {r#"
fn main() -> u32 {
fib(16)
}
fn fib(mut n: u32) -> u32 {
let mut a: u32 = 0;
let mut b: u32 = 1;
while n != 0 {
n = n - 1;
let temp = b;
b = a + b;
a = temp;
};
a
}
"#})
.build(&t);
Scarb::quick_snapbox()
.arg("build")
.current_dir(&t)
.assert()
.success();
t.child("target/dev/hello.sierra.json")
.assert(predicates::str::contains(r#""withdraw_gas""#));
}

#[test]
fn can_disable_gas() {
let t = TempDir::new().unwrap();
ProjectBuilder::start()
.name("hello")
.lib_cairo(indoc! {r#"
fn main() -> u32 {
fib(16)
}
fn fib(mut n: u32) -> u32 {
let mut a: u32 = 0;
let mut b: u32 = 1;
while n != 0 {
n = n - 1;
let temp = b;
b = a + b;
a = temp;
};
a
}
"#})
.manifest_extra(indoc! {r#"
[cairo]
enable-gas = false
"#})
.build(&t);
Scarb::quick_snapbox()
.arg("build")
.current_dir(&t)
.assert()
.success();
t.child("target/dev/hello.sierra.json")
.assert(predicates::str::contains(r#""withdraw_gas""#).not());
}

#[test]
fn cannot_disable_gas_for_starknet_contract() {
let t = TempDir::new().unwrap();
ProjectBuilder::start()
.name("hello")
.dep_starknet()
.lib_cairo(BALANCE_CONTRACT)
.manifest_extra(indoc! {r#"
[[target.starknet-contract]]
[cairo]
enable-gas = false
"#})
.build(&t);
Scarb::quick_snapbox()
.arg("build")
.current_dir(&t)
.assert()
.failure()
.stdout_matches(indoc! {r#"
[..]Compiling hello v1.0.0 ([..]Scarb.toml)
error: the target starknet contract compilation requires gas to be enabled
error: could not compile `hello` due to previous error
"#});
}
12 changes: 12 additions & 0 deletions website/docs/reference/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ By default, this flag is enabled.
allow-warnings = false
```

### `enable-gas`

If enabled, during the project compilation Scarb will not add any instructions related to gas usage calculation.
By default, this flag is enabled.

```toml
[cairo]
enable-gas = false
```

This flag cannot be disabled while compiling the `starknet-contract` target.

## `[profile]`

See [Profiles](./profiles) page.
Expand Down

0 comments on commit 850b938

Please sign in to comment.