Skip to content

Commit

Permalink
Do not collect all config symbols into a vec needlessly
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Aug 18, 2024
1 parent ba46d91 commit e2431ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
4 changes: 2 additions & 2 deletions esp-hal/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn main() -> Result<(), Box<dyn Error>> {
config.define_symbols();

#[allow(unused_mut)]
let mut config_symbols = config.all();
let mut config_symbols = config.all().collect::<Vec<_>>();
#[cfg(feature = "flip-link")]
config_symbols.push("flip-link".to_owned());

Expand Down Expand Up @@ -135,7 +135,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// Helper Functions

fn copy_dir_all(
config_symbols: &Vec<String>,
config_symbols: &[String],
src: impl AsRef<Path>,
dst: impl AsRef<Path>,
) -> std::io::Result<()> {
Expand Down
28 changes: 9 additions & 19 deletions esp-metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,36 +210,26 @@ impl Config {
}

/// All configuration values for the device.
pub fn all(&self) -> Vec<String> {
pub fn all(&self) -> impl Iterator<Item = String> {
[
vec![
self.device.name.clone(),
self.device.arch.to_string(),
self.device.cores.to_string(),
],
self.device.peripherals.clone(),
self.device.symbols.clone(),
self.device.name.clone(),
self.device.arch.to_string(),
self.device.cores.to_string(),
]
.concat()
.into_iter()
.chain(self.device.peripherals.clone())
.chain(self.device.symbols.clone())
}

/// Does the configuration contain `item`?
pub fn contains(&self, item: &String) -> bool {
self.all().contains(item)
self.all().any(|i| &i == item)
}

/// Define all symbols for a given configuration.
pub fn define_symbols(&self) {
// Define all necessary configuration symbols for the configured device:
println!("cargo:rustc-cfg={}", self.name());
println!("cargo:rustc-cfg={}", self.arch());
println!("cargo:rustc-cfg={}", self.cores());

for peripheral in self.peripherals() {
println!("cargo:rustc-cfg={peripheral}");
}

for symbol in self.symbols() {
for symbol in self.all() {
println!("cargo:rustc-cfg={symbol}");
}
}
Expand Down

0 comments on commit e2431ba

Please sign in to comment.