Skip to content

Commit c0f11f8

Browse files
committed
Release version 0.2.0
1 parent 4d60568 commit c0f11f8

File tree

18 files changed

+363
-158
lines changed

18 files changed

+363
-158
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,30 @@ jobs:
4545
- name: cargo clippy (deny warnings)
4646
run: cargo clippy --workspace --all-features --locked -- -D warnings
4747

48-
# -- Step 6: Run the test suite
48+
# -- Step 6: Install Foundry for EVM tests
49+
- name: Install Foundry
50+
run: |
51+
curl -L https://foundry.paradigm.xyz | bash
52+
source ~/.bashrc
53+
foundryup
54+
echo "$HOME/.foundry/bin" >> $GITHUB_PATH
55+
56+
# -- Step 7: Install nargo for Noir compilation
57+
- name: Install nargo
58+
run: |
59+
curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
60+
source ~/.bashrc
61+
noirup
62+
echo "$HOME/.nargo/bin" >> $GITHUB_PATH
63+
64+
# -- Step 8: Install bb for proof generation
65+
- name: Install bb
66+
run: |
67+
curl -L https://raw.githubusercontent.com/AztecProtocol/aztec-packages/refs/heads/master/barretenberg/bbup/install | bash
68+
source ~/.bashrc
69+
bbup
70+
echo "$HOME/.bb/bin" >> $GITHUB_PATH
71+
72+
# -- Step 9: Run the test suite
4973
- name: cargo test
5074
run: cargo test --workspace --all-features --locked

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased]
8+
## [v0.2.0]
99

1010
### Added
1111
- Runner abstraction with `CmdSpec`, `Runner` trait, `RealRunner`, and `DryRunRunner` implementations
@@ -68,4 +68,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6868
- Eliminated code duplication across command modules
6969
- Established consistent command execution pattern for all nargo-based commands
7070
- Verified no unsafe blocks remain in codebase
71-
- All acceptance criteria for Phase 3 satisfied
71+
- All acceptance criteria for Phase 3 satisfied

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = [".", "crates/bargo-core"]
33

44
[package]
55
name = "bargo"
6-
version = "0.1.0"
6+
version = "0.2.0"
77
edition = "2024"
88

99
[dependencies]
@@ -17,3 +17,6 @@ predicates = "3"
1717
serde_json = "1.0"
1818
assert_fs = "1.1"
1919
path-slash = "0.2"
20+
21+
[features]
22+
runner-history-tests = []

crates/bargo-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bargo-core"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = "2024"
55

66
[dependencies]
Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
1+
//! Build command implementation
2+
13
use color_eyre::Result;
4+
use std::path::Path;
25

36
use crate::{
4-
commands::common::run_nargo_command,
7+
commands::common::run_nargo_command_in_directory,
58
config::Config,
69
util::{self, Flavour, Timer, format_operation_result, success},
710
};
811

