Skip to content

Commit

Permalink
Add features flag for cargo stylus check/deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
cygaar committed Apr 15, 2024
1 parent a2ac0dd commit 306a6d3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub async fn run_checks(cfg: CheckConfig) -> eyre::Result<bool> {
Some(path) => PathBuf::from_str(path).unwrap(),
None => project::build_project_dylib(BuildConfig {
opt_level: project::OptLevel::default(),
features: cfg.features.clone(),
nightly: cfg.nightly,
rebuild: true,
skip_contract_size_check: cfg.skip_contract_size_check,
Expand Down
1 change: 1 addition & 0 deletions src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ programs to Stylus chains here https://docs.arbitrum.io/stylus/stylus-quickstart
Some(path) => PathBuf::from_str(path).unwrap(),
None => project::build_project_dylib(BuildConfig {
opt_level: project::OptLevel::default(),
features: cfg.check_cfg.features,
nightly: cfg.check_cfg.nightly,
rebuild: false, // The check step at the start of this command rebuilt.
skip_contract_size_check: cfg.check_cfg.skip_contract_size_check,
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ pub struct CheckConfig {
/// Specifies a WASM file instead of looking for one in the current directory.
#[arg(long)]
wasm_file_path: Option<String>,
/// Specifies the features to use when building the Stylus binary.
#[arg(long)]
features: Option<String>,
/// Specify the program address we want to check activation for. If unspecified, it will
/// compute the next program address from the user's wallet address and nonce, which will require
/// wallet-related flags to be specified.
Expand Down
7 changes: 7 additions & 0 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum OptLevel {

pub struct BuildConfig {
pub opt_level: OptLevel,
pub features: Option<String>,
pub nightly: bool,
pub rebuild: bool,
pub skip_contract_size_check: bool,
Expand Down Expand Up @@ -65,6 +66,10 @@ pub fn build_project_dylib(cfg: BuildConfig) -> Result<PathBuf> {
cmd.arg("build");
cmd.arg("--lib");

if cfg.features != None {
cmd.arg(format!("--features={}", cfg.features.clone().unwrap()));
}

if cfg.nightly {
cmd.arg("-Z");
cmd.arg("build-std=std,panic_abort");
Expand Down Expand Up @@ -126,6 +131,7 @@ https://github.com/OffchainLabs/cargo-stylus/blob/main/OPTIMIZING_BINARIES.md"#,
// Attempt to build again with a bumped-up optimization level.
return build_project_dylib(BuildConfig {
opt_level: OptLevel::Z,
features: cfg.features,
nightly: cfg.nightly,
rebuild: true,
skip_contract_size_check: cfg.skip_contract_size_check,
Expand All @@ -141,6 +147,7 @@ https://github.com/OffchainLabs/cargo-stylus/blob/main/OPTIMIZING_BINARIES.md"#,
// only available with nightly compilation.
return build_project_dylib(BuildConfig {
opt_level: OptLevel::Z,
features: cfg.features,
nightly: true,
rebuild: true,
skip_contract_size_check: cfg.skip_contract_size_check,
Expand Down

0 comments on commit 306a6d3

Please sign in to comment.