Skip to main content

Module build_helper

Module build_helper 

Source
Expand description

Build script helper for code generation.

This module provides utilities for generating code at compile time via build.rs.

§Example

Add to your build.rs:

use aptos_sdk::codegen::build_helper;

fn main() {
    // Generate from a local ABI file
    build_helper::generate_from_abi(
        "abi/my_module.json",
        "src/generated/",
    ).expect("code generation failed");

    // Generate from multiple modules
    build_helper::generate_from_abis(&[
        "abi/coin.json",
        "abi/token.json",
    ], "src/generated/").expect("code generation failed");

    // Rerun if ABI files change
    println!("cargo:rerun-if-changed=abi/");
}

§Directory Structure

my_project/
├── build.rs
├── abi/
│   ├── my_module.json
│   └── another_module.json
└── src/
    └── generated/
        ├── mod.rs          (auto-generated)
        ├── my_module.rs
        └── another_module.rs

Structs§

BuildConfig
Configuration for build-time code generation.

Functions§

generate_from_abi
Generates Rust code from a single ABI file.
generate_from_abi_with_config
Generates Rust code from a single ABI file with custom configuration.
generate_from_abi_with_source
Generates Rust code from an ABI file with Move source for better names.
generate_from_abis
Generates Rust code from multiple ABI files.
generate_from_abis_with_config
Generates Rust code from multiple ABI files with custom configuration.
generate_from_directory
Scans a directory for ABI files and generates code for all of them.