bevy_render_macros/
lib.rs1#![allow(missing_docs, reason = "Not all docs are written yet, see #3492.")]
3#![cfg_attr(docsrs, feature(doc_auto_cfg))]
4
5mod as_bind_group;
6mod extract_component;
7mod extract_resource;
8
9use bevy_macro_utils::{derive_label, BevyManifest};
10use proc_macro::TokenStream;
11use quote::format_ident;
12use syn::{parse_macro_input, DeriveInput};
13
14pub(crate) fn bevy_render_path() -> syn::Path {
15 BevyManifest::default()
16 .maybe_get_path("bevy_render")
17 .unwrap_or_else(|| BevyManifest::parse_str("crate"))
19}
20
21#[proc_macro_derive(ExtractResource)]
22pub fn derive_extract_resource(input: TokenStream) -> TokenStream {
23 extract_resource::derive_extract_resource(input)
24}
25
26#[proc_macro_derive(ExtractComponent, attributes(extract_component_filter))]
54pub fn derive_extract_component(input: TokenStream) -> TokenStream {
55 extract_component::derive_extract_component(input)
56}
57
58#[proc_macro_derive(
59 AsBindGroup,
60 attributes(uniform, storage_texture, texture, sampler, bind_group_data, storage)
61)]
62pub fn derive_as_bind_group(input: TokenStream) -> TokenStream {
63 let input = parse_macro_input!(input as DeriveInput);
64
65 as_bind_group::derive_as_bind_group(input).unwrap_or_else(|err| err.to_compile_error().into())
66}
67
68#[proc_macro_derive(RenderLabel)]
72pub fn derive_render_label(input: TokenStream) -> TokenStream {
73 let input = parse_macro_input!(input as DeriveInput);
74 let mut trait_path = bevy_render_path();
75 trait_path
76 .segments
77 .push(format_ident!("render_graph").into());
78 let mut dyn_eq_path = trait_path.clone();
79 trait_path
80 .segments
81 .push(format_ident!("RenderLabel").into());
82 dyn_eq_path.segments.push(format_ident!("DynEq").into());
83 derive_label(input, "RenderLabel", &trait_path, &dyn_eq_path)
84}
85
86#[proc_macro_derive(RenderSubGraph)]
90pub fn derive_render_sub_graph(input: TokenStream) -> TokenStream {
91 let input = parse_macro_input!(input as DeriveInput);
92 let mut trait_path = bevy_render_path();
93 trait_path
94 .segments
95 .push(format_ident!("render_graph").into());
96 let mut dyn_eq_path = trait_path.clone();
97 trait_path
98 .segments
99 .push(format_ident!("RenderSubGraph").into());
100 dyn_eq_path.segments.push(format_ident!("DynEq").into());
101 derive_label(input, "RenderSubGraph", &trait_path, &dyn_eq_path)
102}