-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(cairo_native): make the starknet-native-compile crate a part of…
… the workspace
- Loading branch information
1 parent
a3d8940
commit 902b823
Showing
9 changed files
with
135 additions
and
89 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
[package] | ||
name = "starknet-native-compile" | ||
# The version of this crate should equal the version of cairo-native. | ||
version = "0.2.5" | ||
edition = "2021" | ||
repository = "https://github.com/starkware-libs/sequencer/" | ||
license = "Apache-2.0" | ||
# Make sure this version equals the version of `cairo-native`. | ||
version.workspace = true | ||
edition.workspace = true | ||
repository.workspace = true | ||
license-file.workspace = true | ||
description = "A binary that compiles Sierra into Cairo native." | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[features] | ||
cairo_native = [ | ||
"dep:cairo-lang-sierra", | ||
"dep:cairo-lang-starknet-classes", | ||
"dep:cairo-native", | ||
"dep:clap", | ||
"dep:serde_json", | ||
] | ||
|
||
[dependencies] | ||
# TODO(Avi, 01/02/2025): Check consistency with the blockifier. | ||
cairo-lang-sierra = "2.10.0-rc.1" | ||
cairo-lang-starknet-classes = "2.10.0-rc.1" | ||
cairo-native = { git = "https://github.com/lambdaclass/cairo_native", rev = "981093a" } | ||
clap = { version = "4.5.4", features = ["derive"] } | ||
serde_json = "1.0.116" | ||
cairo-lang-sierra = { workspace = true, optional = true } | ||
cairo-lang-starknet-classes = { workspace = true, optional = true } | ||
cairo-native = { workspace = true, optional = true } | ||
clap = { workspace = true, optional = true } | ||
serde_json = { workspace = true, optional = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::path::PathBuf; | ||
use std::process; | ||
|
||
use cairo_lang_sierra::program::Program; | ||
use cairo_lang_starknet_classes::contract_class::ContractClass; | ||
use cairo_native::executor::AotContractExecutor; | ||
use cairo_native::OptLevel; | ||
use clap::Parser; | ||
|
||
#[derive(Parser, Debug)] | ||
#[clap(version, verbatim_doc_comment)] | ||
struct Args { | ||
/// The path of the Sierra file to compile. | ||
path: PathBuf, | ||
/// The output file path. | ||
output: PathBuf, | ||
} | ||
|
||
pub(crate) fn main() { | ||
let args = Args::parse(); | ||
let path = args.path; | ||
let output = args.output; | ||
|
||
let (contract_class, sierra_program) = load_sierra_program_from_file(&path); | ||
|
||
// TODO(Avi, 01/12/2024): Test different optimization levels for best performance. | ||
let mut contract_executor = AotContractExecutor::new( | ||
&sierra_program, | ||
&contract_class.entry_points_by_type, | ||
OptLevel::default(), | ||
) | ||
.unwrap_or_else(|err| { | ||
eprintln!("Error compiling Sierra program: {}", err); | ||
process::exit(1); | ||
}); | ||
contract_executor.save(output.clone()).unwrap_or_else(|err| { | ||
eprintln!("Error saving compiled program: {}", err); | ||
process::exit(1); | ||
}); | ||
} | ||
|
||
fn load_sierra_program_from_file(path: &PathBuf) -> (ContractClass, Program) { | ||
let raw_contract_class = std::fs::read_to_string(path).unwrap_or_else(|err| { | ||
eprintln!("Error reading Sierra file: {}", err); | ||
process::exit(1); | ||
}); | ||
let contract_class: ContractClass = | ||
serde_json::from_str(&raw_contract_class).unwrap_or_else(|err| { | ||
eprintln!("Error deserializing Sierra file into contract class: {}", err); | ||
process::exit(1); | ||
}); | ||
( | ||
contract_class.clone(), | ||
contract_class.extract_sierra_program().unwrap_or_else(|err| { | ||
eprintln!("Error extracting Sierra program from contract class: {}", err); | ||
process::exit(1); | ||
}), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,14 @@ | ||
use std::path::PathBuf; | ||
use std::process; | ||
|
||
use cairo_native::executor::AotContractExecutor; | ||
use cairo_native::OptLevel; | ||
use clap::Parser; | ||
|
||
use crate::utils::load_sierra_program_from_file; | ||
|
||
mod utils; | ||
|
||
#[derive(Parser, Debug)] | ||
#[clap(version, verbatim_doc_comment)] | ||
struct Args { | ||
/// The path of the Sierra file to compile. | ||
path: PathBuf, | ||
/// The output file path. | ||
output: PathBuf, | ||
} | ||
#[cfg(feature = "cairo_native")] | ||
mod cairo_native; | ||
|
||
fn main() { | ||
// TODO(Avi, 01/12/2024): Find a way to restrict time, memory and file size during compilation. | ||
let args = Args::parse(); | ||
let path = args.path; | ||
let output = args.output; | ||
|
||
let (contract_class, sierra_program) = load_sierra_program_from_file(&path); | ||
|
||
// TODO(Avi, 01/12/2024): Test different optimization levels for best performance. | ||
let mut contract_executor = AotContractExecutor::new( | ||
&sierra_program, | ||
&contract_class.entry_points_by_type, | ||
OptLevel::default(), | ||
) | ||
.unwrap_or_else(|err| { | ||
eprintln!("Error compiling Sierra program: {}", err); | ||
process::exit(1); | ||
}); | ||
contract_executor.save(output.clone()).unwrap_or_else(|err| { | ||
eprintln!("Error saving compiled program: {}", err); | ||
process::exit(1); | ||
}); | ||
#[cfg(not(feature = "cairo_native"))] | ||
{ | ||
eprintln!( | ||
"The `starknet-native-compile` binary was compiled without the 'cairo_native' feature." | ||
); | ||
std::process::exit(1); | ||
} | ||
#[cfg(feature = "cairo_native")] | ||
cairo_native::main(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters