Skip to content

Commit

Permalink
Merge pull request #17 from Defernus/feat/add-bin-attr
Browse files Browse the repository at this point in the history
Feat/add bin attr
  • Loading branch information
rauljordan authored Oct 2, 2023
2 parents ae43fa8 + c132786 commit 0049f53
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 @@ -23,6 +23,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 @@ -79,6 +80,11 @@ pub fn build_project_dylib(cfg: BuildConfig) -> 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 Down Expand Up @@ -107,8 +113,18 @@ pub fn build_project_dylib(cfg: BuildConfig) -> 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 @@ -130,6 +146,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 @@ -147,6 +164,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 0049f53

Please sign in to comment.