Skip to content
Draft
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
75 changes: 29 additions & 46 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ testcontainers = "0.27.2"
httpmock = "0.7.0"
astral-tokio-tar = "0.6.0"

[patch.crates-io]
# Pending https://github.com/stellar/rs-stellar-xdr/pull/566, which widens the
# user-defined type name limit so that a fully qualified type name fits. Pinned
# to the same rev rs-soroban-sdk#1970 uses so the graph has one stellar-xdr.
stellar-xdr = { git = "https://github.com/stellar/rs-stellar-xdr", rev = "9c6c2f8c09b678d1ebed87b3f41f621068badcf4" }
# Pending https://github.com/stellar/rs-soroban-sdk/pull/1970, which names
# user-defined types in contract specs by their fully qualified path.
soroban-spec = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "7093a641145329526b221e683fbb5e74f9710053" }
soroban-spec-rust = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "7093a641145329526b221e683fbb5e74f9710053" }
soroban-sdk = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "7093a641145329526b221e683fbb5e74f9710053" }
soroban-token-sdk = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "7093a641145329526b221e683fbb5e74f9710053" }
stellar-asset-spec = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "7093a641145329526b221e683fbb5e74f9710053" }
soroban-ledger-snapshot = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "7093a641145329526b221e683fbb5e74f9710053" }
# Pending https://github.com/stellar/rs-soroban-env/pull/1733, which adapts the
# host to the XDR constants that rs-stellar-xdr#580 changes from u64 to u32.
# rs-soroban-sdk#1970 is on that 29.x line, so pin to the same rev it uses.
soroban-env-common = { git = "https://github.com/stellar/rs-soroban-env", rev = "de68ee914401e70d3d8350a4d004c0442943324e" }
soroban-env-guest = { git = "https://github.com/stellar/rs-soroban-env", rev = "de68ee914401e70d3d8350a4d004c0442943324e" }
soroban-env-host = { git = "https://github.com/stellar/rs-soroban-env", rev = "de68ee914401e70d3d8350a4d004c0442943324e" }

[profile.release]
overflow-checks = true

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ build:
cargo build

build-test-wasms:
SOROBAN_SDK_BUILD_SYSTEM_SUPPORTS_SPEC_SHAKING_V2=1 cargo build --package 'test_*' --profile test-wasms --target wasm32v1-none
SOROBAN_SDK_BUILD_SYSTEM_SUPPORTS_SPEC_SHAKING_V2=1 SOROBAN_SDK_BUILD_SYSTEM_SUPPORTS_REDUCING_FULL_NAMES=1 cargo build --package 'test_*' --profile test-wasms --target wasm32v1-none

build-test: build-test-wasms build-fixtures install

Expand Down
2 changes: 1 addition & 1 deletion cmd/crates/soroban-spec-tools/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ fn indent(s: &str, n: usize) -> String {
.join("\n")
}

