Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix --no-default-features library-only builds. #984

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
15 changes: 9 additions & 6 deletions src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<Program>> {
pub fn cairo_to_sierra(program: &Path) -> crate::error::Result<Arc<Program>> {
if program
.extension()
.map(|x| {
Expand All @@ -184,14 +184,14 @@ pub fn cairo_to_sierra(program: &Path) -> anyhow::Result<Arc<Program>> {
..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.
Expand Down
24 changes: 18 additions & 6 deletions src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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::<u8>()).cast();
*ptr.cast::<u8>().as_mut() = *value;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down
Loading