From dac20ff2bb9370175ce4f962de5db5711c683cb2 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Tue, 30 May 2023 12:45:27 -0400 Subject: [PATCH 1/6] feat!(CLI): make `contract optimize` optional --- cmd/crates/soroban-test/tests/it/invoke_sandbox.rs | 4 ++-- cmd/soroban-cli/Cargo.toml | 6 +++++- cmd/soroban-cli/src/commands/contract/optimize.rs | 8 ++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/crates/soroban-test/tests/it/invoke_sandbox.rs b/cmd/crates/soroban-test/tests/it/invoke_sandbox.rs index 99b520334a..038182fcbf 100644 --- a/cmd/crates/soroban-test/tests/it/invoke_sandbox.rs +++ b/cmd/crates/soroban-test/tests/it/invoke_sandbox.rs @@ -27,7 +27,7 @@ fn install_wasm_then_deploy_contract() { .arg("--id=1") .assert() .success() - .stdout("0000000000000000000000000000000000000000000000000000000000000001\n"); + .stdout("CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM\n"); } #[test] @@ -40,7 +40,7 @@ fn deploy_contract_with_wasm_file() { .arg("--id=1") .assert() .success() - .stdout("0000000000000000000000000000000000000000000000000000000000000001\n"); + .stdout("CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM\n"); } #[test] diff --git a/cmd/soroban-cli/Cargo.toml b/cmd/soroban-cli/Cargo.toml index f7d1e2f087..f5d86ac282 100644 --- a/cmd/soroban-cli/Cargo.toml +++ b/cmd/soroban-cli/Cargo.toml @@ -26,6 +26,10 @@ name = "soroban_cli" path = "src/lib.rs" doctest = false +[features] +default = [] +opt = ["wasm-opt"] + [dependencies] soroban-env-host = { workspace = true, features = [ "vm", @@ -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" diff --git a/cmd/soroban-cli/src/commands/contract/optimize.rs b/cmd/soroban-cli/src/commands/contract/optimize.rs index 9bbcedc7c9..25266db249 100644 --- a/cmd/soroban-cli/src/commands/contract/optimize.rs +++ b/cmd/soroban-cli/src/commands/contract/optimize.rs @@ -1,5 +1,6 @@ use clap::{arg, command, Parser}; use std::fmt::Debug; +#[cfg(feature = "opt")] use wasm_opt::{OptimizationError, OptimizationOptions}; use crate::wasm; @@ -18,11 +19,18 @@ pub struct Cmd { pub enum Error { #[error(transparent)] Wasm(#[from] wasm::Error), + #[cfg(feature = "opt")] #[error("optimization error: {0}")] OptimizationError(OptimizationError), } impl Cmd { + #[cfg(not(feature = "opt"))] + pub fn run(&self) -> Result<(), Error> { + todo!("Must install with \"opt\" feature"); + } + + #[cfg(feature = "opt")] pub fn run(&self) -> Result<(), Error> { let wasm_size = self.wasm.len()?; From fa07c00b726c30b25144627248f49c4d7236f10d Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Thu, 1 Jun 2023 09:59:39 -0400 Subject: [PATCH 2/6] fix: use proper error --- cmd/crates/soroban-test/tests/it/invoke_sandbox.rs | 4 ++-- cmd/soroban-cli/src/commands/contract/optimize.rs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/crates/soroban-test/tests/it/invoke_sandbox.rs b/cmd/crates/soroban-test/tests/it/invoke_sandbox.rs index 038182fcbf..99b520334a 100644 --- a/cmd/crates/soroban-test/tests/it/invoke_sandbox.rs +++ b/cmd/crates/soroban-test/tests/it/invoke_sandbox.rs @@ -27,7 +27,7 @@ fn install_wasm_then_deploy_contract() { .arg("--id=1") .assert() .success() - .stdout("CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM\n"); + .stdout("0000000000000000000000000000000000000000000000000000000000000001\n"); } #[test] @@ -40,7 +40,7 @@ fn deploy_contract_with_wasm_file() { .arg("--id=1") .assert() .success() - .stdout("CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM\n"); + .stdout("0000000000000000000000000000000000000000000000000000000000000001\n"); } #[test] diff --git a/cmd/soroban-cli/src/commands/contract/optimize.rs b/cmd/soroban-cli/src/commands/contract/optimize.rs index 25266db249..50c89ef992 100644 --- a/cmd/soroban-cli/src/commands/contract/optimize.rs +++ b/cmd/soroban-cli/src/commands/contract/optimize.rs @@ -22,12 +22,15 @@ pub enum 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> { - todo!("Must install with \"opt\" feature"); + Err(Error::Install) } #[cfg(feature = "opt")] From 5a4e5a4b7280f73444882dddbafe08b641ea711f Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Thu, 1 Jun 2023 12:55:30 -0700 Subject: [PATCH 3/6] add opt to cli features when building for release --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c70379e23a..fe30e7e4a0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 }} From 71294a6fc6d8d2e5fdb249dc5f3404b16dfd7b15 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Thu, 1 Jun 2023 12:58:49 -0700 Subject: [PATCH 4/6] dep:wasm-opt --- cmd/soroban-cli/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/soroban-cli/Cargo.toml b/cmd/soroban-cli/Cargo.toml index f5d86ac282..585eb745df 100644 --- a/cmd/soroban-cli/Cargo.toml +++ b/cmd/soroban-cli/Cargo.toml @@ -28,7 +28,7 @@ doctest = false [features] default = [] -opt = ["wasm-opt"] +opt = ["dep:wasm-opt"] [dependencies] soroban-env-host = { workspace = true, features = [ From 60ccc25b01c1e462b85afbd4478f0a30f79af66a Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Thu, 1 Jun 2023 13:01:18 -0700 Subject: [PATCH 5/6] add note to readme --- cmd/soroban-cli/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/soroban-cli/README.md b/cmd/soroban-cli/README.md index 051494f83c..0a02c048a1 100644 --- a/cmd/soroban-cli/README.md +++ b/cmd/soroban-cli/README.md @@ -10,6 +10,12 @@ 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. From 035940f9a56cfda0ddaf7536919ba763b710bc2b Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 7 Jun 2023 11:58:52 -0400 Subject: [PATCH 6/6] chore: update readme --- cmd/soroban-cli/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/soroban-cli/README.md b/cmd/soroban-cli/README.md index 0a02c048a1..d17261b18d 100644 --- a/cmd/soroban-cli/README.md +++ b/cmd/soroban-cli/README.md @@ -18,10 +18,11 @@ 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 --wasm -- -- +soroban invoke --id --wasm -- --help +soroban invoke --id --network futurenet -- --help ```