16 releases (6 stable)

new 1.3.1-pre.3 Apr 19, 2024
1.1.1 Feb 12, 2024
1.1.1-rc.0 Jan 29, 2024
1.0.3 Dec 28, 2023
0.1.1 Feb 19, 2022

#1683 in Magic Beans

Download history 3/week @ 2023-12-22 12/week @ 2024-01-05 3/week @ 2024-01-12 56/week @ 2024-01-19 47/week @ 2024-01-26 75/week @ 2024-02-02 183/week @ 2024-02-09 110/week @ 2024-02-16 170/week @ 2024-02-23 80/week @ 2024-03-01 104/week @ 2024-03-08 109/week @ 2024-03-15 194/week @ 2024-03-22 187/week @ 2024-03-29 125/week @ 2024-04-05

632 downloads per month
Used in 2 crates

GPL-3.0 license

485KB
10K SLoC

Gear WASM Builder

This is a helper crate that can be used in build scripts for building Gear programs.

Usage

  1. Add the gear-wasm-builder crate as a build dependency to the Cargo.toml:
# ...

[build-dependencies]
gear-wasm-builder = "0.1.2"

# ...
  1. Create a build.rs file and place it at the directory with Cargo.toml:
fn main() {
    gear_wasm_builder::build();
}
  1. Use cargo as usually:
cargo clean
cargo build
cargo build --release
cargo test
cargo test --release
  1. Find the built WASM binaries in target/wasm32-unknown-unknown/<profile> directory:
  • .wasm — original WASM built from the source files
  • .opt.wasm — optimised WASM binary to be submitted to the blockchain
  • .meta.wasm — metadata providing WASM binary for auxiliary purposes
  1. Also, you can include a generated wasm_binary.rs source file to use the WASM code while e.g. writing tests. When doing this, you need to use some feature which will be excluded from passing it down to the build process triggered by the build script. By default, this is the std feature. If you want to use a custom feature for that, use one of the the build_XXX_custom functions in your build.rs
#[cfg(feature = "std")]
mod code {
    include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
}

#[test]
fn debug_wasm() {
    assert_eq!(
        std::fs::read("target/wasm32-unknown-unknown/debug/test_program.wasm").unwrap(),
        code::WASM_BINARY,
    );
    assert_eq!(
        std::fs::read("target/wasm32-unknown-unknown/debug/test_program.opt.wasm").unwrap(),
        code::WASM_BINARY_OPT,
    );
    assert_eq!(
        std::fs::read("target/wasm32-unknown-unknown/debug/test_program.meta.wasm").unwrap(),
        code::WASM_BINARY_META,
    );
}

License

Source code is licensed under GPL-3.0-or-later WITH Classpath-exception-2.0.

Dependencies

~12–25MB
~369K SLoC