Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
cd target/package
tar xvfz soroban-cli-$VERSION.crate
cd soroban-cli-$VERSION
cargo build --target-dir=../.. --release --target ${{ matrix.target }}
cargo build --target-dir=../.. --features opt --release --target ${{ matrix.target }}
- uses: actions/upload-artifact@v3
with:
name: ${{ env.NAME }}
Expand Down
6 changes: 5 additions & 1 deletion cmd/soroban-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ name = "soroban_cli"
path = "src/lib.rs"
doctest = false

[features]
default = []
opt = ["dep:wasm-opt"]

[dependencies]
soroban-env-host = { workspace = true, features = [
"vm",
Expand Down Expand Up @@ -63,7 +67,7 @@ jsonrpsee-http-client = "0.18.1"
jsonrpsee-core = "0.18.1"
http = "0.2.9"
regex = "1.6.0"
wasm-opt = "0.112.0"
wasm-opt = { version = "0.112.0", optional = true }
chrono = "0.4.23"
rpassword = "7.2.0"
dirs = "4.0.0"
Expand Down
11 changes: 9 additions & 2 deletions cmd/soroban-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ Soroban: https://soroban.stellar.org
cargo install --locked soroban-cli
```

To install with the `opt` feature, which includes a WASM optimization feature and wasm-opt built in:

```
cargo install --locked soroban-cli --features opt
```

## Usage

All values passed to `--arg` are the JSON representation of SCVals.
Can invoke a contract method as a subcommand with different arguments. Anything after the slop (`--`) is passed to the contract's CLI. You can use `--help` to learn about which methods are available and what their arguments are including an example of the type of the input.

## Example

```
soroban invoke --id <HEX_CONTRACTID> --wasm <WASMFILE> -- <FUNCNAME> --<contract fn argument name> <value>
soroban invoke --id <CONTRACT_ID> --wasm <WASMFILE> -- --help
soroban invoke --id <CONTRACT_ID> --network futurenet -- --help
```
11 changes: 11 additions & 0 deletions cmd/soroban-cli/src/commands/contract/optimize.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap::{arg, command, Parser};
use std::fmt::Debug;
#[cfg(feature = "opt")]
use wasm_opt::{OptimizationError, OptimizationOptions};

use crate::wasm;
Expand All @@ -18,11 +19,21 @@ pub struct Cmd {
pub enum Error {
#[error(transparent)]
Wasm(#[from] wasm::Error),
#[cfg(feature = "opt")]
#[error("optimization error: {0}")]
OptimizationError(OptimizationError),
#[cfg(not(feature = "opt"))]
#[error("Must install with \"opt\" feature, e.g. `cargo install soroban-cli --features opt")]
Install,
}

impl Cmd {
#[cfg(not(feature = "opt"))]
pub fn run(&self) -> Result<(), Error> {
Err(Error::Install)
}

#[cfg(feature = "opt")]
pub fn run(&self) -> Result<(), Error> {
let wasm_size = self.wasm.len()?;

Expand Down