From 3249563a02eca501d06a2af0a24f053ca1c02b39 Mon Sep 17 00:00:00 2001 From: MrAzteca Date: Fri, 20 Dec 2024 15:19:42 -0300 Subject: [PATCH] Fix `--no-default-features` library-only builds. (#984) --- Cargo.toml | 4 +--- src/arch.rs | 15 +++++++++------ src/error.rs | 3 +++ src/utils.rs | 8 ++++---- src/values.rs | 24 ++++++++++++++++++------ 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d3c9237fd..e281e69a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,6 @@ build-cli = [ "dep:tracing-subscriber", "dep:anyhow", "dep:cairo-lang-test-plugin", - "dep:cairo-lang-runner", "dep:colored", ] scarb = ["build-cli", "dep:scarb-ui", "dep:scarb-metadata"] @@ -62,6 +61,7 @@ bumpalo = "3.16.0" cairo-lang-compiler = "2.9.2" cairo-lang-defs = "2.9.2" cairo-lang-filesystem = "2.9.2" +cairo-lang-runner = "2.9.2" cairo-lang-semantic = "2.9.2" cairo-lang-sierra = "2.9.2" cairo-lang-sierra-generator = "2.9.2" @@ -102,7 +102,6 @@ tracing-subscriber = { version = "0.3.19", features = [ serde = { version = "1.0", features = ["derive"] } anyhow = { version = "1.0", optional = true } cairo-lang-test-plugin = { version = "2.9.2", optional = true } -cairo-lang-runner = { version = "2.9.2", optional = true } colored = { version = "2.1.0", optional = true } # needed to interface with cairo-lang-* keccak = "0.1.5" @@ -121,7 +120,6 @@ num-integer = "0.1.46" [dev-dependencies] cairo-vm = { version = "2.0.0-rc0", features = ["cairo-1-hints"] } -cairo-lang-runner = "2.9.2" cairo-lang-semantic = { version = "2.9.2", features = ["testing"] } criterion = { version = "0.5.1", features = ["html_reports"] } lambdaworks-math = "0.11.0" diff --git a/src/arch.rs b/src/arch.rs index e90079e8a..ceaca4cdb 100644 --- a/src/arch.rs +++ b/src/arch.rs @@ -146,12 +146,15 @@ impl AbiArgument for ValueWithInfoWrapper<'_> { #[cfg(not(feature = "with-runtime"))] native_panic!("enable the `with-runtime` feature to use felt252 dicts"); - // TODO: Assert that `info.ty` matches all the values' types. - - self.value - .to_ptr(self.arena, self.registry, self.type_id)? - .as_ptr() - .to_bytes(buffer)? + #[cfg(feature = "with-runtime")] + { + // TODO: Assert that `info.ty` matches all the values' types. + + self.value + .to_ptr(self.arena, self.registry, self.type_id)? + .as_ptr() + .to_bytes(buffer)? + } } ( Value::Secp256K1Point(Secp256k1Point { x, y, is_infinity }), diff --git a/src/error.rs b/src/error.rs index af6b60fda..5f5b65546 100644 --- a/src/error.rs +++ b/src/error.rs @@ -87,6 +87,9 @@ pub enum Error { #[error(transparent)] SerdeJsonError(#[from] serde_json::Error), + + #[error("Failed to parse a Cairo/Sierra program: {0}")] + ProgramParser(String), } impl Error { diff --git a/src/utils.rs b/src/utils.rs index ea6159bbd..6ac8733c2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -167,7 +167,7 @@ pub fn get_integer_layout(width: u32) -> Layout { } /// Compile a cairo program found at the given path to sierra. -pub fn cairo_to_sierra(program: &Path) -> anyhow::Result> { +pub fn cairo_to_sierra(program: &Path) -> crate::error::Result> { if program .extension() .map(|x| { @@ -184,14 +184,14 @@ pub fn cairo_to_sierra(program: &Path) -> anyhow::Result> { ..Default::default() }, ) - .map(Arc::new) + .map_err(|err| crate::error::Error::ProgramParser(err.to_string())) } else { let source = std::fs::read_to_string(program)?; cairo_lang_sierra::ProgramParser::new() .parse(&source) - .map_err(|err| anyhow::Error::msg(err.to_string())) - .map(Arc::new) + .map_err(|err| crate::error::Error::ProgramParser(err.to_string())) } + .map(Arc::new) } /// Returns the given entry point if present. diff --git a/src/values.rs b/src/values.rs index 237b283c3..042443173 100644 --- a/src/values.rs +++ b/src/values.rs @@ -21,16 +21,18 @@ use cairo_lang_sierra::{ ids::ConcreteTypeId, program_registry::ProgramRegistry, }; -use cairo_native_runtime::FeltDict; use educe::Educe; use num_bigint::{BigInt, BigUint, Sign}; use num_traits::{Euclid, One}; use starknet_types_core::felt::Felt; -use std::{ - alloc::{alloc, dealloc, Layout}, - collections::HashMap, - ptr::{null_mut, NonNull}, - slice, +use std::{alloc::Layout, collections::HashMap, ptr::NonNull, slice}; +#[cfg(feature = "with-runtime")] +use { + cairo_native_runtime::FeltDict, + std::{ + alloc::{alloc, dealloc}, + ptr::null_mut, + }, }; /// A Value is a value that can be passed to either the JIT engine or a compiled program as an argument or received as a result. @@ -377,6 +379,7 @@ impl Value { )))? } } + #[cfg(feature = "with-runtime")] Self::Felt252Dict { value: map, .. } => { if let CoreTypeConcrete::Felt252Dict(info) = Self::resolve_type(ty, registry)? { let elem_ty = registry.get_type(&info.ty)?; @@ -426,6 +429,10 @@ impl Value { )))? } } + #[cfg(not(feature = "with-runtime"))] + Self::Felt252Dict { .. } => { + native_panic!("runtime is disabled, dicts are not available"); + } Self::Uint8(value) => { let ptr = arena.alloc_layout(Layout::new::()).cast(); *ptr.cast::().as_mut() = *value; @@ -796,6 +803,7 @@ impl Value { debug_name: type_id.debug_name.as_ref().map(|x| x.to_string()), } } + #[cfg(feature = "with-runtime")] CoreTypeConcrete::Felt252Dict(info) | CoreTypeConcrete::SquashedFelt252Dict(info) => { let dict = &ptr @@ -852,6 +860,10 @@ impl Value { debug_name: type_id.debug_name.as_ref().map(|x| x.to_string()), } } + #[cfg(not(feature = "with-runtime"))] + CoreTypeConcrete::Felt252Dict(_) | CoreTypeConcrete::SquashedFelt252Dict(_) => { + native_panic!("runtime is disabled, dicts are not available") + } CoreTypeConcrete::Felt252DictEntry(_) => { native_panic!("unimplemented: should be impossible to return") }