Getting Started Rust
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.
#Using the standalone CLI
- Install the CLI:
cargo install wesl-cli
- Compile a shader:
wesl compile <path/to/shader.wesl>
- Type
wesl --help
or visit the crate documentation for more configuration options.
#Using wesl-rs
at compile-time
- Add the crate to your build-dependencies:
cargo add --build wesl
- Create the file
build.rs
next 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");
#Using wesl-rs
at run-time
- 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();
#Next Steps
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.