From 9e230b64a409379b3e24ed4ad7195c06ea212e1f Mon Sep 17 00:00:00 2001 From: xoviat Date: Mon, 23 Oct 2023 18:19:42 -0500 Subject: [PATCH] stm32/build: deterministically generate data --- embassy-stm32/build.rs | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index f8908756d..938e44b14 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -1,4 +1,4 @@ -use std::collections::{HashMap, HashSet}; +use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use std::fmt::Write as _; use std::path::PathBuf; use std::{env, fs}; @@ -352,7 +352,7 @@ fn main() { // ======== // Generate DMA IRQs. - let mut dma_irqs: HashMap<&str, Vec<(&str, &str, &str)>> = HashMap::new(); + let mut dma_irqs: BTreeMap<&str, Vec<(&str, &str, &str)>> = BTreeMap::new(); for p in METADATA.peripherals { if let Some(r) = &p.registers { @@ -371,22 +371,27 @@ fn main() { } } - for (irq, channels) in dma_irqs { - let irq = format_ident!("{}", irq); + let dma_irqs: TokenStream = dma_irqs + .iter() + .map(|(irq, channels)| { + let irq = format_ident!("{}", irq); - let xdma = format_ident!("{}", channels[0].0); - let channels = channels.iter().map(|(_, dma, ch)| format_ident!("{}_{}", dma, ch)); + let xdma = format_ident!("{}", channels[0].0); + let channels = channels.iter().map(|(_, dma, ch)| format_ident!("{}_{}", dma, ch)); - g.extend(quote! { - #[cfg(feature = "rt")] - #[crate::interrupt] - unsafe fn #irq () { - #( - ::on_irq(); - )* + quote! { + #[cfg(feature = "rt")] + #[crate::interrupt] + unsafe fn #irq () { + #( + ::on_irq(); + )* + } } - }); - } + }) + .collect(); + + g.extend(dma_irqs); // ======== // Extract the rcc registers @@ -433,7 +438,7 @@ fn main() { // Generate RccPeripheral impls let refcounted_peripherals = HashSet::from(["usart", "adc"]); - let mut refcount_statics = HashSet::new(); + let mut refcount_statics = BTreeSet::new(); for p in METADATA.peripherals { if !singletons.contains(&p.name.to_string()) {