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> >> <path/to/generated-shader.wgsl - Type
wesl --helpor 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 - 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");
#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(&"package::main".parse().unwrap()) .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.