From 69d89adedf82e5b361cc1b05b973157d64387116 Mon Sep 17 00:00:00 2001 From: Denis Lavrentev Date: Fri, 29 Sep 2023 06:38:47 -0400 Subject: [PATCH 1/2] add bin attr --- src/check.rs | 1 + src/deploy.rs | 1 + src/main.rs | 5 +++++ src/project.rs | 22 ++++++++++++++++++++-- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/check.rs b/src/check.rs index 649463d..ad5dfcc 100644 --- a/src/check.rs +++ b/src/check.rs @@ -67,6 +67,7 @@ pub async fn run_checks(cfg: CheckConfig) -> eyre::Result { opt_level: project::OptLevel::default(), nightly: cfg.nightly, rebuild: true, + bin: cfg.bin.clone(), }) .map_err(|e| eyre!("failed to build project to WASM: {e}"))?, }; diff --git a/src/deploy.rs b/src/deploy.rs index 486afd9..8906149 100644 --- a/src/deploy.rs +++ b/src/deploy.rs @@ -117,6 +117,7 @@ programs to Stylus chains here https://docs.arbitrum.io/stylus/stylus-quickstart opt_level: project::OptLevel::default(), nightly: cfg.check_cfg.nightly, rebuild: false, // The check step at the start of this command rebuilt. + bin: cfg.check_cfg.bin, }) .map_err(|e| eyre!("could not build project to WASM: {e}"))?, }; diff --git a/src/main.rs b/src/main.rs index 5a70a12..fbc79fb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,6 +90,11 @@ pub struct CheckConfig { /// to the current Stylus testnet RPC endpoint. #[arg(short, long, default_value = "https://stylus-testnet.arbitrum.io/rpc")] endpoint: String, + /// Build only the specified binary (See cargo's `--bin` attribute + /// https://doc.rust-lang.org/cargo/commands/cargo-build.html#target-selection) + /// Useful for projects with workspaces that have multiple contracts. + #[arg(long)] + bin: Option, /// If desired, it loads a WASM file from a specified path. If not provided, it will try to find /// a WASM file under the current working directory's Rust target release directory and use its /// contents for the deploy command. diff --git a/src/project.rs b/src/project.rs index 689e28c..5175b29 100644 --- a/src/project.rs +++ b/src/project.rs @@ -26,6 +26,7 @@ pub struct BuildConfig { pub opt_level: OptLevel, pub nightly: bool, pub rebuild: bool, + pub bin: Option, } #[derive(thiserror::Error, Debug, PartialEq, Eq, Clone)] @@ -82,6 +83,11 @@ pub fn build_project_to_wasm(cfg: BuildConfig) -> eyre::Result { cmd.arg("profile.release.opt-level='z'"); } + if let Some(bin) = &cfg.bin { + cmd.arg("--bin"); + cmd.arg(bin); + } + let output = cmd .arg("--release") .arg(format!("--target={}", RUST_TARGET)) @@ -106,8 +112,18 @@ pub fn build_project_to_wasm(cfg: BuildConfig) -> eyre::Result { let wasm_file_path = release_files .into_iter() .find(|p| { - if let Some(ext) = p.file_name() { - return ext.to_str().unwrap_or_default().contains(".wasm"); + if let Some(file_name) = p.file_name() { + let file_name = file_name.to_str().unwrap_or_default(); + + if !file_name.contains(".wasm") { + return false; + } + + if let Some(bin) = &cfg.bin { + return file_name.contains(bin); + } + + return true; } false }) @@ -129,6 +145,7 @@ https://github.com/OffchainLabs/cargo-stylus/blob/main/OPTIMIZING_BINARIES.md"#, opt_level: OptLevel::Z, nightly: cfg.nightly, rebuild: true, + bin: cfg.bin, }); } OptLevel::Z => { @@ -146,6 +163,7 @@ https://github.com/OffchainLabs/cargo-stylus/blob/main/OPTIMIZING_BINARIES.md"#, opt_level: OptLevel::Z, nightly: true, rebuild: true, + bin: cfg.bin, }); } return Err(BuildError::ExceedsMaxDespiteBestEffort { From c132786b9ca2bad5d44e7e8e1279040aea03fd06 Mon Sep 17 00:00:00 2001 From: Denis Lavrentev Date: Fri, 29 Sep 2023 06:42:21 -0400 Subject: [PATCH 2/2] fix docs comment --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index fbc79fb..47e76f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -91,7 +91,7 @@ pub struct CheckConfig { #[arg(short, long, default_value = "https://stylus-testnet.arbitrum.io/rpc")] endpoint: String, /// Build only the specified binary (See cargo's `--bin` attribute - /// https://doc.rust-lang.org/cargo/commands/cargo-build.html#target-selection) + /// https://doc.rust-lang.org/cargo/commands/cargo-build.html#target-selection). /// Useful for projects with workspaces that have multiple contracts. #[arg(long)] bin: Option,