Skip to content

Commit d8b1993

Browse files
committed
Add foundry commands to runner abstraction
1 parent 73051b7 commit d8b1993

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

crates/bargo-core/src/commands/evm/foundry.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,43 @@
55
66
use color_eyre::Result;
77

8-
use crate::backends;
8+
use crate::{backends, commands::common, config::Config};
99

1010
/// Initialize a new Foundry project
1111
///
1212
/// This function creates a new Foundry project structure with the necessary
1313
/// configuration files and directories.
1414
///
1515
/// # Arguments
16+
/// * `cfg` - Configuration containing runner and flags
1617
/// * `project_path` - Path where the Foundry project should be created
1718
///
1819
/// # Returns
1920
/// * `Result<()>` - Success or error from Foundry initialization
20-
pub fn init_foundry_project(project_path: &str) -> Result<()> {
21-
backends::foundry::run_forge(&["init", "--force", project_path])
21+
pub fn init_foundry_project(cfg: &Config, project_path: &str) -> Result<()> {
22+
common::run_foundry_command(cfg, "forge", &["init", "--force", project_path])
2223
}
2324

2425
/// Initialize Foundry project at the default EVM contracts location
2526
///
2627
/// Convenience function that initializes a Foundry project at the standard
2728
/// location used by the Bargo workflow.
2829
///
30+
/// # Arguments
31+
/// * `cfg` - Configuration containing runner and flags
32+
///
2933
/// # Returns
3034
/// * `Result<()>` - Success or error from initialization
31-
pub fn init_default_foundry_project() -> Result<()> {
32-
init_foundry_project("contracts/evm")
35+
pub fn init_default_foundry_project(cfg: &Config) -> Result<()> {
36+
init_foundry_project(cfg, "contracts/evm")
3337
}
3438

3539
/// Deploy a contract using Foundry
3640
///
3741
/// This function deploys a contract to an EVM network using forge create.
3842
///
3943
/// # Arguments
44+
/// * `cfg` - Configuration containing runner and flags
4045
/// * `contract_path` - Path to the contract source file
4146
/// * `contract_name` - Name of the contract to deploy
4247
/// * `rpc_url` - RPC URL for the target network
@@ -46,6 +51,7 @@ pub fn init_default_foundry_project() -> Result<()> {
4651
/// # Returns
4752
/// * `Result<String>` - Contract address or error
4853
pub fn deploy_contract(
54+
_cfg: &Config,
4955
contract_path: &str,
5056
_contract_name: &str,
5157
rpc_url: &str,
@@ -66,6 +72,8 @@ pub fn deploy_contract(
6672
args.extend(constructor_args);
6773
}
6874

75+
// TODO: Extend runner interface to capture stdout for contract address parsing
76+
// For now, fall back to direct backend call
6977
let (stdout, _stderr) = backends::foundry::run_forge_with_output(&args)?;
7078

7179
// Parse contract address from forge output
@@ -89,13 +97,15 @@ pub fn deploy_contract(
8997
/// standard EVM contracts directory.
9098
///
9199
/// # Arguments
100+
/// * `cfg` - Configuration containing runner and flags
92101
/// * `rpc_url` - RPC URL for the target network
93102
/// * `private_key` - Private key for deployment
94103
///
95104
/// # Returns
96105
/// * `Result<String>` - Contract address or error
97-
pub fn deploy_verifier_contract(rpc_url: &str, private_key: &str) -> Result<String> {
106+
pub fn deploy_verifier_contract(cfg: &Config, rpc_url: &str, private_key: &str) -> Result<String> {
98107
deploy_contract(
108+
cfg,
99109
"contracts/evm/src/Verifier.sol:Verifier",
100110
"Verifier",
101111
rpc_url,

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,7 @@ pub fn run_gen(cfg: &Config) -> Result<()> {
5656
}
5757
let foundry_timer = Timer::start();
5858

59-
// TODO: Migrate foundry to runner abstraction in next checkpoint
60-
if cfg.dry_run {
61-
println!("Would run: forge init --force contracts/evm");
62-
} else {
63-
foundry::init_default_foundry_project().map_err(enhance_error_with_suggestions)?;
64-
}
59+
foundry::init_default_foundry_project(cfg).map_err(enhance_error_with_suggestions)?;
6560

6661
if !cfg.quiet {
6762
let foundry_dir = directories::get_evm_contracts_dir();
@@ -290,7 +285,7 @@ pub fn run_deploy(cfg: &Config, network: &str) -> Result<()> {
290285
}
291286

292287
let deploy_timer = Timer::start();
293-
let contract_address = foundry::deploy_verifier_contract(&rpc_url, &private_key)
288+
let contract_address = foundry::deploy_verifier_contract(cfg, &rpc_url, &private_key)
294289
.map_err(enhance_error_with_suggestions)?;
295290

296291
// Save contract address for future commands

0 commit comments

Comments
 (0)