Crates.io | include-wasm-rs |
lib.rs | include-wasm-rs |
version | 0.2.0 |
source | src |
created_at | 2023-12-13 15:18:10.547437 |
updated_at | 2024-08-31 13:42:21.851281 |
description | Builds a Rust WebAssembly module at compile time and returns the bytes. |
homepage | https://github.com/LucentFlux/include-wasm-rs |
repository | https://github.com/LucentFlux/include-wasm-rs |
max_upload_size | |
id | 1068107 |
size | 28,191 |
Builds a Rust WebAssembly module at compile time and returns the bytes.
let module = build_wasm!("relative/path/to/module");
This crate provides a wrapper around cargo
to build and then include a WebAssembly module at compile time. This is intended for use in unit tests, where the target platform may not be able to invoke cargo itself, for example while using MIRI
or when executing the compiled module on the Web.
To use this crate, you must have the wasm32-unknown-unknown
nightly toolchain installed, and have the rust-src
component. You can install these with the following commands:
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup component add rust-src
The build macro allows for an assortment of arguments to be passed to the build command:
let module = build_wasm!{
path: "relative/path/to/module",
features: [
atomics, // Controls if the `atomics` proposal is enabled
bulk_memory, // Controls if the `bulk-memory` proposal is enabled
mutable_globals, // Controls if the `mutable-globals` proposal is enabled
],
// Allows additional environment variables to be set while compiling the module.
env: Env {
FOO: "bar",
BAX: 7,
},
// Controls if the module should be built in debug or release mode.
release: true
};
If you're on nightly, the proc_macro_span
feature will enable better call site location resolution.