pub struct Compiler<R = ()> {
pub options: CompileOptions,
pub resolver: R,
}Expand description
The WESL compiler.
§Basic Usage
let compiler = Compiler::default();
let wgsl_string = compiler
.compile("path/to/shader.wgsl")
.inspect_err(|e| eprintln!("{e}")) // pretty-print errors
.unwrap()
.to_string();Fields§
§options: CompileOptions§resolver: RImplementations§
Source§impl<R1> Compiler<R1>
impl<R1> Compiler<R1>
Sourcepub fn with_resolver<R2>(self, resolver: R2) -> Compiler<R2>
pub fn with_resolver<R2>(self, resolver: R2) -> Compiler<R2>
Set the compilation crate::Resolver or crate::AsyncResolver.
Source§impl<R> Compiler<R>
impl<R> Compiler<R>
Sourcepub fn new_with_resolver(options: CompileOptions, resolver: R) -> Self
pub fn new_with_resolver(options: CompileOptions, resolver: R) -> Self
Shorthand for Compiler::new(options).with_resolver(resolver).
Source§impl Compiler<()>
impl Compiler<()>
Sourcepub fn new(options: CompileOptions) -> Self
pub fn new(options: CompileOptions) -> Self
Create a new compiler.
By default, the compiler will use a StandardResolver when compiling.
Source§impl Compiler<()>
impl Compiler<()>
Sourcepub fn compile(&self, path: impl AsRef<Path>) -> Result<CompileResult, Error>
pub fn compile(&self, path: impl AsRef<Path>) -> Result<CompileResult, Error>
Compile a WESL shader to WGSL.
path defines where to look for shader files.
It can point to a wesl.toml file, a directory or a shader file.
The main module (which exposes entry points, bindings and overrides) is determined from path:
It is the package root module if path points to a toml file or a directory,
otherwise it is the file that path points to.
See Self::compile_module to compile a different main module.
| Path | Package root directory | Main module |
|---|---|---|
wesl.toml | root field in wesl.toml | package.wesl in root dir |
| directory | the directory | package.wesl in root dir |
.wesl file | the parent directory | the file specified |
Note: .wgsl extensions are also supported, but .wesl takes priority.
Sourcepub fn compile_module(
&self,
pkg_root_dir: impl AsRef<Path>,
main_path: &ModulePath,
) -> Result<CompileResult, Error>
pub fn compile_module( &self, pkg_root_dir: impl AsRef<Path>, main_path: &ModulePath, ) -> Result<CompileResult, Error>
Variant of Self::compile with a custom main module path.
Sourcepub async fn compile_async(&self, path: &Path) -> Result<CompileResult, Error>
pub async fn compile_async(&self, path: &Path) -> Result<CompileResult, Error>
Async version of Self::compile.
Sourcepub async fn compile_module_async(
&self,
pkg_root_dir: impl AsRef<Path>,
main_path: &ModulePath,
) -> Result<CompileResult, Error>
pub async fn compile_module_async( &self, pkg_root_dir: impl AsRef<Path>, main_path: &ModulePath, ) -> Result<CompileResult, Error>
Async version of Self::compile_module.
Source§impl<R: Resolver> Compiler<R>
impl<R: Resolver> Compiler<R>
Sourcepub fn compile_root(&self) -> Result<CompileResult, Error>
pub fn compile_root(&self) -> Result<CompileResult, Error>
Compile a WESL shader to WGSL.
The main module defaults to the package root module.
See Self::compile_module to compile a different main module.
Sourcepub fn compile_module(
&self,
main_path: &ModulePath,
) -> Result<CompileResult, Error>
pub fn compile_module( &self, main_path: &ModulePath, ) -> Result<CompileResult, Error>
Variant of Self::compile with a custom main module path.
Sourcepub fn compile(
&self,
fs_main_path: impl AsRef<Path>,
) -> Result<CompileResult, Error>
pub fn compile( &self, fs_main_path: impl AsRef<Path>, ) -> Result<CompileResult, Error>
Variant of Self::compile_root with a custom main module path.
fs_main_path defines the main module path according to the resolver’s file system mapping implemented in Resolver::module_path.
§Warning
This function works best with filesystem resolvers which implement Resolver::module_path.
If not, this function assumes that the package root directory is the current working directory.
§Panics
Can panic if ModulePath::from_path fails.
Sourcepub async fn compile_root_async(&self) -> Result<CompileResult, Error>
pub async fn compile_root_async(&self) -> Result<CompileResult, Error>
Async version of Self::compile_root.
Sourcepub async fn compile_module_async(
&self,
main_path: &ModulePath,
) -> Result<CompileResult, Error>
pub async fn compile_module_async( &self, main_path: &ModulePath, ) -> Result<CompileResult, Error>
Async version of Self::compile_module.
Sourcepub async fn compile_async(
&self,
fs_main_path: &impl AsRef<Path>,
) -> Result<CompileResult, Error>
pub async fn compile_async( &self, fs_main_path: &impl AsRef<Path>, ) -> Result<CompileResult, Error>
Async version of Self::compile.
Trait Implementations§
Auto Trait Implementations§
impl<R> Freeze for Compiler<R>where
R: Freeze,
impl<R> RefUnwindSafe for Compiler<R>where
R: RefUnwindSafe,
impl<R> Send for Compiler<R>where
R: Send,
impl<R> Sync for Compiler<R>where
R: Sync,
impl<R> Unpin for Compiler<R>where
R: Unpin,
impl<R> UnsafeUnpin for Compiler<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for Compiler<R>where
R: UnwindSafe,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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