diff --git a/CHANGELOG.md b/CHANGELOG.md index 142478919..22fdf1685 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Synchronized with `polkadot-sdk/c40b36c3a7c208f9a6837b80812473af3d9ba7f7` ‒ [2102](https://github.com/use-ink/cargo-contract/pull/2102) +- Re-enable `rustc` overflow checks - [#2116](https://github.com/use-ink/cargo-contract/pull/2116) ### Removed - Removed chain extension functionality ‒ [2120](https://github.com/use-ink/cargo-contract/pull/2120) diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs index afb5d4ed5..297b15d44 100644 --- a/crates/build/src/lib.rs +++ b/crates/build/src/lib.rs @@ -357,7 +357,10 @@ fn exec_cargo_for_onchain_target( if build_mode == &BuildMode::Debug { features.push("ink/ink-debug".to_string()); } else { - args.push("-Zbuild-std-features=panic_immediate_abort".to_owned()); + args.push( + "-Zbuild-std-features=panic_immediate_abort,compiler-builtins-mem" + .to_owned(), + ); } features.append_to_args(&mut args); let mut env = Vec::new(); diff --git a/crates/build/src/workspace/manifest.rs b/crates/build/src/workspace/manifest.rs index e21a88c3d..f5e37f0ff 100644 --- a/crates/build/src/workspace/manifest.rs +++ b/crates/build/src/workspace/manifest.rs @@ -134,19 +134,11 @@ impl Manifest { pub fn new(manifest_path: ManifestPath) -> Result { let toml = fs::read_to_string(&manifest_path).context("Loading Cargo.toml")?; let toml: value::Table = toml::from_str(&toml)?; - let mut manifest = Manifest { + let manifest = Manifest { path: manifest_path, toml, metadata_package: false, }; - let profile = manifest.profile_release_table_mut()?; - if profile - .get("overflow-checks") - .and_then(|val| val.as_bool()) - .unwrap_or(false) - { - anyhow::bail!("Overflow checks must be disabled. Cargo contract makes sure that no unchecked arithmetic is used.") - } Ok(manifest) } diff --git a/crates/build/src/workspace/profile.rs b/crates/build/src/workspace/profile.rs index a66e3aa1c..00761f19b 100644 --- a/crates/build/src/workspace/profile.rs +++ b/crates/build/src/workspace/profile.rs @@ -27,6 +27,7 @@ pub struct Profile { // `None` means use rustc default. pub codegen_units: Option, pub panic: Option, + pub overflow_checks: Option, } impl Profile { @@ -37,6 +38,7 @@ impl Profile { lto: Some(Lto::Fat), codegen_units: Some(1), panic: Some(PanicStrategy::Abort), + overflow_checks: Some(true), } } @@ -73,6 +75,7 @@ impl Profile { self.panic.map(PanicStrategy::to_toml_value), profile, ); + set_value_if_vacant("overflow-checks", self.overflow_checks, profile); } } @@ -159,6 +162,7 @@ mod tests { expected.insert("lto".into(), value::Value::String("fat".into())); expected.insert("codegen-units".into(), value::Value::Integer(1)); expected.insert("panic".into(), value::Value::String("abort".into())); + expected.insert("overflow-checks".into(), value::Value::Boolean(true)); let mut manifest_profile = toml::from_str(manifest_toml).unwrap(); @@ -176,12 +180,14 @@ mod tests { lto = false opt-level = 3 codegen-units = 256 + overflow-checks = false "#; let mut expected = value::Table::new(); expected.insert("opt-level".into(), value::Value::Integer(3)); expected.insert("lto".into(), value::Value::Boolean(false)); expected.insert("codegen-units".into(), value::Value::Integer(256)); expected.insert("panic".into(), value::Value::String("unwind".into())); + expected.insert("overflow-checks".into(), value::Value::Boolean(false)); let mut manifest_profile = toml::from_str(manifest_toml).unwrap();