mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 09:31:34 +11:00
Start switching to the quote crate for generating the code
This commit is contained in:
parent
19e0a0527b
commit
d7a24d9659
2
agb-image-converter/Cargo.lock
generated
2
agb-image-converter/Cargo.lock
generated
|
@ -13,6 +13,8 @@ name = "agb_image_converter"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"image",
|
"image",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
"serde",
|
"serde",
|
||||||
"syn",
|
"syn",
|
||||||
"toml",
|
"toml",
|
||||||
|
|
|
@ -13,4 +13,6 @@ proc-macro = true
|
||||||
image = { version = "0.23.14", default-features = false, features = [ "png", "bmp" ] }
|
image = { version = "0.23.14", default-features = false, features = [ "png", "bmp" ] }
|
||||||
toml = "0.5.8"
|
toml = "0.5.8"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
syn = "1.0.73"
|
syn = "1.0.73"
|
||||||
|
proc-macro2 = "1.0.27"
|
||||||
|
quote = "1.0.9"
|
|
@ -1,9 +1,10 @@
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use syn::parse_macro_input;
|
use syn::parse_macro_input;
|
||||||
|
|
||||||
use std::fmt::Write;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
use quote::{quote, format_ident};
|
||||||
|
|
||||||
mod colour;
|
mod colour;
|
||||||
mod config;
|
mod config;
|
||||||
mod image_loader;
|
mod image_loader;
|
||||||
|
@ -43,30 +44,23 @@ pub fn include_gfx(input: TokenStream) -> TokenStream {
|
||||||
|
|
||||||
let config = config::parse(&path.to_string_lossy());
|
let config = config::parse(&path.to_string_lossy());
|
||||||
|
|
||||||
let module_name = path.file_stem().expect("Expected a file stem");
|
let module_name = format_ident!("{}", path.file_stem().expect("Expected a file stem").to_string_lossy());
|
||||||
|
let include_path = path.to_string_lossy();
|
||||||
|
|
||||||
let mut output = String::new();
|
let images = config.images();
|
||||||
|
let image_code = images
|
||||||
|
.iter()
|
||||||
|
.map(|(image_name, &image)| convert_image(image, parent, &image_name, &config.crate_prefix()).parse::<proc_macro2::TokenStream>().unwrap());
|
||||||
|
|
||||||
writeln!(&mut output, "mod {} {{", module_name.to_string_lossy()).unwrap();
|
let module = quote! {
|
||||||
writeln!(
|
pub mod #module_name {
|
||||||
&mut output,
|
const _: &[u8] = include_bytes!(#include_path);
|
||||||
"const _: &[u8] = include_bytes!(\"{}\");",
|
|
||||||
path.to_string_lossy()
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
for (image_name, image) in config.images() {
|
#(#image_code)*
|
||||||
writeln!(
|
}
|
||||||
&mut output,
|
};
|
||||||
"{}",
|
|
||||||
convert_image(image, parent, &image_name, &config.crate_prefix())
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
writeln!(&mut output, "}}").unwrap();
|
TokenStream::from(module)
|
||||||
|
|
||||||
output.parse().expect("Failed to generate valid rust code")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_image(
|
fn convert_image(
|
||||||
|
|
2
agb/Cargo.lock
generated
2
agb/Cargo.lock
generated
|
@ -21,6 +21,8 @@ name = "agb_image_converter"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"image",
|
"image",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
"serde",
|
"serde",
|
||||||
"syn",
|
"syn",
|
||||||
"toml",
|
"toml",
|
||||||
|
|
Loading…
Reference in a new issue