From db36e8b0b7025379b2ef9c4e49ea61127b67f9e0 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Thu, 28 Jan 2021 04:37:06 +1300 Subject: [PATCH] Move the 'core_generator' from a build script to an in-repository tool The core generator will be run manually before release. --- Cargo.toml | 13 ++++++------- core_generator/Cargo.toml | 22 ++++++++++++++++++++++ core_generator/{ => src}/gen.rs | 0 core_generator/{build.rs => src/main.rs} | 11 +++++++---- regenerate-cores.sh | 10 ++++++++++ 5 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 core_generator/Cargo.toml rename core_generator/{ => src}/gen.rs (100%) rename core_generator/{build.rs => src/main.rs} (90%) create mode 100755 regenerate-cores.sh diff --git a/Cargo.toml b/Cargo.toml index ec5231c..8f222dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,9 @@ +[workspace] +members = [ + ".", + "./core_generator", +] + [package] name = "ruduino" version = "0.2.7" @@ -15,8 +21,6 @@ description = """ Reusable components for AVR microcontrollers """ -build = "core_generator/build.rs" - keywords = ["avr", "arduino", "uno"] [features] @@ -25,8 +29,3 @@ default = ["avr-std-stub"] [dependencies] avr-std-stub = { version = "1.0", optional = true } target-cpu-macro = "0.1" - -[build-dependencies] -avr-mcu = "0.3" -target-cpu-fetch = "0.1" - diff --git a/core_generator/Cargo.toml b/core_generator/Cargo.toml new file mode 100644 index 0000000..999cad6 --- /dev/null +++ b/core_generator/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "ruduino-core-generator" +version = "0.0.0" # not versioned +publish = false +edition = "2018" +authors = [ + "The AVR-Rust Project Developers", + "Jake Goulding ", + "Dylan McKay ", +] + +license = "MIT/Apache-2.0" +readme = "README.md" +repository = "https://github.com/avr-rust/ruduino" + +[[bin]] +name = "ruduino-core-generator" +path = "src/main.rs" + +[dependencies] +avr-mcu = "0.3" +target-cpu-fetch = "0.1" diff --git a/core_generator/gen.rs b/core_generator/src/gen.rs similarity index 100% rename from core_generator/gen.rs rename to core_generator/src/gen.rs diff --git a/core_generator/build.rs b/core_generator/src/main.rs similarity index 90% rename from core_generator/build.rs rename to core_generator/src/main.rs index 18c900e..39e0e2c 100644 --- a/core_generator/build.rs +++ b/core_generator/src/main.rs @@ -14,12 +14,15 @@ const DEFAULT_MCU_FOR_NON_AVR_DOCS: &'static str = "atmega328"; const DEFAULT_FREQUENCY_HZ_FOR_NON_AVR_DOCS: u64 = 16_000_000; -fn src_path() -> PathBuf { - Path::new(env!("CARGO_MANIFEST_DIR")).join("src") +fn base_output_path() -> PathBuf { + match std::env::args().skip(1).next() { + Some(path) => Path::new(&path).to_owned(), + None => panic!("please pass a destination path for the generated cores on the command line"), + } } fn cores_path() -> PathBuf { - src_path().join("cores") + base_output_path().join("cores") } fn core_module_name(mcu: &Mcu) -> String { @@ -57,7 +60,7 @@ fn generate_cores(mcus: &[Mcu]) -> Result<(), io::Error> { } fn generate_config_module() -> Result<(), io::Error> { - let path = src_path().join("config.rs"); + let path = base_output_path().join("config.rs"); let mut f = File::create(&path)?; let clock: u64 = if cfg!(arch = "avr") { diff --git a/regenerate-cores.sh b/regenerate-cores.sh new file mode 100755 index 0000000..64b7405 --- /dev/null +++ b/regenerate-cores.sh @@ -0,0 +1,10 @@ +#! /bin/sh -ea + +set -o pipefail + +SCRIPT_DIR=$(dirname $0) + +cd "${SCRIPT_DIR}/core_generator" + +cargo run "../src" +