ABI Build Process
This document explains how ABI generation works during the Rust build process for Calimero applications.
Overview
The ABI generation process follows a two-step flow:
- Generate ABI at build time as JSON - The build process analyzes your Rust code and generates a JSON Schema-based ABI
- Optionally embed into WASM - The ABI can be embedded into the WASM binary for tools that may load/swap different WASMs
Build Script
Create a simple build.rs
file:
use calimero_abi_emitter::emit_manifest;
fn main() {
emit_manifest().expect("Failed to generate ABI manifest");
}
Type Mapping
Rust types are automatically mapped to ABI-compatible representations:
Rust Type | ABI Type | Notes |
---|---|---|
u8 , u16 , u32 , u64 | u8 , u16 , u32 , u64 | Direct mapping |
i8 , i16 , i32 , i64 | i8 , i16 , i32 , i64 | Direct mapping |
bool | bool | Direct mapping |
String | string | UTF-8 string |
Vec<T> | list<T> | Dynamic array |
[T; N] | array<T, N> | Fixed-size array |
Option<T> | T? | Nullable type |
Result<T, E> | T | Success type only |
BTreeMap<K, V> | map<K, V> | Key-value mapping |
HashMap<K, V> | map<K, V> | Key-value mapping |
struct S { ... } | record S { ... } | Record type |
enum E { ... } | variant E { ... } | Variant type |
ABI Extraction
Use the calimero-abi
tool to extract the ABI from your WASM binary:
calimero-abi extract target/wasm32-unknown-unknown/release/my_app.wasm
Next Steps
- Configuration - Configure ABI generation for your project
- Rust Integration - Integrate ABI generation with your Rust code
- Validation - Set up ABI validation and testing
Was this page helpful?