38 releases (stable)
Uses new Rust 2024
| 1.10.0 | Dec 2, 2025 |
|---|---|
| 1.9.2 | Oct 3, 2025 |
| 1.9.1 | Sep 5, 2025 |
| 1.8.1 | May 15, 2025 |
| 0.1.2 | Mar 13, 2022 |
#6 in #wasm-builder
678 downloads per month
Used in 4 crates
695KB
15K
SLoC
Gear WASM Builder
This is a helper crate that can be used in build scripts for building Gear programs.
Usage
- Add the
gear-wasm-buildercrate as a build dependency to theCargo.toml:
# ...
[build-dependencies]
gear-wasm-builder = "0.1.2"
# ...
- Create a
build.rsfile and place it at the directory withCargo.toml:
fn main() {
gear_wasm_builder::build();
}
- Use
cargoas usually:
cargo clean
cargo build
cargo build --release
cargo test
cargo test --release
- Find the built WASM binaries in
target/wasm32-gear/<profile>directory:
.wasm— original WASM built from the source files.opt.wasm— optimised WASM binary to be submitted to the blockchain
- Also, you can include a generated
wasm_binary.rssource 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 thestdfeature. If you want to use a custom feature for that, use one of the thebuild_XXX_customfunctions in yourbuild.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-gear/debug/test_program.wasm").unwrap(),
code::WASM_BINARY,
);
assert_eq!(
std::fs::read("target/wasm32-gear/debug/test_program.opt.wasm").unwrap(),
code::WASM_BINARY_OPT,
);
}
License
Source code is licensed under GPL-3.0-or-later WITH Classpath-exception-2.0.
Dependencies
~16–33MB
~507K SLoC