-
Notifications
You must be signed in to change notification settings - Fork 1
Getting Started Rust
Mathis Brossier edited this page May 19, 2025
·
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.
- Install the CLI:
cargo install wesl-cli - Compile a shader:
wesl compile <path/to/shader.wesl> - Type
wesl --helpor visit the crate documentation for more configuration options.
- Add the crate to your build-dependencies:
cargo add --build wesl - Create the file
build.rsnext to yourCargo.toml. - Paste this content:
fn main() { wesl::Wesl::new("src/shaders").build_artifact("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 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("main.wesl") .inspect_err(|e| eprintln!("WESL error: {e}")) // pretty errors with `display()` .unwrap() .to_string();
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.