pub struct ShaderBuild { /* private fields */ }Expand description
One crate’s shader-binding generation, run from its build script.
Implementations§
Source§impl ShaderBuild
impl ShaderBuild
Sourcepub fn discover(shader_root: impl AsRef<Path>) -> Result<Self, ShaderBuildError>
pub fn discover(shader_root: impl AsRef<Path>) -> Result<Self, ShaderBuildError>
Returns a build of every .wgsl file under shader_root without a #define_import_path line.
A symlink to a directory is followed, and a directory reached twice is walked once. Note that the build stamp of
stamp_commit follows no such link, and an edit to a shader in a linked directory changes no stamp.
§Errors
Returns ShaderBuildError that lists the files. Files that are not .wgsl are never checked.
ShaderBuildError::InvalidNamefor a.wgslpath below the root with a component that is not a Rust identifier or is a keyword, and for an entry point whoseShaderEntryvariant is not a Rust identifier (self_.wgslgivesSelf).ShaderBuildError::NameCollisionfor two entry points whose module paths,ShaderEntryvariants or binding constants collide, and for an entry point whose module contains another entry point’s module.ShaderBuildError::ReservedNamefor a file namedhenad.wgslor a directory namedhenadholding a.wgslfile at any depth under the root, for a.wgslpath starting with a name the generated bindings use, and for a root whose last component ishenad.ShaderBuildError::Iofor a file or directory that cannot be read.
Sourcepub fn new(shader_root: impl AsRef<Path>) -> Self
pub fn new(shader_root: impl AsRef<Path>) -> Self
Returns a build with no entry points until Self::entry_point adds them.
Sourcepub fn entry_point(self, path: impl AsRef<Path>) -> Self
pub fn entry_point(self, path: impl AsRef<Path>) -> Self
Adds the entry point path, relative to the shader root.
Note that the path is checked when Self::generate runs, in the same way as a discovered entry point: it lies
under the root, and each of its components is a Rust identifier and not a keyword.
Sourcepub fn generate(self) -> Result<(), ShaderBuildError>
pub fn generate(self) -> Result<(), ShaderBuildError>
Writes shader_bindings.rs and binding_decls.rs to OUT_DIR, each only when its bytes change.
Prints a cargo:rerun-if-changed line for the shader root, which Cargo watches recursively, one for each entry
point Self::entry_point added, and one for each file outside the root that an entry point imports. No line
refers to a path under OUT_DIR.
§Errors
Returns ShaderBuildError in these cases:
ShaderBuildError::EnvironmentwhenOUT_DIRis not set, andShaderBuildError::Iofor a file that cannot be read or written.ShaderBuildError::ReservedNamefor a shader root whose last component ishenador a reserved name under the root, andShaderBuildError::ReservedImportfor a module imported under a reserved name.ShaderBuildError::OutsideRootfor an entry point outside the root, andShaderBuildError::InvalidNameorShaderBuildError::NameCollisionfor an entry point whose path gives no Rust name or repeats another entry’s name.ShaderBuildError::BindingLine,ShaderBuildError::UnsupportedBinding,ShaderBuildError::ModuleBindingandShaderBuildError::BindingGapfor bindings that the reader rejects.ShaderBuildError::Composefor a shader that does not compose.