include-wasm-rs

Crates.ioinclude-wasm-rs
lib.rsinclude-wasm-rs
version0.2.0
sourcesrc
created_at2023-12-13 15:18:10.547437
updated_at2024-08-31 13:42:21.851281
descriptionBuilds a Rust WebAssembly module at compile time and returns the bytes.
homepagehttps://github.com/LucentFlux/include-wasm-rs
repositoryhttps://github.com/LucentFlux/include-wasm-rs
max_upload_size
id1068107
size28,191
Joe O'Connor (Joeoc2001)

documentation

README

Include Wasm-RS

crates.io docs.rs crates.io

Builds a Rust WebAssembly module at compile time and returns the bytes.

Example

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.

Toolchain

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

Arguments

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
};

Features

If you're on nightly, the proc_macro_span feature will enable better call site location resolution.

Commit count: 3

cargo fmt