Skip to content

Commit

Permalink
add bin attr
Browse files Browse the repository at this point in the history
  • Loading branch information
Defernus committed Sep 29, 2023
1 parent 088a5c7 commit 69d89ad
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub async fn run_checks(cfg: CheckConfig) -> eyre::Result<bool> {
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}"))?,
};
Expand Down
1 change: 1 addition & 0 deletions src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"))?,
};
Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// 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.
Expand Down
22 changes: 20 additions & 2 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct BuildConfig {
pub opt_level: OptLevel,
pub nightly: bool,
pub rebuild: bool,
pub bin: Option<String>,
}

#[derive(thiserror::Error, Debug, PartialEq, Eq, Clone)]
Expand Down Expand Up @@ -82,6 +83,11 @@ pub fn build_project_to_wasm(cfg: BuildConfig) -> eyre::Result<PathBuf> {
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))
Expand All @@ -106,8 +112,18 @@ pub fn build_project_to_wasm(cfg: BuildConfig) -> eyre::Result<PathBuf> {
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
})
Expand All @@ -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 => {
Expand All @@ -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 {
Expand Down

0 comments on commit 69d89ad

Please sign in to comment.