Skip to content

Commit

Permalink
Expose rust code gen of contracts without the file import (#1311)
Browse files Browse the repository at this point in the history
### What
Expose rust code gen of contracts without the file import.

### Why
The code gen function for rust code generates the interface and types as
well as an import of the wasm binary. The CLI uses this function and
wants to output the generated code without the wasm binary.

Related to:
-
stellar/stellar-cli#1532 (comment)
  • Loading branch information
leighmcculloch authored Aug 8, 2024
1 parent 10a3372 commit 39fd18f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions soroban-spec-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ pub fn generate_from_wasm(
}

pub fn generate(specs: &[ScSpecEntry], file: &str, sha256: &str) -> TokenStream {
let generated = generate_without_file(specs);
quote! {
pub const WASM: &[u8] = soroban_sdk::contractfile!(file = #file, sha256 = #sha256);
#generated
}
}

pub fn generate_without_file(specs: &[ScSpecEntry]) -> TokenStream {
let mut spec_fns = Vec::new();
let mut spec_structs = Vec::new();
let mut spec_unions = Vec::new();
Expand All @@ -81,8 +89,6 @@ pub fn generate(specs: &[ScSpecEntry], file: &str, sha256: &str) -> TokenStream
let error_enums = spec_error_enums.iter().map(|s| generate_error_enum(s));

quote! {
pub const WASM: &[u8] = soroban_sdk::contractfile!(file = #file, sha256 = #sha256);

#[soroban_sdk::contractclient(name = "Client")]
#trait_

Expand Down

0 comments on commit 39fd18f

Please sign in to comment.