912
/// Determine whether a rebuild is needed based on source timestamps
10-
pub fn should_rebuild(pkg: &str, cfg: &Config) -> Result<bool> {
13+
fn should_rebuild(pkg_name: &str, cfg: &Config) -> Result<bool> {
1114
if cfg.dry_run {
1215
return Ok(true);
1316
}
14-
util::needs_rebuild(pkg)
17+
util::needs_rebuild(pkg_name)
1518
}
1619

1720
/// Execute the build workflow
1821
pub fn run(cfg: &Config) -> Result<()> {
22+
run_in_directory(cfg, None)
23+
}
24+
25+
/// Execute the build workflow in a specific directory
26+
pub fn run_in_directory(cfg: &Config, working_dir: Option<&Path>) -> Result<()> {
1927
if cfg.dry_run {
20-
return run_nargo_command(cfg, &["execute"]);
28+
return run_nargo_command_in_directory(cfg, &["execute"], working_dir);
2129
}
2230

23-
let pkg_name = util::get_package_name(cfg.pkg.as_ref())?;
31+
let pkg_name = match working_dir {
32+
Some(dir) => util::get_package_name_in_directory(cfg.pkg.as_ref(), dir)?,
33+
None => util::get_package_name(cfg.pkg.as_ref())?,
34+
};
2435

2536
if !should_rebuild(&pkg_name, cfg)? {
2637
if !cfg.quiet {
@@ -30,29 +41,32 @@ pub fn run(cfg: &Config) -> Result<()> {
3041
}
3142

3243
let timer = Timer::start();
33-
run_nargo_command(cfg, &["execute"])?;
44+
run_nargo_command_in_directory(cfg, &["execute"], working_dir)?;
45+
46+
match working_dir {
47+
Some(dir) => util::organize_build_artifacts_in_directory(&pkg_name, Flavour::Bb, dir)?,
48+
None => util::organize_build_artifacts(&pkg_name, Flavour::Bb)?,
49+
}
3450

35-
util::organize_build_artifacts(&pkg_name, Flavour::Bb)?;
3651
if !cfg.quiet {
37-
let bytecode_path = util::get_bytecode_path(&pkg_name, Flavour::Bb);
38-
let witness_path = util::get_witness_path(&pkg_name, Flavour::Bb);
52+
let current_dir;
53+
let base_dir = match working_dir {
54+
Some(dir) => dir,
55+
None => {
56+
current_dir = std::env::current_dir()?;
57+
&current_dir
58+
}
59+
};
60+
let bytecode_path = base_dir.join(util::get_bytecode_path(&pkg_name, Flavour::Bb));
3961
println!(
4062
"{}",
4163
success(&format_operation_result(
42-
"Bytecode generated",
64+
"Build completed",
4365
&bytecode_path,
4466
&timer
4567
))
4668
);
47-
let witness_timer = Timer::start();
48-
println!(
49-
"{}",
50-
success(&format_operation_result(
51-
"Witness generated",
52-
&witness_path,
53-
&witness_timer
54-
))
55-
);
5669
}
70+
5771
Ok(())
5872
}

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ pub(crate) fn internal_declare(cfg: &Config, network: &str) -> Result<()> {
282282
load_env_vars();
283283

284284
if cfg.dry_run {
285-
println!("Would declare contract on network: {}", network);
285+
println!("Would declare contract on network: {network}");
286286
return Ok(());
287287
}
288288

@@ -304,7 +304,7 @@ pub(crate) fn internal_declare(cfg: &Config, network: &str) -> Result<()> {
304304
// Implementation would depend on Starknet CLI integration
305305
// This is a placeholder for the actual declare logic
306306
println!("🚧 Contract declaration functionality coming soon");
307-
println!("Network: {}", network);
307+
println!("Network: {network}");
308308
println!("Contract directory: {}", cairo_dir.display());
309309

310310
Ok(())
@@ -326,7 +326,7 @@ pub fn run_deploy(cfg: &Config, class_hash: Option<&str>) -> Result<()> {
326326
Some(hash) => hash.to_string(),
327327
None => "<class_hash_from_declare>".to_string(), // Placeholder for dry-run
328328
};
329-
println!("Would deploy contract with class hash: {}", hash);
329+
println!("Would deploy contract with class hash: {hash}");
330330
return Ok(());
331331
}
332332

@@ -358,7 +358,7 @@ pub fn run_deploy(cfg: &Config, class_hash: Option<&str>) -> Result<()> {
358358
// Implementation would depend on Starknet CLI integration
359359
// This is a placeholder for the actual deploy logic
360360
println!("🚧 Contract deployment functionality coming soon");
361-
println!("Class hash: {}", hash);
361+
println!("Class hash: {hash}");
362362

363363
Ok(())
364364
}
@@ -408,10 +408,7 @@ pub fn run_verify_onchain(cfg: &Config, address: Option<&str>) -> Result<()> {
408408
}
409409

410410
if cfg.dry_run {
411-
println!(
412-
"Would verify proof on-chain at address: {}",
413-
contract_address
414-
);
411+
println!("Would verify proof on-chain at address: {contract_address}");
415412
return Ok(());
416413
}
417414

@@ -422,7 +419,7 @@ pub fn run_verify_onchain(cfg: &Config, address: Option<&str>) -> Result<()> {
422419
// Implementation would depend on Starknet CLI integration
423420
// This is a placeholder for the actual on-chain verification logic
424421
println!("🚧 On-chain verification functionality coming soon");
425-
println!("Contract address: {}", contract_address);
422+
println!("Contract address: {contract_address}");
426423
println!("Calldata: {}", calldata_path.display());
427424

428425
Ok(())

crates/bargo-core/src/commands/common.rs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use color_eyre::Result;
2+
use std::path::Path;
23
use tracing::info;
34

45
use crate::{config::Config, runner::CmdSpec};
@@ -66,6 +67,78 @@ pub fn run_nargo_command(cfg: &Config, base_args: &[&str]) -> Result<()> {
6667
cfg.runner.run(&spec)
6768
}
6869

70+
/// Run a nargo command in a specific working directory
71+
///
72+
/// This is similar to `run_nargo_command` but allows specifying a working directory
73+
/// for the command execution. If `working_dir` is None, behaves like `run_nargo_command`.
74+
///
75+
/// # Arguments
76+
/// * `cfg` - The global configuration containing all flags
77+
/// * `base_args` - Base command arguments to pass to nargo
78+
/// * `working_dir` - Optional working directory for command execution
79+
///
80+
/// # Returns
81+
/// * `Result<()>` - Success or error from command execution
82+
pub fn run_nargo_command_in_directory(
83+
cfg: &Config,
84+
base_args: &[&str],
85+
working_dir: Option<&Path>,
86+
) -> Result<()> {
87+
let args = build_nargo_args(cfg, base_args)?;
88+
89+
if cfg.verbose && !cfg.quiet {
90+
info!("Running: nargo {}", args.join(" "));
91+
}
92+
93+
// Create command specification for nargo
94+
let mut spec = CmdSpec::new("nargo".to_string(), args);
95+
96+
// Set working directory if provided
97+
if let Some(dir) = working_dir {
98+
spec = spec.with_cwd(dir.to_path_buf());
99+
}
100+
101+
// Use the runner to execute the command (handles dry-run automatically)
102+
cfg.runner.run(&spec)
103+
}
104+
105+
/// Run any external tool in a specific working directory
106+
///
107+
/// This is similar to `run_tool` but allows specifying a working directory
108+
/// for the command execution. If `working_dir` is None, behaves like `run_tool`.
109+
///
110+
/// # Arguments
111+
/// * `cfg` - The global configuration containing all flags and runner
112+
/// * `tool` - The tool command to run (bb, garaga, forge, cast, nargo, etc.)
113+
/// * `args` - Arguments to pass to the tool
114+
/// * `working_dir` - Optional working directory for command execution
115+
///
116+
/// # Returns
117+
/// * `Result<()>` - Success or error from command execution
118+
pub fn run_tool_in_directory(
119+
cfg: &Config,
120+
tool: &str,
121+
args: &[&str],
122+
working_dir: Option<&Path>,
123+
) -> Result<()> {
124+
let args_vec: Vec<String> = args.iter().map(|s| s.to_string()).collect();
125+
126+
if cfg.verbose && !cfg.quiet {
127+
info!("Running: {} {}", tool, args_vec.join(" "));
128+
}
129+
130+
// Create command specification for the tool
131+
let mut spec = CmdSpec::new(tool.to_string(), args_vec);
132+
133+
// Set working directory if provided
134+
if let Some(dir) = working_dir {
135+
spec = spec.with_cwd(dir.to_path_buf());
136+
}
137+
138+
// Use the runner to execute the command (handles dry-run automatically)
139+
cfg.runner.run(&spec)
140+
}
141+
69142
/// Run any external tool with unified command execution
70143
///
71144
/// This is the unified helper for executing external tools consistently across all
@@ -139,3 +212,44 @@ pub fn run_tool_capture(cfg: &Config, tool: &str, args: &[&str]) -> Result<Strin
139212
// Use the runner to execute the command and capture output
140213
cfg.runner.run_capture(&spec)
141214
}
215+
216+
/// Run any external tool in a specific working directory and capture its stdout
217+
///
218+
/// This is similar to `run_tool_capture` but allows specifying a working directory
219+
/// for the command execution. If `working_dir` is None, behaves like `run_tool_capture`.
220+
///
221+
/// # Arguments
222+
/// * `cfg` - The global configuration containing all flags and runner
223+
/// * `tool` - The tool command to run (bb, garaga, forge, cast, nargo, etc.)
224+
/// * `args` - Arguments to pass to the tool
225+
/// * `working_dir` - Optional working directory for command execution
226+
///
227+
/// # Returns
228+
/// * `Result<String>` - Stdout from command execution or error
229+
pub fn run_tool_capture_in_directory(
230+
cfg: &Config,
231+
tool: &str,
232+
args: &[&str],
233+
working_dir: Option<&Path>,
234+
) -> Result<String> {
235+
let args_vec: Vec<String> = args.iter().map(|s| s.to_string()).collect();
236+
237+
if cfg.verbose && !cfg.quiet {
238+
info!(
239+
"Running (capturing output): {} {}",
240+
tool,
241+
args_vec.join(" ")
242+
);
243+
}
244+
245+
// Create command specification for the tool
246+
let mut spec = CmdSpec::new(tool.to_string(), args_vec);
247+
248+
// Set working directory if provided
249+
if let Some(dir) = working_dir {
250+
spec = spec.with_cwd(dir.to_path_buf());
251+
}
252+
253+
// Use the runner to execute the command and capture output
254+
cfg.runner.run_capture(&spec)
255+
}

0 commit comments

Comments
 (0)