pub struct PackageBuilder { /* private fields */ }Expand description
A builder that generates code for WESL packages.
WESL packages are bundles of shader files that can be reused in other projects, like
Rust crates. See the consumer example to see how to use them.
This type is mainly designed to be used in a build script (build.rs file). Add wesl
to the build-dependencies of your project and enable the package feature flag.
§Usage
// in build.rs
fn main() {
wesl::package::PackageBuilder::new("my_package")
// read all wesl files in the directory "src/shaders"
.scan_root("src/shaders")
.expect("failed to scan WESL files")
// validation is optional
.validate()
.inspect_err(|e| eprintln!("{e}"))
.expect("validation error")
// write "my_package.rs" in OUT_DIR
.build_artifact()
.expect("failed to build artifact");
}Then, in your lib.rs file, expose the generated module with the wesl_core::wesl_pkg macro.
wesl::wesl_pkg!(pub my_package);The package name must be a valid rust identifier, E.g. it must not contain dashes -.
Dashes are replaced with underscores _.
Implementations§
Source§impl PackageBuilder
impl PackageBuilder
pub fn new(name: &str) -> Self
Sourcepub fn add_package(self, pkg: &'static StaticPackage) -> Self
pub fn add_package(self, pkg: &'static StaticPackage) -> Self
Add a package dependency.
Learn more about packages in PackageBuilder.
Sourcepub fn add_packages(
self,
pkgs: impl IntoIterator<Item = &'static StaticPackage>,
) -> Self
pub fn add_packages( self, pkgs: impl IntoIterator<Item = &'static StaticPackage>, ) -> Self
Add several package dependencies.
Learn more about packages in PackageBuilder.
Sourcepub fn scan_root(
self,
pkg_root_dir: impl AsRef<Path>,
) -> Result<Package, ScanDirectoryError>
pub fn scan_root( self, pkg_root_dir: impl AsRef<Path>, ) -> Result<Package, ScanDirectoryError>
Read all files to include in the package, starting from the package root directory.
The package will include all .wesl and .wgsl files reachable from the package root, recursively.
Sourcepub fn scan_toml(
self,
toml_path: impl AsRef<Path>,
) -> Result<Package, TomlError>
pub fn scan_toml( self, toml_path: impl AsRef<Path>, ) -> Result<Package, TomlError>
Reads a wesl.toml file and builds a package from its configuration.
The wesl.toml file should be located in the given directory and contain:
edition(required),root,include,excludeas top-level keys[dependencies]section (optional)
§Example
wesl::package::PackageBuilder::new("my_package")
.scan_toml(".") // looks for ./wesl.toml
.expect("failed to scan WESL files")
.build_artifact()
.expect("failed to build artifact");Auto Trait Implementations§
impl Freeze for PackageBuilder
impl RefUnwindSafe for PackageBuilder
impl Send for PackageBuilder
impl Sync for PackageBuilder
impl Unpin for PackageBuilder
impl UnsafeUnpin for PackageBuilder
impl UnwindSafe for PackageBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more