From 4adae80f2d575b631b0bc1aef4b7272e62acedb6 Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Sat, 15 Apr 2023 00:50:46 +0200 Subject: xtask: don't add default arguments if building for a no_std target --- xtask/src/main.rs | 55 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 13 deletions(-) (limited to 'xtask/src/main.rs') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 4cb38c2..8f6a556 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -33,14 +33,42 @@ use crate::{ command::{run_command, run_successful, CargoCommand}, }; -// x86_64-unknown-linux-gnu -const _X86_64: &str = "x86_64-unknown-linux-gnu"; -const ARMV6M: &str = "thumbv6m-none-eabi"; -const ARMV7M: &str = "thumbv7m-none-eabi"; -const ARMV8MBASE: &str = "thumbv8m.base-none-eabi"; -const ARMV8MMAIN: &str = "thumbv8m.main-none-eabi"; +#[derive(Debug, Clone, Copy)] +pub struct Target<'a> { + triple: &'a str, + has_std: bool, +} + +impl<'a> Target<'a> { + const STD_FEATURES: &str = "test-critical-section"; + + pub const fn new(triple: &'a str, has_std: bool) -> Self { + Self { triple, has_std } + } + + pub fn triple(&self) -> &str { + self.triple + } + + pub fn has_std(&self) -> bool { + self.has_std + } + + pub fn and_features(&self, features: &str) -> String { + if self.has_std { + format!("{},{}", Self::STD_FEATURES, features) + } else { + features.to_string() + } + } +} -const DEFAULT_FEATURES: &str = "test-critical-section"; +// x86_64-unknown-linux-gnu +const _X86_64: Target = Target::new("x86_64-unknown-linux-gnu", true); +const ARMV6M: Target = Target::new("thumbv6m-none-eabi", false); +const ARMV7M: Target = Target::new("thumbv7m-none-eabi", false); +const ARMV8MBASE: Target = Target::new("thumbv8m.base-none-eabi", false); +const ARMV8MMAIN: Target = Target::new("thumbv8m.main-none-eabi", false); #[derive(Debug, Clone)] pub struct RunResult { @@ -276,12 +304,13 @@ fn main() -> anyhow::Result<()> { /// Without package specified the features for RTIC are required /// With only a single package which is not RTIC, no special /// features are needed -fn package_feature_extractor(package: &PackageOpt, backend: Backends) -> Option { - let default_features = Some(format!( - "{},{}", - DEFAULT_FEATURES, - backend.to_rtic_feature() - )); +fn package_feature_extractor( + target: Target, + package: &PackageOpt, + backend: Backends, +) -> Option { + let default_features = Some(target.and_features(backend.to_rtic_feature())); + if let Some(package) = package.package { debug!("\nTesting package: {package}"); match package { -- cgit v1.2.3