Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
24 changes: 20 additions & 4 deletions FULL_HELP_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,11 @@ To view the commands that will be executed, without executing them, use the --pr
If ommitted, wasm files are written only to the cargo target directory.

- `--locked` — Assert that `Cargo.lock` will remain unchanged
- `--optimize` — Optimize the generated wasm
- `--optimize <OPTIMIZE>` — Optimize the generated wasm. Enabled by default; pass `--optimize=false` to disable

Default value: `true`

Possible values: `true`, `false`

###### **Other:**

Expand Down Expand Up @@ -474,7 +478,11 @@ Deploy a wasm contract
Default value: `false`

- `--alias <ALIAS>` — The alias that will be used to save the contract's id. Whenever used, `--alias` will always overwrite the existing contract id configuration without asking for confirmation
- `--optimize` — Optimize the generated wasm
- `--optimize <OPTIMIZE>` — Optimize the generated wasm. Enabled by default; pass `--optimize=false` to disable

Default value: `true`

Possible values: `true`, `false`

###### **RPC Options:**

Expand Down Expand Up @@ -836,7 +844,11 @@ Install a WASM file to the ledger without creating a contract instance

Default value: `false`

- `--optimize` — Optimize the generated wasm
- `--optimize <OPTIMIZE>` — Optimize the generated wasm. Enabled by default; pass `--optimize=false` to disable

Default value: `true`

Possible values: `true`, `false`

###### **RPC Options:**

Expand Down Expand Up @@ -888,7 +900,11 @@ Install a WASM file to the ledger without creating a contract instance

Default value: `false`

- `--optimize` — Optimize the generated wasm
- `--optimize <OPTIMIZE>` — Optimize the generated wasm. Enabled by default; pass `--optimize=false` to disable

Default value: `true`

Possible values: `true`, `false`

###### **RPC Options:**

Expand Down
32 changes: 24 additions & 8 deletions cmd/soroban-cli/src/commands/contract/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,34 @@ pub struct Cmd {
}

/// Shared build options for meta and optimization, reused by deploy and upload.
#[derive(Parser, Debug, Clone, Default)]
#[derive(Parser, Debug, Clone)]
pub struct BuildArgs {
/// Add key-value to contract meta (adds the meta to the `contractmetav0` custom section)
#[arg(long, num_args=1, value_parser=parse_meta_arg, action=clap::ArgAction::Append, help_heading = "Metadata")]
pub meta: Vec<(String, String)>,

/// Optimize the generated wasm.
#[cfg_attr(feature = "additional-libs", arg(long))]
#[cfg_attr(not(feature = "additional-libs"), arg(long, hide = true))]
/// Optimize the generated wasm. Enabled by default; pass `--optimize=false` to disable.
#[arg(
long,
default_value_t = true,
default_missing_value = "true",
num_args = 0..=1,
Comment thread
fnando marked this conversation as resolved.
action = clap::ArgAction::Set,
)]
pub optimize: bool,
}

// Manual impl so `optimize` defaults to `true`, matching the CLI default.
// `#[derive(Default)]` would set it to `false`.
impl Default for BuildArgs {
fn default() -> Self {
Self {
meta: Vec::new(),
optimize: true,
}
}
}

pub fn parse_meta_arg(s: &str) -> Result<(String, String), Error> {
let parts = s.splitn(2, '=');

Expand Down Expand Up @@ -170,9 +186,6 @@ pub enum Error {
)]
RustVersion(String),

#[error("must install with \"additional-libs\" feature.")]
OptimizeFeatureNotEnabled,

#[error("invalid Cargo.toml configuration: {0}")]
CargoConfiguration(String),

Expand Down Expand Up @@ -330,7 +343,10 @@ impl Cmd {

#[cfg(not(feature = "additional-libs"))]
if self.build_args.optimize {
return Err(Error::OptimizeFeatureNotEnabled);
print.warnln(
"Optimization skipped: stellar-cli was installed without the `additional-libs` feature. \
Reinstall with `--features additional-libs` to enable."
);
}

Self::print_build_summary(
Expand Down
Loading