Skip to content

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.

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.rs next to your Cargo.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();

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 --help or visit the crate documentation for more configuration options.

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.

Documentation has moved → wesl-lang.dev

This wiki is no longer maintained.

Clone this wiki locally