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

[WIP] Add features flag for cargo stylus check/deploy #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -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