Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo-make script. #563

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[config]
default_to_workspace = false

[tasks.default]
alias = "run_tests"

[tasks.run_tests]
# Builds the required packages, using the correct settings. Mirrors what the github CI does.
script_runner = "@rust"
script = { file = "makefile.rs" }
127 changes: 127 additions & 0 deletions makefile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//! ```cargo
//! [dependencies]
//! owo-colors = "*"
//! ```

#![allow(unused_assignments)]

use owo_colors::OwoColorize;
use std::process::{Command, ExitCode};

#[derive(Debug)]
enum CompilationType {
// Name, examples
Board(&'static str, bool),
// Name, spec, crate
Mcu(&'static str, &'static str, &'static str),
}

fn main() -> ExitCode {
// Matrix elements
let matrix = vec![
CompilationType::Board("arduino-uno", true),
CompilationType::Board("arduino-diecimila", true),
CompilationType::Board("arduino-leonardo", true),
CompilationType::Board("arduino-mega2560", true),
CompilationType::Board("arduino-mega1280", true),
CompilationType::Board("sparkfun-promicro", true),
CompilationType::Board("sparkfun-promini-3v3", true),
CompilationType::Board("sparkfun-promini-5v", true),
CompilationType::Board("trinket-pro", true),
CompilationType::Board("trinket", true),
CompilationType::Board("arduino-nano", true),
CompilationType::Board("nano168", true),
CompilationType::Board("atmega2560", true),
// MCU Time
CompilationType::Mcu("atmega1280", "atmega1280", "atmega-hal"),
CompilationType::Mcu("atmega32a", "atmega32a", "atmega-hal"),
CompilationType::Mcu("atmega128a", "atmega128a", "atmega-hal"),
CompilationType::Mcu("atmega328pb", "atmega328p", "atmega-hal"),
CompilationType::Mcu("atmega48p", "atmega48p", "atmega-hal"),
CompilationType::Mcu("atmega1284p", "atmega1284p", "atmega-hal"),
CompilationType::Mcu("atmega8", "atmega8", "atmega-hal"),
CompilationType::Mcu("attiny85", "attiny85", "attiny-hal"),
CompilationType::Mcu("attiny88", "attiny88", "attiny-hal"),
CompilationType::Mcu("attiny167", "attiny167", "attiny-hal"),
CompilationType::Mcu("attiny2313", "attiny2313", "attiny-hal"),
];

let mut status = Vec::new();
let mut error_len = 0;

for comp in matrix {
let mut directory = String::new();
let mut args = Vec::new();
let spec_str;
match comp {
CompilationType::Board(name, examples) => {
if examples {
directory = format!("examples/{}", name);
args = vec!["build", "--bins"];
} else {
directory = "arduino-hal/".to_string();
args = vec!["build", "--features", name]
}
}
CompilationType::Mcu(name, spec, run_crate) => {
directory = format!("mcu/{}", run_crate);
spec_str = format!("../../avr-specs/avr-{}.json", spec);
args = vec![
"build",
"--features",
name,
"-Z",
"build-std=core",
"--target",
&spec_str,
]
}
}

println!("=== {} ===", "Building".magenta().bold());
println!("{} {:?}", "Type:".yellow(), comp);
println!("{} {}", "Directory:".yellow(), directory);
println!("{} {:?}", "Args:".yellow(), args);

// Run cargo with the args, and directory attached
let mut child = Command::new("cargo")
.args(args)
.current_dir(directory)
.spawn()
.expect("Something fucked up.");
let res = child.wait().unwrap();

if !res.success() {
println!("Exited with code: {}", res.bold());
status.push((false, res.code().unwrap(), comp));
error_len += 1;
continue;
}
status.push((true, 0, comp));
// println!("--- {} ---", "BUILT".green().bold());
}

println!("");

let length = status.len();
println!(
"{} {} out of {} built.",
"Finished!".green().bold(),
length - error_len,
length.underline()
);
for (success, _code, details) in status {
let name = match details {
CompilationType::Board(name, _) => name,
CompilationType::Mcu(name, _, _) => name,
};

if success {
println!("{}... {}", name.italic(), "SUCCESS".green().bold());
} else {
println!("{}... {}", name.italic(), "FAIL".red().bold());
}
}

ExitCode::SUCCESS
}