Added support for #[src=filename]
@@ -3,12 +3,17 @@ extern crate proc_macro;
extern crate syn;
extern crate vulkano_shaders;
+use std::path::Path;
+use std::fs::File;
+use std::io::Read;
+
use proc_macro::TokenStream;
#[proc_macro_derive(VulkanoShader, attributes(src, ty))]
pub fn derive(input: TokenStream) -> TokenStream {
let syn_item = syn::parse_macro_input(&input.to_string()).unwrap();
+ let src = {
let src = syn_item.attrs.iter().filter_map(|attr| {
match attr.value {
syn::MetaItem::NameValue(ref i, syn::Lit::Str(ref val, _)) if i == "src" => {
@@ -18,6 +23,18 @@ pub fn derive(input: TokenStream) -> TokenStream {
}
}).next().expect("Can't find `src` attribute ; put #[src = \"...\"] for example.");
+ if Path::new(&src[..]).is_file() {
+ let mut buf = String::new();
+ File::open(src).and_then(|mut file| file.read_to_string(&mut buf)).expect("Unable to read source from given file");
+ buf
+ } else {
+ src
+ }
+ };
+
+ println!("Source: {}", src);
+
+
let ty_str = syn_item.attrs.iter().filter_map(|attr| {
match attr.value {
syn::MetaItem::NameValue(ref i, syn::Lit::Str(ref val, _)) if i == "ty" => {
