Getting Started Rust - wgsl-tooling-wg/wesl-spec GitHub Wiki

WESL is designed to work with both JavaScript and Rust. We have two distinct implementations for these languages, wesl-js and wesl-rs.

Wesl can be operated in a few different ways:

  • Using the standalone Command-Line tool to generate WGSL files.
  • At build-time, using a Vite Plugin (JavaScript) or a Build Script (Rust).
  • At run-time, using the linker libraries.

wesl-rs documentation: (TODO link)

Using the standalone CLI

  • Install the CLI: cargo install --git https://github.com/wgsl-tooling-wg/wesl-rs wesl-cli
  • Compile a shader: wesl compile <path/to/shader.wesl>
  • Type wesl --help or visit the crate documentation (coming soon) for more configuration options.

Using wesl-rs at compile-time

  • Add wesl-rs to your build-dependencies: cargo add --git https://github.com/wgsl-tooling-wg/wesl-rs --build wesl
  • Create the file build.rs right next to your Cargo.toml.
  • Paste this content:
    fn main() {
        wesl::Wesl::new_spec_compliant("src/shaders").build_artefact("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 wesl-rs to your dependencies: cargo add --git https://github.com/wgsl-tooling-wg/wesl-rs 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_spec_compliant("src/shaders")
        .compile("main.wesl")
        .inspect_err(|e| eprintln!("WESL error: {e}")) // pretty errors with `display()`
        .unwrap()
        .to_string();
    

Next Steps

Visit the Authoring Shaders page to learn how to write your first WESL shaders.

Visit the Reference page for the complete documentation of WESL Extensions.