include_wgsl

Crates.ioinclude_wgsl
lib.rsinclude_wgsl
version1.1.1
sourcesrc
created_at2021-04-29 14:55:01.518507
updated_at2021-10-11 05:57:28.060786
descriptionA tiny proc macro to include a WGSL file in your binary, and verify that it is valid at compile time.
homepage
repositoryhttps://github.com/ashpil/include_wgsl
max_upload_size
id391089
size8,461
Andrei Shpilenok (ashpil)

documentation

README

include_wgsl

Crates.io Docs.rs

A tiny proc macro to include a WGSL file in your binary, and verify that it is valid at compile time.

Example

This is how you might create a wgpu shader module:

let shader_str = include_wgsl!("shader.wgsl");
device.create_shader_module(&ShaderModuleDescriptor {
    source: ShaderSource::Wgsl(Cow::Borrowed(&shader_str)),
    flags: ShaderFlags::default(),
    label: None,
})

This functions exactly as it would if you had used include_str!("shader.wgsl"), but it also makes sure at compile time that your WGSL is valid using naga.

If your WGSL code is valid, compliation continues on, but if your WGSL is invalid, you will get a friendly naga error, and compliation will halt:

error: Unable to parse shader.wgsl

error: invalid field accessor `world_positoon`
   ┌─ wgsl:33:9
   │
33 │     out.world_positoon = world_position.xyz;
   │         ^^^^^^^^^^^^^^ invalid accessor

The syntax errors are typically pretty understandable, but at the moment naga validation errors are a bit dense. I do not consider improving them part of the scope of this project, but will happily update this crate once naga has made them more approachable.

Nightly

This crate is currently nightly-only. If I have to choose between nightly or fewer dependencies, I choose nightly, and I have adhered to that philosophy in this crate.

Commit count: 15

cargo fmt