Skip to main content

PackageBuilder

Struct PackageBuilder 

Source
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

Source

pub fn new(name: &str) -> Self

Source

pub fn add_package(self, pkg: &'static StaticPackage) -> Self

Add a package dependency.

Learn more about packages in PackageBuilder.

Source

pub fn add_packages( self, pkgs: impl IntoIterator<Item = &'static StaticPackage>, ) -> Self

Add several package dependencies.

Learn more about packages in PackageBuilder.

Source

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.

Source

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, exclude as 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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.