Files
Graphite/node-graph/node-macro/src/crate_ident.rs
T
Keavon Chambers b39ec01d7d Retire Rust GPU, the 'Upload Texture' node, and the "GPU"-suffixed adjustment node twins (#4873)
* Retire the rust-gpu twins of the adjustment nodes, leaving rust-gpu dormant

* Remove the dormant rust-gpu shader crate and everything that supported it
2026-10-30 17:52:29 -07:00

40 lines
1.1 KiB
Rust

use proc_macro_crate::{FoundCrate, crate_name};
use proc_macro2::{Span, TokenStream};
use quote::{format_ident, quote};
pub struct CrateIdent {
gcore: syn::Result<TokenStream>,
graphene_core: syn::Result<TokenStream>,
}
impl CrateIdent {
pub fn gcore(&self) -> syn::Result<&TokenStream> {
self.gcore.as_ref().map_err(Clone::clone)
}
pub fn graphene_core(&self) -> syn::Result<&TokenStream> {
self.graphene_core.as_ref().map_err(Clone::clone)
}
}
impl Default for CrateIdent {
fn default() -> Self {
let find_crate = |orig_name| match crate_name(orig_name) {
Ok(FoundCrate::Itself) => Ok(quote!(crate)),
Ok(FoundCrate::Name(name)) => {
let name = format_ident!("{}", name);
Ok(quote!(::#name))
}
Err(e) => Err(syn::Error::new(Span::call_site(), format!("Could not find dependency on `{orig_name}`:\n{e}"))),
};
let gcore = find_crate("core-types");
let graphene_core = find_crate("graphene-core").or_else(|ecore| {
find_crate("graphene-std")
.map(|gstd| quote!(#gstd::graphene_core))
.map_err(|estd| syn::Error::new(Span::call_site(), format!("{ecore}\n\nFallback: {estd}")))
});
Self { gcore, graphene_core }
}
}