wesl_core/lib.rs
1#![doc = include_str!("../README.md")]
2
3/// Include a WGSL file compiled with [`wesl::CompileResult::write_artifact`](https://docs.rs/wesl/latest/wesl/struct.CompileResult.html#method.write_artifact) as a string.
4///
5/// The argument corresponds to the `artifact_name` passed to `write_artifact`.
6///
7/// This is a very simple convenience macro. See the crate documentation for a usage
8/// example.
9#[macro_export]
10macro_rules! include_wesl {
11 ($artifact_name:literal) => {
12 include_str!(concat!(env!("OUT_DIR"), "/", $artifact_name, ".wgsl"))
13 };
14}
15
16/// The type holding the source code of external packages.
17///
18/// You typically don't implement this, instead it is generated for you by [`wesl::PackageBuilder`](https://docs.rs/wesl/latest/wesl/package/struct.PackageBuilder.html).
19/// Crates containing shader packages export `const` instances of this type, which you can
20/// then import and [add to your resolver](https://docs.rs/wesl/latest/wesl/struct.StandardResolver.html#method.add_package).
21#[derive(Debug, PartialEq, Eq)]
22pub struct StaticPackage {
23 pub crate_name: &'static str,
24 pub root: &'static StaticPackageModule,
25 pub dependencies: &'static [&'static StaticPackage],
26}
27
28/// The type holding the source code of modules in external packages.
29///
30/// See [`StaticPackage`].
31#[derive(Debug, PartialEq, Eq)]
32pub struct StaticPackageModule {
33 pub name: &'static str,
34 pub source: &'static str,
35 pub submodules: &'static [&'static StaticPackageModule],
36}
37
38/// Include a generated package.
39///
40/// Generates a module containing the code generated by the packager.
41///
42/// See [`wesl::PackageBuilder`](https://docs.rs/wesl/latest/wesl/package/struct.PackageBuilder.html) for more information about building WESL packages.
43///
44/// ```rust,ignore
45/// # use wesl::wesl_pkg;
46/// // Load package in `OUT_DIR/my_package.rs`
47/// wesl_pkg!(my_package);
48///
49/// // make module `pub`
50/// wesl_pkg!(pub my_package);
51///
52/// // add module attributes
53/// wesl_pkg!(#[allow(clippy::all)] pub my_package);
54/// ```
55#[macro_export]
56macro_rules! wesl_pkg {
57 ($(#[$attr:meta])* $vis:vis $pkg_name:ident) => {
58 $crate::wesl_pkg!($(#[$attr])* $vis $pkg_name, concat!(stringify!($pkg_name), ".rs"));
59 };
60 ($(#[$attr:meta])* $vis:vis $pkg_name:ident, $source:expr) => {
61 $(#[$attr])* $vis mod $pkg_name {
62 #![allow(non_snake_case)]
63 use $crate::{StaticPackageModule, StaticPackage};
64 include!(concat!(env!("OUT_DIR"), "/", $source));
65 }
66 };
67 }