-
Notifications
You must be signed in to change notification settings - Fork 1
Getting Started Rust
lee mighdoll edited this page Feb 27, 2026
·
12 revisions
wesl-rs can be operated in a few different ways:
- Using the standalone command-line tool to generate WGSL files.
- At build-time, using a build Script.
- At run-time.
These are the quick setup instructions. Read the crate documentation and visit the code samples for a more in-depth explanation.
- Add the crate to your build-dependencies:
cargo add --build wesl - Add the crate to your dependencies:
cargo add wesl - Create the file
build.rsnext to yourCargo.toml. - Paste this content:
fn main() { wesl::Wesl::new("src/shaders").build_artifact(&"package::main".parse().unwrap(), "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; let shader_string = include_wesl!("my_shader");
- Add the crate to your dependencies:
cargo add 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("src/shaders") .compile(&"package::main".parse().unwrap()) .inspect_err(|e| eprintln!("WESL error: {e}")) // pretty errors with `display()` .unwrap() .to_string();
- Install the CLI:
cargo install wesl-cli - Compile a shader:
wesl compile <path/to/shader.wesl> > <path/to/generated-shader.wgsl> - Type
wesl --helpor visit the crate documentation for more configuration options.
Visit the Writing Shaders page to learn how to write your first WESL shaders.
Visit the Reference page for the complete documentation of WESL Extensions.