From 339679b826bab119e98b31b1d0eefb03e147f9e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 24 Nov 2021 15:30:29 +0100 Subject: [PATCH] rom: build.rs script to generate Pokemon structs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- rom/Cargo.toml | 9 +++++++++ rom/build.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 rom/Cargo.toml create mode 100644 rom/build.rs diff --git a/rom/Cargo.toml b/rom/Cargo.toml new file mode 100644 index 0000000..ea4ec26 --- /dev/null +++ b/rom/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "rom" +version = "0.1.0" +authors = ["Maxime “pep” Buquet "] +edition = "2021" +license = "AGPL-3.0-or-later" + +[build-dependencies] +quote = "1.0" diff --git a/rom/build.rs b/rom/build.rs new file mode 100644 index 0000000..cf5456c --- /dev/null +++ b/rom/build.rs @@ -0,0 +1,43 @@ +// Copyright (C) 2021 "Maxime “pep” Buquet " +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU Affero General Public License as published by the +// Free Software Foundation, either version 3 of the License, or (at your +// option) any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License +// for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +use std::fs::File; +use std::io::{BufWriter, Write}; +use std::path::Path; + +use quote::{format_ident, quote}; + +fn main() { + let output = Path::new(&env::var("OUT_DIR").unwrap()).join("output.rs"); + let mut output = BufWriter::new(File::create(&output).unwrap()); + + let pkmn_names: Vec<_> = [ + "Rhydon", + "Kangashkan", + "NidoranM", + ].iter() + .map(|n| format_ident!("{}", n)) + .collect(); + + let tokens = quote! { + /// Generated file containing various resources extracted from the provided ROM. + + pub enum PokemonNames { + #(#pkmn_names),* + } + }; + + write!(output, "{}", tokens).unwrap(); +}