Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add bin attr #17

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading