diff --git a/Cargo.lock b/Cargo.lock index 28d35be94d..7311f32aad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1748,7 +1748,7 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] name = "doc-gen" -version = "28.1.0" +version = "30.0.0" dependencies = [ "clap-markdown", "soroban-cli", @@ -5251,7 +5251,7 @@ dependencies = [ [[package]] name = "soroban-cli" -version = "28.1.0" +version = "30.0.0" dependencies = [ "assert_fs", "async-compression", @@ -5408,12 +5408,12 @@ dependencies = [ [[package]] name = "soroban-hello" -version = "28.1.0" +version = "30.0.0" [[package]] name = "soroban-ledger-snapshot" -version = "28.0.0" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=bdb9dad832e66effa900e0a32685c36d332f6a40#bdb9dad832e66effa900e0a32685c36d332f6a40" +version = "30.0.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=a7081319bfa59a7da7352510dfa9e05734510be4#a7081319bfa59a7da7352510dfa9e05734510be4" dependencies = [ "serde", "serde_json", @@ -5425,8 +5425,8 @@ dependencies = [ [[package]] name = "soroban-meta" -version = "28.0.0" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=bdb9dad832e66effa900e0a32685c36d332f6a40#bdb9dad832e66effa900e0a32685c36d332f6a40" +version = "30.0.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=a7081319bfa59a7da7352510dfa9e05734510be4#a7081319bfa59a7da7352510dfa9e05734510be4" dependencies = [ "stellar-xdr", "thiserror 1.0.69", @@ -5435,8 +5435,8 @@ dependencies = [ [[package]] name = "soroban-sdk" -version = "28.0.0" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=bdb9dad832e66effa900e0a32685c36d332f6a40#bdb9dad832e66effa900e0a32685c36d332f6a40" +version = "30.0.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=a7081319bfa59a7da7352510dfa9e05734510be4#a7081319bfa59a7da7352510dfa9e05734510be4" dependencies = [ "arbitrary", "bytes-lit", @@ -5461,8 +5461,8 @@ dependencies = [ [[package]] name = "soroban-sdk-macros" -version = "28.0.0" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=bdb9dad832e66effa900e0a32685c36d332f6a40#bdb9dad832e66effa900e0a32685c36d332f6a40" +version = "30.0.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=a7081319bfa59a7da7352510dfa9e05734510be4#a7081319bfa59a7da7352510dfa9e05734510be4" dependencies = [ "darling 0.20.11", "heck 0.5.0", @@ -5480,8 +5480,8 @@ dependencies = [ [[package]] name = "soroban-spec" -version = "28.0.0" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=bdb9dad832e66effa900e0a32685c36d332f6a40#bdb9dad832e66effa900e0a32685c36d332f6a40" +version = "30.0.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=a7081319bfa59a7da7352510dfa9e05734510be4#a7081319bfa59a7da7352510dfa9e05734510be4" dependencies = [ "base64 0.22.1", "stellar-xdr", @@ -5491,8 +5491,8 @@ dependencies = [ [[package]] name = "soroban-spec-rust" -version = "28.0.0" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=bdb9dad832e66effa900e0a32685c36d332f6a40#bdb9dad832e66effa900e0a32685c36d332f6a40" +version = "30.0.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=a7081319bfa59a7da7352510dfa9e05734510be4#a7081319bfa59a7da7352510dfa9e05734510be4" dependencies = [ "prettyplease", "proc-macro2", @@ -5507,7 +5507,7 @@ dependencies = [ [[package]] name = "soroban-spec-tools" -version = "28.1.0" +version = "30.0.0" dependencies = [ "base64 0.21.7", "escape-bytes", @@ -5527,7 +5527,7 @@ dependencies = [ [[package]] name = "soroban-spec-typescript" -version = "28.1.0" +version = "30.0.0" dependencies = [ "heck 0.4.1", "include_dir", @@ -5545,7 +5545,7 @@ dependencies = [ [[package]] name = "soroban-test" -version = "28.1.0" +version = "30.0.0" dependencies = [ "assert_cmd", "assert_fs", @@ -5583,16 +5583,16 @@ dependencies = [ [[package]] name = "soroban-token-sdk" -version = "28.0.0" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=bdb9dad832e66effa900e0a32685c36d332f6a40#bdb9dad832e66effa900e0a32685c36d332f6a40" +version = "30.0.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=a7081319bfa59a7da7352510dfa9e05734510be4#a7081319bfa59a7da7352510dfa9e05734510be4" dependencies = [ "soroban-sdk", ] [[package]] name = "soroban-token-spec" -version = "28.0.0" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=bdb9dad832e66effa900e0a32685c36d332f6a40#bdb9dad832e66effa900e0a32685c36d332f6a40" +version = "30.0.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=a7081319bfa59a7da7352510dfa9e05734510be4#a7081319bfa59a7da7352510dfa9e05734510be4" dependencies = [ "soroban-sdk", "soroban-token-sdk", @@ -5640,8 +5640,8 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "stellar-asset-spec" -version = "28.0.0" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=bdb9dad832e66effa900e0a32685c36d332f6a40#bdb9dad832e66effa900e0a32685c36d332f6a40" +version = "30.0.0" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=a7081319bfa59a7da7352510dfa9e05734510be4#a7081319bfa59a7da7352510dfa9e05734510be4" dependencies = [ "soroban-sdk", "soroban-token-spec", @@ -5649,18 +5649,18 @@ dependencies = [ [[package]] name = "stellar-bye" -version = "28.1.0" +version = "30.0.0" [[package]] name = "stellar-cli" -version = "28.1.0" +version = "30.0.0" dependencies = [ "soroban-cli", ] [[package]] name = "stellar-ledger" -version = "28.1.0" +version = "30.0.0" dependencies = [ "async-trait", "hex", @@ -5997,56 +5997,56 @@ dependencies = [ [[package]] name = "test_auth" -version = "28.1.0" +version = "30.0.0" dependencies = [ "soroban-sdk", ] [[package]] name = "test_constructor" -version = "28.1.0" +version = "30.0.0" dependencies = [ "soroban-sdk", ] [[package]] name = "test_custom_account" -version = "28.1.0" +version = "30.0.0" dependencies = [ "soroban-sdk", ] [[package]] name = "test_custom_types" -version = "28.1.0" +version = "30.0.0" dependencies = [ "soroban-sdk", ] [[package]] name = "test_empty_constructor" -version = "28.1.0" +version = "30.0.0" dependencies = [ "soroban-sdk", ] [[package]] name = "test_hello_world" -version = "28.1.0" +version = "30.0.0" dependencies = [ "soroban-sdk", ] [[package]] name = "test_swap" -version = "28.1.0" +version = "30.0.0" dependencies = [ "soroban-sdk", ] [[package]] name = "test_token" -version = "28.1.0" +version = "30.0.0" dependencies = [ "soroban-sdk", "soroban-token-sdk", @@ -6054,14 +6054,14 @@ dependencies = [ [[package]] name = "test_token_renamed" -version = "28.1.0" +version = "30.0.0" dependencies = [ "soroban-sdk", ] [[package]] name = "test_udt" -version = "28.1.0" +version = "30.0.0" dependencies = [ "soroban-sdk", ] diff --git a/Cargo.toml b/Cargo.toml index 0f9b3d46e8..5845c2a1f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,25 +21,25 @@ exclude = [ ] [workspace.package] -version = "28.1.0" +version = "30.0.0" rust-version = "1.93.0" # Dependencies located in this repo: [workspace.dependencies.soroban-cli] -version = "=28.1.0" +version = "=30.0.0" path = "cmd/soroban-cli" default-features = false [workspace.dependencies.soroban-spec-typescript] -version = "28.1.0" +version = "30.0.0" path = "./cmd/crates/soroban-spec-typescript" [workspace.dependencies.soroban-spec-tools] -version = "28.1.0" +version = "30.0.0" path = "./cmd/crates/soroban-spec-tools" [workspace.dependencies.stellar-ledger] -version = "=28.1.0" +version = "=30.0.0" path = "cmd/crates/stellar-ledger" # Dependencies from the rs-stellar-xdr repo: @@ -51,37 +51,37 @@ version = "28.0.0" version = "28.0.2" # Dependencies from the rs-soroban-sdk repo, pinned to -# https://github.com/stellar/rs-soroban-sdk/pull/1970, which names user-defined -# types in contract specs by their fully qualified path: +# https://github.com/stellar/rs-soroban-sdk/pull/2043, which shakes specs by +# following the references to each type by name: [workspace.dependencies.soroban-spec] -version = "28.0.0" +version = "30.0.0" git = "https://github.com/stellar/rs-soroban-sdk" -rev = "bdb9dad832e66effa900e0a32685c36d332f6a40" +rev = "a7081319bfa59a7da7352510dfa9e05734510be4" [workspace.dependencies.soroban-spec-rust] -version = "28.0.0" +version = "30.0.0" git = "https://github.com/stellar/rs-soroban-sdk" -rev = "bdb9dad832e66effa900e0a32685c36d332f6a40" +rev = "a7081319bfa59a7da7352510dfa9e05734510be4" [workspace.dependencies.soroban-sdk] -version = "28.0.0" +version = "30.0.0" git = "https://github.com/stellar/rs-soroban-sdk" -rev = "bdb9dad832e66effa900e0a32685c36d332f6a40" +rev = "a7081319bfa59a7da7352510dfa9e05734510be4" [workspace.dependencies.soroban-token-sdk] -version = "28.0.0" +version = "30.0.0" git = "https://github.com/stellar/rs-soroban-sdk" -rev = "bdb9dad832e66effa900e0a32685c36d332f6a40" +rev = "a7081319bfa59a7da7352510dfa9e05734510be4" [workspace.dependencies.stellar-asset-spec] -version = "28.0.0" +version = "30.0.0" git = "https://github.com/stellar/rs-soroban-sdk" -rev = "bdb9dad832e66effa900e0a32685c36d332f6a40" +rev = "a7081319bfa59a7da7352510dfa9e05734510be4" [workspace.dependencies.soroban-ledger-snapshot] -version = "28.0.0" +version = "30.0.0" git = "https://github.com/stellar/rs-soroban-sdk" -rev = "bdb9dad832e66effa900e0a32685c36d332f6a40" +rev = "a7081319bfa59a7da7352510dfa9e05734510be4" # Dependencies from the rs-stellar-rpc-client repo: [workspace.dependencies.soroban-rpc] diff --git a/cmd/crates/soroban-test/tests/fixtures/bye/Cargo.toml b/cmd/crates/soroban-test/tests/fixtures/bye/Cargo.toml index 2fb527a0e7..1d6a5da00a 100644 --- a/cmd/crates/soroban-test/tests/fixtures/bye/Cargo.toml +++ b/cmd/crates/soroban-test/tests/fixtures/bye/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stellar-bye" -version = "28.1.0" +version = "30.0.0" edition = "2021" publish = false diff --git a/cmd/crates/soroban-test/tests/fixtures/hello/Cargo.toml b/cmd/crates/soroban-test/tests/fixtures/hello/Cargo.toml index 47c736ce1d..a13a870f9b 100644 --- a/cmd/crates/soroban-test/tests/fixtures/hello/Cargo.toml +++ b/cmd/crates/soroban-test/tests/fixtures/hello/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "soroban-hello" -version = "28.1.0" +version = "30.0.0" edition = "2021" publish = false diff --git a/cmd/crates/soroban-test/tests/fixtures/test-wasms/auth/Cargo.toml b/cmd/crates/soroban-test/tests/fixtures/test-wasms/auth/Cargo.toml index c1525d84d2..294918b421 100644 --- a/cmd/crates/soroban-test/tests/fixtures/test-wasms/auth/Cargo.toml +++ b/cmd/crates/soroban-test/tests/fixtures/test-wasms/auth/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test_auth" -version = "28.1.0" +version = "30.0.0" authors = ["Stellar Development Foundation "] license = "Apache-2.0" edition = "2021" diff --git a/cmd/crates/soroban-test/tests/fixtures/test-wasms/constructor/Cargo.toml b/cmd/crates/soroban-test/tests/fixtures/test-wasms/constructor/Cargo.toml index 1a62fe4797..2e5b111529 100644 --- a/cmd/crates/soroban-test/tests/fixtures/test-wasms/constructor/Cargo.toml +++ b/cmd/crates/soroban-test/tests/fixtures/test-wasms/constructor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test_constructor" -version = "28.1.0" +version = "30.0.0" authors = ["Stellar Development Foundation "] license = "Apache-2.0" edition = "2021" diff --git a/cmd/crates/soroban-test/tests/fixtures/test-wasms/custom_account/Cargo.toml b/cmd/crates/soroban-test/tests/fixtures/test-wasms/custom_account/Cargo.toml index 7ca0cffdae..6421fbb081 100644 --- a/cmd/crates/soroban-test/tests/fixtures/test-wasms/custom_account/Cargo.toml +++ b/cmd/crates/soroban-test/tests/fixtures/test-wasms/custom_account/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test_custom_account" -version = "28.1.0" +version = "30.0.0" authors = ["Stellar Development Foundation "] license = "Apache-2.0" edition = "2021" diff --git a/cmd/crates/soroban-test/tests/fixtures/test-wasms/custom_type/Cargo.toml b/cmd/crates/soroban-test/tests/fixtures/test-wasms/custom_type/Cargo.toml index 79c6917aa5..edb89274de 100644 --- a/cmd/crates/soroban-test/tests/fixtures/test-wasms/custom_type/Cargo.toml +++ b/cmd/crates/soroban-test/tests/fixtures/test-wasms/custom_type/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test_custom_types" -version = "28.1.0" +version = "30.0.0" authors = ["Stellar Development Foundation "] license = "Apache-2.0" edition = "2021" diff --git a/cmd/crates/soroban-test/tests/fixtures/test-wasms/empty_constructor/Cargo.toml b/cmd/crates/soroban-test/tests/fixtures/test-wasms/empty_constructor/Cargo.toml index 480bcf5ac9..1d0c196671 100644 --- a/cmd/crates/soroban-test/tests/fixtures/test-wasms/empty_constructor/Cargo.toml +++ b/cmd/crates/soroban-test/tests/fixtures/test-wasms/empty_constructor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test_empty_constructor" -version = "28.1.0" +version = "30.0.0" authors = ["Stellar Development Foundation "] license = "Apache-2.0" edition = "2021" diff --git a/cmd/crates/soroban-test/tests/fixtures/test-wasms/hello_world/Cargo.toml b/cmd/crates/soroban-test/tests/fixtures/test-wasms/hello_world/Cargo.toml index 5f7a42d901..7b86d45d1e 100644 --- a/cmd/crates/soroban-test/tests/fixtures/test-wasms/hello_world/Cargo.toml +++ b/cmd/crates/soroban-test/tests/fixtures/test-wasms/hello_world/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test_hello_world" -version = "28.1.0" +version = "30.0.0" authors = ["Stellar Development Foundation "] license = "Apache-2.0" edition = "2021" diff --git a/cmd/crates/soroban-test/tests/fixtures/test-wasms/swap/Cargo.toml b/cmd/crates/soroban-test/tests/fixtures/test-wasms/swap/Cargo.toml index 4d790bf80c..9d479af342 100644 --- a/cmd/crates/soroban-test/tests/fixtures/test-wasms/swap/Cargo.toml +++ b/cmd/crates/soroban-test/tests/fixtures/test-wasms/swap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test_swap" -version = "28.1.0" +version = "30.0.0" authors = ["Stellar Development Foundation "] license = "Apache-2.0" edition = "2021" diff --git a/cmd/crates/soroban-test/tests/fixtures/test-wasms/token/Cargo.toml b/cmd/crates/soroban-test/tests/fixtures/test-wasms/token/Cargo.toml index 23cc948922..87af7bc976 100644 --- a/cmd/crates/soroban-test/tests/fixtures/test-wasms/token/Cargo.toml +++ b/cmd/crates/soroban-test/tests/fixtures/test-wasms/token/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test_token" -version = "28.1.0" +version = "30.0.0" description = "Soroban standard token contract" authors = ["Stellar Development Foundation "] license = "Apache-2.0" diff --git a/cmd/crates/soroban-test/tests/fixtures/test-wasms/token_renamed/Cargo.toml b/cmd/crates/soroban-test/tests/fixtures/test-wasms/token_renamed/Cargo.toml index 87d6d7f806..26e7b83cf2 100644 --- a/cmd/crates/soroban-test/tests/fixtures/test-wasms/token_renamed/Cargo.toml +++ b/cmd/crates/soroban-test/tests/fixtures/test-wasms/token_renamed/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test_token_renamed" -version = "28.1.0" +version = "30.0.0" description = "A SEP-41-shaped token whose parameters use non-canonical names" authors = ["Stellar Development Foundation "] license = "Apache-2.0" diff --git a/cmd/crates/soroban-test/tests/fixtures/workspace-with-qualified-names/Cargo.toml b/cmd/crates/soroban-test/tests/fixtures/workspace-with-qualified-names/Cargo.toml new file mode 100644 index 0000000000..97842e7b54 --- /dev/null +++ b/cmd/crates/soroban-test/tests/fixtures/workspace-with-qualified-names/Cargo.toml @@ -0,0 +1,18 @@ +[workspace] +resolver = "2" +members = [ + "contracts/*", +] + +[workspace.dependencies] +soroban-sdk = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "a7081319bfa59a7da7352510dfa9e05734510be4" } + +[profile.release] +opt-level = "z" +overflow-checks = true +debug = 0 +strip = "symbols" +debug-assertions = false +panic = "abort" +codegen-units = 1 +lto = true diff --git a/cmd/crates/soroban-test/tests/fixtures/workspace-with-qualified-names/contracts/names/Cargo.toml b/cmd/crates/soroban-test/tests/fixtures/workspace-with-qualified-names/contracts/names/Cargo.toml new file mode 100644 index 0000000000..f5e1bbe92b --- /dev/null +++ b/cmd/crates/soroban-test/tests/fixtures/workspace-with-qualified-names/contracts/names/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "names" +version = "0.0.0" +edition = "2021" +publish = false + +[lib] +crate-type = ["cdylib"] +doctest = false + +[dependencies] +soroban-sdk = { workspace = true } diff --git a/cmd/crates/soroban-test/tests/fixtures/workspace-with-qualified-names/contracts/names/src/lib.rs b/cmd/crates/soroban-test/tests/fixtures/workspace-with-qualified-names/contracts/names/src/lib.rs new file mode 100644 index 0000000000..bd6def2f84 --- /dev/null +++ b/cmd/crates/soroban-test/tests/fixtures/workspace-with-qualified-names/contracts/names/src/lib.rs @@ -0,0 +1,48 @@ +#![no_std] +use soroban_sdk::{contract, contractevent, contractimpl, Env}; + +pub mod a { + use soroban_sdk::contracttype; + + #[contracttype] + pub struct State { + pub count: u32, + } +} + +pub mod b { + use soroban_sdk::contracttype; + + #[contracttype] + pub struct State { + pub enabled: bool, + } + + #[contracttype] + pub struct Wrapper { + pub state: State, + } +} + +#[contractevent] +pub struct Updated { + pub count: u32, +} + +#[contract] +pub struct Contract; + +#[contractimpl] +impl Contract { + pub fn get_a(_env: Env, state: a::State) -> a::State { + state + } + + pub fn get_b(_env: Env, wrapper: b::Wrapper) -> b::State { + wrapper.state + } + + pub fn update(env: Env, count: u32) { + Updated { count }.publish(&env); + } +} diff --git a/cmd/crates/soroban-test/tests/it/build.rs b/cmd/crates/soroban-test/tests/it/build.rs index ffabfbe038..18c27dc6c8 100644 --- a/cmd/crates/soroban-test/tests/it/build.rs +++ b/cmd/crates/soroban-test/tests/it/build.rs @@ -512,7 +512,7 @@ fn filter_and_dedup_spec_removes_duplicates() { .unwrap(), }); - // Build markers for the struct so it passes the filter + // Build markers for the struct so it passes the markers filter let mut markers = std::collections::HashSet::new(); markers.insert(soroban_spec::shaking::generate_marker_for_entry( &used_struct, @@ -527,7 +527,8 @@ fn filter_and_dedup_spec_removes_duplicates() { used_struct.clone(), ]; - let result_xdr = filter_and_dedup_spec(entries, &markers).unwrap(); + let result_xdr = + filter_and_dedup_spec(entries, &markers, soroban_spec::shaking::Model::Markers).unwrap(); // Parse back the entries from the XDR let result_entries: Vec = @@ -554,11 +555,16 @@ fn filter_and_dedup_spec_removes_duplicates() { fn build_with_spec_shaking_has_feature_meta() { let (_spec, meta) = build_spec_shaking_fixture(); - let version = soroban_spec::shaking::spec_shaking_version_for_meta(&meta); + let model = soroban_spec::shaking::model_for_meta(&meta); + // The fixture builds against a published soroban-sdk, which records spec + // shaking version 2. The workspace's `[patch.crates-io]` does not reach a + // contract built in a temp dir, so this covers the markers rules end to + // end, and the SDK's own test contract covers the references rules. assert_eq!( - version, 2, - "contractmeta should indicate spec shaking version 2" + model, + soroban_spec::shaking::Model::Markers, + "contractmeta should select the markers model" ); } @@ -1348,3 +1354,96 @@ fn contract_archive_dirty_tree_errors() { "no archive should be written for a dirty tree" ); } + +#[test] +fn build_reduces_qualified_names_and_rewrites_references() { + let sandbox = TestEnv::default(); + let outdir = sandbox.dir().join("out"); + let cargo_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let fixture_path = cargo_dir.join("tests/fixtures/workspace-with-qualified-names"); + let temp = TempDir::new().unwrap(); + let dir_path = temp.path(); + fs_extra::dir::copy(fixture_path, dir_path, &CopyOptions::new()).unwrap(); + let dir_path = dir_path.join("workspace-with-qualified-names"); + + // The two `State` types collide once reduced to their last segment, and the + // build warns about the one it numbers. + sandbox + .new_assert_cmd("contract") + .current_dir(&dir_path) + .arg("build") + .arg("--out-dir") + .arg(&outdir) + .assert() + .success() + .stderr(predicate::str::contains( + "names: reduced type and event names collided and were disambiguated with a numeric suffix:", + )) + .stderr(predicate::str::contains("::names::b::State -> State2")); + + let wasm = std::fs::read(dir_path.join(&outdir).join("names.wasm")).unwrap(); + let spec = Spec::new(&wasm).unwrap(); + + let udt = |name: &str| { + soroban_cli::xdr::ScSpecTypeDef::Udt(soroban_cli::xdr::ScSpecTypeUdt { + name: name.try_into().unwrap(), + }) + }; + + let mut structs = Vec::new(); + let mut events = Vec::new(); + let mut functions = Vec::new(); + for entry in &spec.spec { + match entry { + ScSpecEntry::UdtStructV0(s) => structs.push(( + s.name.to_utf8_string_lossy(), + s.fields.iter().map(|f| f.type_.clone()).collect::>(), + )), + ScSpecEntry::EventV0(e) => events.push(e.name.to_utf8_string_lossy()), + ScSpecEntry::FunctionV0(f) => functions.push(( + f.name.to_utf8_string_lossy(), + f.inputs.iter().map(|i| i.type_.clone()).collect::>(), + f.outputs.to_vec(), + )), + _ => {} + } + } + structs.sort_by(|a, b| a.0.cmp(&b.0)); + functions.sort_by(|a, b| a.0.cmp(&b.0)); + + // `a::State` sorts before `b::State` by its full name, so keeps the name, and + // `b::State` is numbered. Every name is reduced to its last segment. + assert_eq!( + structs, + [ + ( + "State".to_string(), + vec![soroban_cli::xdr::ScSpecTypeDef::U32] + ), + ( + "State2".to_string(), + vec![soroban_cli::xdr::ScSpecTypeDef::Bool] + ), + ("Wrapper".to_string(), vec![udt("State2")]), + ] + ); + assert_eq!(events, ["Updated"]); + + // The references in the functions are rewritten to the reduced names. + assert_eq!( + functions, + [ + ("get_a".to_string(), vec![udt("State")], vec![udt("State")]), + ( + "get_b".to_string(), + vec![udt("Wrapper")], + vec![udt("State2")] + ), + ( + "update".to_string(), + vec![soroban_cli::xdr::ScSpecTypeDef::U32], + vec![] + ), + ] + ); +} diff --git a/cmd/soroban-cli/src/commands/contract/build.rs b/cmd/soroban-cli/src/commands/contract/build.rs index 8de55d3ae3..3681559519 100644 --- a/cmd/soroban-cli/src/commands/contract/build.rs +++ b/cmd/soroban-cli/src/commands/contract/build.rs @@ -373,7 +373,9 @@ impl Cmd { } // Set env var to inform the SDK that this CLI supports spec - // optimization using markers. Current and new SDK versions no + // optimization. The var says only that this CLI shakes; which + // rules it shakes a given contract by comes from the model that + // contract's meta selects. Current and new SDK versions no // longer read this var, relying on the CLI version below // instead, but it must keep being set for past SDK versions that // require it. @@ -402,8 +404,10 @@ impl Cmd { .join(&file); self.inject_meta(&target_file_path)?; - Self::filter_spec(&target_file_path)?; - Self::reduce_spec(&print, &p.name, &target_file_path)?; + let model = Self::filter_spec(&target_file_path)?; + if model == soroban_spec::shaking::Model::References { + Self::reduce_spec(&print, &p.name, &target_file_path)?; + } let final_path = if let Some(out_dir) = &self.out_dir { fs::create_dir_all(out_dir).map_err(Error::CreatingOutDir)?; @@ -533,17 +537,19 @@ impl Cmd { fs::write(target_file_path, wasm_bytes).map_err(Error::WritingWasmFile) } - /// Filters unused types and events from the contract spec. - /// - /// This removes: - /// - Type definitions that are not referenced by any function - /// - Events that don't have corresponding markers in the WASM data section - /// (events that are defined but never published) + /// Filters unused types and events from the contract spec, and returns the + /// model the contract's spec is shaken by. /// - /// The SDK embeds markers in the data section for types/events that are - /// actually used. These markers survive dead code elimination, so we can - /// detect which spec entries are truly needed. - fn filter_spec(target_file_path: &PathBuf) -> Result<(), Error> { + /// The SDK that built the contract selects the model, which says which + /// entries carry a marker and so what a missing marker means. Read it from + /// the contract's meta and shake by its rules rather than the newest known: + /// a soroban-sdk v30 or later contract marks only the events it publishes + /// and the errors it panics with, and every other type is settled by + /// following the references to it, while a contract recording spec + /// shaking version 2 marks every used type, so markers alone say what is + /// used. Any other contract records nothing to shake by, and its spec is + /// left alone. + fn filter_spec(target_file_path: &PathBuf) -> Result { use soroban_spec_tools::contract::Spec; use soroban_spec_tools::wasm::replace_custom_section; @@ -552,17 +558,19 @@ impl Cmd { // Parse the spec from the wasm let spec = Spec::new(&wasm_bytes)?; - // Check if the contract meta indicates spec shaking v2 is enabled. - if soroban_spec::shaking::spec_shaking_version_for_meta(&spec.meta) != 2 { - return Ok(()); + // Read the model the contract is shaken by, which selects the rules + // below. Nothing to shake by under the none model, so leave it alone. + let model = soroban_spec::shaking::model_for_meta(&spec.meta); + if model == soroban_spec::shaking::Model::None { + return Ok(model); } // Extract markers from the WASM data section let markers = soroban_spec::shaking::find_all(&wasm_bytes); - // Filter spec entries (types, events) based on markers, and + // Filter spec entries (types, events) by that model's rules, and // deduplicate any exact duplicate entries. - let filtered_xdr = filter_and_dedup_spec(spec.spec.clone(), &markers)?; + let filtered_xdr = filter_and_dedup_spec(spec.spec.clone(), &markers, model)?; // Replace the contractspecv0 section with the filtered version let new_wasm = replace_custom_section(&wasm_bytes, "contractspecv0", &filtered_xdr) @@ -570,7 +578,8 @@ impl Cmd { // Write the modified wasm back fs::remove_file(target_file_path).map_err(Error::DeletingArtifact)?; - fs::write(target_file_path, new_wasm).map_err(Error::WritingWasmFile) + fs::write(target_file_path, new_wasm).map_err(Error::WritingWasmFile)?; + Ok(model) } /// Reduces user-defined type names in the contract spec to their simple @@ -582,8 +591,10 @@ impl Cmd { /// downstream tool see the short names. Names that would collide are /// disambiguated with a numeric suffix, which is warned about. /// - /// Runs after `filter_spec` so only the entries that survive shaking are - /// reduced, but is otherwise independent of spec shaking. + /// Runs only for contracts shaken by the references model, the soroban-sdk + /// v30 or later contracts whose specs name types by their fully qualified + /// path, and after `filter_spec` so only the entries that survive shaking + /// are reduced. fn reduce_spec(print: &Print, name: &str, target_file_path: &PathBuf) -> Result<(), Error> { use soroban_spec_tools::contract::Spec; use soroban_spec_tools::wasm::replace_custom_section; @@ -961,15 +972,17 @@ fn check_overflow_checks(doc: &toml_edit::DocumentMut, profile: &str) -> Result< } } -/// Filters spec entries based on markers and deduplicates exact duplicates. +/// Filters spec entries down to those the contract needs, by the rules of the +/// model its spec is shaken by, and deduplicates exact duplicates. /// -/// Functions are always kept. Other entries (types, events) are kept only if a -/// matching marker exists. Exact duplicate entries (identical XDR) are collapsed +/// Which entries survive is decided by `soroban_spec::shaking::filter` for the +/// given model. Exact duplicate entries (identical XDR) are then collapsed /// to a single occurrence. #[allow(clippy::implicit_hasher)] pub fn filter_and_dedup_spec( entries: Vec, markers: &HashSet, + model: soroban_spec::shaking::Model, ) -> Result, Error> { let mut seen = HashSet::new(); let mut filtered_xdr = Vec::new(); @@ -977,7 +990,7 @@ pub fn filter_and_dedup_spec( Cursor::new(&mut filtered_xdr), Limits::depth(XDR_DEPTH_LIMIT), ); - for entry in soroban_spec::shaking::filter(entries, markers) { + for entry in soroban_spec::shaking::filter(entries, markers, model) { let entry_xdr = entry.to_xdr(Limits::depth(XDR_DEPTH_LIMIT))?; if seen.insert(entry_xdr) { entry.write_xdr(&mut writer)?; diff --git a/cmd/soroban-cli/src/utils/contract-workspace-template/Cargo.toml.removeextension b/cmd/soroban-cli/src/utils/contract-workspace-template/Cargo.toml.removeextension index 27fc38e124..1b2b2b1ea3 100644 --- a/cmd/soroban-cli/src/utils/contract-workspace-template/Cargo.toml.removeextension +++ b/cmd/soroban-cli/src/utils/contract-workspace-template/Cargo.toml.removeextension @@ -5,7 +5,7 @@ members = [ ] [workspace.dependencies] -soroban-sdk = "28" +soroban-sdk = "30" [profile.release] opt-level = "z"