Skip to content

Commit 73051b7

Browse files
committed
Add Config param to Garaga command functions
The added configuration parameter allows for dry-run mode and runner abstraction in Garaga functions, consistent with other commands.
1 parent 16c34f9 commit 73051b7

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

crates/bargo-core/src/commands/cairo/garaga.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use std::path::{Path, PathBuf};
88

99
use crate::{
1010
backends,
11+
commands::common,
12+
config::Config,
1113
util::{self, Flavour, move_generated_project},
1214
};
1315

@@ -17,6 +19,7 @@ use crate::{
1719
/// that can be used for on-chain proof verification on Starknet.
1820
///
1921
/// # Arguments
22+
/// * `cfg` - Configuration containing runner and flags
2023
/// * `proof_path` - Path to the proof file
2124
/// * `vk_path` - Path to the verification key file
2225
/// * `public_inputs_path` - Path to the public inputs file
@@ -25,6 +28,7 @@ use crate::{
2528
/// # Returns
2629
/// * `Result<PathBuf>` - Path to generated calldata file or error
2730
pub fn generate_calldata(
31+
_cfg: &Config,
2832
proof_path: &Path,
2933
vk_path: &Path,
3034
public_inputs_path: &Path,
@@ -46,6 +50,8 @@ pub fn generate_calldata(
4650
&public_inputs_str,
4751
];
4852

53+
// TODO: Extend runner interface to capture stdout for calldata generation
54+
// For now, fall back to direct backend call
4955
let (stdout, _stderr) = backends::garaga::run_with_output(&garaga_args)?;
5056

5157
// Determine output path
@@ -64,14 +70,17 @@ pub fn generate_calldata(
6470
/// Convenience function that uses the standard Starknet artifact locations
6571
/// to generate calldata JSON.
6672
///
73+
/// # Arguments
74+
/// * `cfg` - Configuration containing runner and flags
75+
///
6776
/// # Returns
6877
/// * `Result<PathBuf>` - Path to generated calldata file or error
69-
pub fn generate_calldata_from_starknet_artifacts() -> Result<PathBuf> {
78+
pub fn generate_calldata_from_starknet_artifacts(cfg: &Config) -> Result<PathBuf> {
7079
let proof_path = util::get_proof_path(Flavour::Starknet);
7180
let vk_path = util::get_vk_path(Flavour::Starknet);
7281
let public_inputs_path = util::get_public_inputs_path(Flavour::Starknet);
7382

74-
generate_calldata(&proof_path, &vk_path, &public_inputs_path, None)
83+
generate_calldata(cfg, &proof_path, &vk_path, &public_inputs_path, None)
7584
}
7685

7786
/// Generate Cairo verifier contract using Garaga
@@ -80,12 +89,17 @@ pub fn generate_calldata_from_starknet_artifacts() -> Result<PathBuf> {
8089
/// on Starknet using the provided verification key.
8190
///
8291
/// # Arguments
92+
/// * `cfg` - Configuration containing runner and flags
8393
/// * `vk_path` - Path to the verification key file
8494
/// * `output_dir` - Optional output directory (defaults to ./contracts/cairo/)
8595
///
8696
/// # Returns
8797
/// * `Result<()>` - Success or error from Garaga execution
88-
pub fn generate_cairo_contract(vk_path: &Path, output_dir: Option<&str>) -> Result<()> {
98+
pub fn generate_cairo_contract(
99+
cfg: &Config,
100+
vk_path: &Path,
101+
output_dir: Option<&str>,
102+
) -> Result<()> {
89103
let output = output_dir.unwrap_or("./contracts/cairo/");
90104

91105
let vk_str = vk_path.to_string_lossy();
@@ -100,22 +114,29 @@ pub fn generate_cairo_contract(vk_path: &Path, output_dir: Option<&str>) -> Resu
100114
"cairo_verifier",
101115
];
102116

103-
backends::garaga::run(&garaga_args)?;
117+
common::run_garaga_command(cfg, &garaga_args)?;
104118

105-
// Move the generated project to the correct location
106-
move_generated_project("cairo_verifier", output)
119+
// Move the generated project to the correct location (skip in dry-run mode)
120+
if cfg.dry_run {
121+
Ok(())
122+
} else {
123+
move_generated_project("cairo_verifier", output)
124+
}
107125
}
108126

109127
/// Generate Cairo verifier contract using default Starknet VK path
110128
///
111129
/// Convenience function that uses the standard Starknet VK location
112130
/// to generate a Cairo verifier contract.
113131
///
132+
/// # Arguments
133+
/// * `cfg` - Configuration containing runner and flags
134+
///
114135
/// # Returns
115136
/// * `Result<()>` - Success or error from Garaga execution
116-
pub fn generate_cairo_contract_from_starknet_vk() -> Result<()> {
137+
pub fn generate_cairo_contract_from_starknet_vk(cfg: &Config) -> Result<()> {
117138
let vk_path = util::get_vk_path(Flavour::Starknet);
118-
generate_cairo_contract(&vk_path, None)
139+
generate_cairo_contract(cfg, &vk_path, None)
119140
}
120141

121142
/// Validate that required Starknet artifacts exist for Garaga operations

crates/bargo-core/src/commands/cairo/workflow.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,8 @@ pub fn run_gen(cfg: &Config) -> Result<()> {
103103
}
104104
let contract_timer = Timer::start();
105105

106-
// TODO: Migrate garaga to runner abstraction in next checkpoint
107-
if cfg.dry_run {
108-
println!(
109-
"Would run: garaga gen --system ultra_starknet_zk_honk --vk ./target/starknet/vk --output ./contracts/cairo/"
110-
);
111-
} else {
112-
garaga::generate_cairo_contract_from_starknet_vk()
113-
.map_err(enhance_error_with_suggestions)?;
114-
}
106+
garaga::generate_cairo_contract_from_starknet_vk(cfg)
107+
.map_err(enhance_error_with_suggestions)?;
115108

116109
if !cfg.quiet {
117110
let cairo_dir = directories::get_cairo_contracts_dir();
@@ -248,7 +241,7 @@ pub fn run_calldata(cfg: &Config) -> Result<()> {
248241
}
249242

250243
let calldata_timer = Timer::start();
251-
let calldata_path = garaga::generate_calldata_from_starknet_artifacts()
244+
let calldata_path = garaga::generate_calldata_from_starknet_artifacts(cfg)
252245
.map_err(enhance_error_with_suggestions)?;
253246

254247
if !cfg.quiet {

0 commit comments

Comments
 (0)