Skip to content

Commit

Permalink
Allow setting features for specific chips
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Sep 17, 2024
1 parent 0107e66 commit d9d7b6b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 17 deletions.
1 change: 1 addition & 0 deletions esp-metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub enum Cores {
Eq,
PartialOrd,
Ord,
Hash,
serde::Deserialize,
serde::Serialize,
strum::Display,
Expand Down
68 changes: 51 additions & 17 deletions xtask/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
collections::VecDeque,
collections::{HashMap, VecDeque},
fs::{self, File},
io::Write as _,
path::{Path, PathBuf},
Expand Down Expand Up @@ -157,30 +157,56 @@ pub fn load_examples(path: &Path, action: CargoAction) -> Result<Vec<Metadata>>

let mut chips = Chip::iter().collect::<Vec<_>>();
let mut feature_sets = Vec::new();
let mut chip_features = HashMap::new();

// We will indicate metadata lines using the `//%` prefix:
for line in text.lines().filter(|line| line.starts_with("//%")) {
let Some((key, value)) = line.trim_start_matches("//%").split_once(':') else {
bail!("Metadata line is missing ':': {}", line);
};

match key.trim() {
"CHIPS" => {
chips = value
.split_ascii_whitespace()
.map(|s| Chip::from_str(s, false).unwrap())
.collect::<Vec<_>>();
let key = key.trim();

if key == "CHIPS" {
chips = value
.split_ascii_whitespace()
.map(|s| Chip::from_str(s, false).unwrap())
.collect::<Vec<_>>();
} else if key == "FEATURES" {
// Base feature set required to run the example.
// If multiple are specified, we compile the same example multiple times.
let mut values = value
.split_ascii_whitespace()
.map(ToString::to_string)
.collect::<Vec<_>>();

// Sort the features so they are in a deterministic order:
values.sort();

feature_sets.push(values);
} else if key.starts_with("CHIP-FEATURES(") {
// Additional features required for specific chips.
// These are appended to the base feature set(s).
// If multiple are specified, the last entry wins.
let chips = key
.trim_start_matches("CHIP-FEATURES(")
.trim_end_matches(')');

let chips = chips
.split_ascii_whitespace()
.map(|s| Chip::from_str(s, false).unwrap())
.collect::<Vec<_>>();

let values = value
.split_ascii_whitespace()
.map(ToString::to_string)
.collect::<Vec<_>>();

for chip in chips {
chip_features.insert(chip, values.clone());
}
"FEATURES" => {
let mut values = value
.split_ascii_whitespace()
.map(ToString::to_string)
.collect::<Vec<_>>();
// Sort the features so they are in a deterministic order:
values.sort();
feature_sets.push(values);
}
other => log::warn!("Unrecognized metadata key '{other}', ignoring"),
} else {
log::warn!("Unrecognized metadata key '{key}', ignoring");
}
}

Expand All @@ -195,6 +221,14 @@ pub fn load_examples(path: &Path, action: CargoAction) -> Result<Vec<Metadata>>
}
for feature_set in feature_sets {
for chip in &chips {
let mut feature_set = feature_set.clone();
if let Some(chip_features) = chip_features.get(chip) {
feature_set.extend(chip_features.iter().cloned());

// Sort the features so they are in a deterministic order:
feature_set.sort();
}

examples.push(Metadata::new(&path, *chip, feature_set.clone()));
}
}
Expand Down

0 comments on commit d9d7b6b

Please sign in to comment.