fn format_name(lib: &StringM<80>, name: &StringM<60>) -> String {
fn format_name(lib: &StringM<80>, name: &StringM<{ crate::UDT_NAME_LIMIT }>) -> String {
if lib.is_empty() {
sanitize(&name.to_utf8_string_lossy())
} else {
Expand Down
2 changes: 1 addition & 1 deletion cmd/crates/soroban-spec-tools/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ mod tests {
ScSpecEventV0 {
doc: StringM::default(),
lib: StringM::default(),
name: make_symbol(name),
name: name.try_into().unwrap(),
prefix_topics: prefix_topics
.into_iter()
.map(make_symbol)
Expand Down
18 changes: 14 additions & 4 deletions cmd/crates/soroban-spec-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use stellar_xdr::{
ScSpecTypeTuple, ScSpecTypeUdt, ScSpecTypeVec, ScSpecUdtEnumV0, ScSpecUdtErrorEnumCaseV0,
ScSpecUdtErrorEnumV0, ScSpecUdtStructV0, ScSpecUdtUnionCaseTupleV0, ScSpecUdtUnionCaseV0,
ScSpecUdtUnionCaseVoidV0, ScSpecUdtUnionV0, ScString, ScSymbol, ScVal, ScVec, StringM,
UInt128Parts, UInt256Parts, Uint256, VecM,
UInt128Parts, UInt256Parts, Uint256, VecM, SC_SPEC_TYPE_NAME_LIMIT,
};

pub mod contract;
Expand All @@ -25,6 +25,12 @@ pub mod wasm;
pub use contract::sanitize;
pub use verify::SpecWarning;

/// The XDR limit on the length of a user-defined type name
/// ([`SC_SPEC_TYPE_NAME_LIMIT`]), as the `u32` that `StringM`'s const generic
/// expects.
#[allow(clippy::cast_possible_truncation)]
pub const UDT_NAME_LIMIT: u32 = SC_SPEC_TYPE_NAME_LIMIT as u32;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("an unknown error occurred")]
Expand Down Expand Up @@ -372,7 +378,7 @@ impl Spec {
Ok(val)
}

fn parse_udt(&self, name: &StringM<60>, value: &Value) -> Result<ScVal, Error> {
fn parse_udt(&self, name: &StringM<UDT_NAME_LIMIT>, value: &Value) -> Result<ScVal, Error> {
let name = &name.to_utf8_string_lossy();
match (self.find(name)?, value) {
(ScSpecEntry::UdtStructV0(strukt), Value::Object(map)) => {
Expand Down Expand Up @@ -649,7 +655,11 @@ impl Spec {
/// # Panics
///
/// May panic
pub fn udt_to_json(&self, name: &StringM<60>, sc_obj: &ScVal) -> Result<Value, Error> {
pub fn udt_to_json(
&self,
name: &StringM<UDT_NAME_LIMIT>,
sc_obj: &ScVal,
) -> Result<Value, Error> {
let name = &name.to_utf8_string_lossy();
let udt = self.find(name)?;
Ok(match (sc_obj, udt) {
Expand Down Expand Up @@ -2345,7 +2355,7 @@ mod tests {
ScSpecEventV0 {
doc: StringM::default(),
lib: StringM::default(),
name: ScSymbol(name.try_into().unwrap()),
name: name.try_into().unwrap(),
prefix_topics: VecM::default(),
params: VecM::default(),
data_format: stellar_xdr::ScSpecEventDataFormat::SingleValue,
Expand Down
10 changes: 7 additions & 3 deletions cmd/crates/soroban-test/tests/it/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,11 @@ fn parent_path() -> String {
}

fn with_flags(expected: &str) -> String {
const ENV_VAR: &str = "SOROBAN_SDK_BUILD_SYSTEM_SUPPORTS_SPEC_SHAKING_V2=1";
// Serialized in sorted key order, so REDUCING_FULL_NAMES precedes SPEC_SHAKING_V2.
const ENV_VARS: &str = concat!(
"SOROBAN_SDK_BUILD_SYSTEM_SUPPORTS_REDUCING_FULL_NAMES=1 ",
"SOROBAN_SDK_BUILD_SYSTEM_SUPPORTS_SPEC_SHAKING_V2=1"
);

let cargo_home = home::cargo_home().unwrap();
let registry_prefix = cargo_home.join("registry").join("src");
Expand All @@ -747,15 +751,15 @@ fn with_flags(expected: &str) -> String {
let vec: Vec<_> = if env::var("RUSTFLAGS").is_ok() {
expected
.split('\n')
.map(|x| format!("{ENV_VAR} {x}"))
.map(|x| format!("{ENV_VARS} {x}"))
.collect()
} else {
expected
.split('\n')
.map(|x| {
let rustflags_value = format!("--remap-path-prefix={registry_prefix}=");
let escaped_value = escape(std::borrow::Cow::Borrowed(&rustflags_value));
format!("CARGO_BUILD_RUSTFLAGS={escaped_value} {ENV_VAR} {x}")
format!("CARGO_BUILD_RUSTFLAGS={escaped_value} {ENV_VARS} {x}")
})
.collect()
};
Expand Down
Loading
Loading