-
Notifications
You must be signed in to change notification settings - Fork 1
Getting Started Rust
stefnotch edited this page Mar 16, 2025
·
12 revisions
WESL is designed to work with both JavaScript and Rust. We have two distinct implementations for these languages, wesl-js and wesl-rs.
Wesl can be operated in a few different ways:
- Using the standalone Command-Line tool to generate WGSL files.
- At build-time, using a Vite Plugin (JavaScript) or a Build Script (Rust).
- At run-time, using the linker libraries.
wesl-rs documentation: https://docs.rs/wesl/
- Install the CLI:
cargo install --git https://github.com/wgsl-tooling-wg/wesl-rs wesl-cli - Compile a shader:
wesl compile <path/to/shader.wesl> - Type
wesl --helpor visit the crate documentation (coming soon) for more configuration options.
- Add wesl-rs to your build-dependencies:
cargo add --git https://github.com/wgsl-tooling-wg/wesl-rs --build wesl - Create the file
build.rsright next to yourCargo.toml. - Paste this content:
fn main() { wesl::Wesl::new_spec_compliant("src/shaders").build_artefact("main.wesl", "my_shader"); }
- Place your shader in
src/shaders/main.wesl. - Paste this code where you want to access your shader string in Rust code:
use wesl::include_wesl; const shader_string = include_wesl!("my_shader");
- Add wesl-rs to your dependencies:
cargo add --git https://github.com/wgsl-tooling-wg/wesl-rs wesl - Place your shader in
src/shaders/main.wesl. - Paste this code where you want to access your shader string in Rust code:
let shader_string = Wesl::new_spec_compliant("src/shaders") .compile("main.wesl") .inspect_err(|e| eprintln!("WESL error: {e}")) // pretty errors with `display()` .unwrap() .to_string();
Visit the Authoring Shaders page to learn how to write your first WESL shaders.
Visit the Reference page for the complete documentation of WESL Extensions.