Skip to content

Commit d051e02

Browse files
committed
Move the build script into a subcrate tool
1 parent f50f378 commit d051e02

File tree

3 files changed

+63
-24
lines changed

3 files changed

+63
-24
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
[workspace]
2+
members = [
3+
".",
4+
"device_generator",
5+
]
6+
17
[package]
28
name = "avrd"
39
version = "0.3.1"

device_generator/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "avrd-device-generator"
3+
version = "0.0.0"
4+
authors = ["Dylan McKay <[email protected]>"]
5+
publish = false
6+
edition = "2018"
7+
8+
description = """
9+
Device-specific constants and information for all AVR microcontrollers
10+
"""
11+
12+
license = "MIT"
13+
repository = "https://github.com/avr-rust/avrd"
14+
documentation = "https://docs.rs/avrd"
15+
16+
[dependencies]
17+
avr-mcu = "0.3"
18+
clap = "2.33"

build.rs renamed to device_generator/src/main.rs

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
11
extern crate avr_mcu;
22

3-
use std::path::Path;
3+
use clap::{App, Arg};
44

5-
fn main() {
6-
let crate_root = Path::new(env!("CARGO_MANIFEST_DIR"));
7-
8-
let mcus = if cfg!(feature = "all_mcus") {
9-
avr_mcu::microcontrollers().to_owned()
10-
} else {
11-
// By default, when compiling for AVR we should hard error if
12-
// microcontroller is not specified.
13-
if cfg!(arch = "avr") {
14-
let current_mcu = avr_mcu::current::mcu()
15-
.expect("no target cpu set");
16-
vec![current_mcu]
17-
} else {
18-
// On non-avr architectures, support all microcontrollers.
19-
avr_mcu::microcontrollers().to_owned()
20-
}
21-
};
5+
use std::path::{Path, PathBuf};
6+
7+
#[derive(Clone, Debug)]
8+
struct Config {
9+
output_directory: PathBuf,
10+
mcus: Vec<avr_mcu::Mcu>,
11+
}
2212

23-
// Useful for test
24-
// let mcus = vec![
25-
// avr_mcu::microcontroller("ata5795").clone(),
26-
// avr_mcu::microcontroller("atmega328").clone(), // required when compiling for PC
27-
// ];
13+
fn get_cli_config() -> Config {
14+
let matches = App::new(env!("CARGO_PKG_NAME"))
15+
.version("1.0")
16+
.author(env!("CARGO_PKG_AUTHORS"))
17+
.about(env!("CARGO_PKG_DESCRIPTION"))
18+
.arg(Arg::with_name("out-dir")
19+
.short("o")
20+
.long("out-dir")
21+
.value_name("DIRECTORY")
22+
.help("Sets the directory path that will contain the newly generated Rust source code files")
23+
.takes_value(true)
24+
.required(true))
25+
.arg(Arg::with_name("mcus")
26+
.short("m")
27+
.long("mcus")
28+
.value_name("COMMA SEPARATED MCU LIST")
29+
.help("Generate outputs for a specific microcontroller or microcontrollers rather than the default of all")
30+
.takes_value(true))
31+
.get_matches();
32+
let output_directory = Path::new(matches.value_of("out-dir").unwrap()).to_owned();
33+
34+
let mcus = matches.values_of("mcus")
35+
.map(|m| m.flat_map(|a| a.split(",").map(|s| avr_mcu::microcontroller(s).clone())).collect())
36+
.unwrap_or_else(|| avr_mcu::microcontrollers().to_owned() );
37+
38+
Config { output_directory, mcus }
39+
}
40+
41+
fn main() {
42+
let config = get_cli_config();
2843

29-
gen::all(&crate_root.join("src").join("gen"), &mcus).unwrap();
44+
gen::all(&config.output_directory, &config.mcus).unwrap();
3045
}
3146

3247
mod gen {

0 commit comments

Comments
 (0)