-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #718 from stm32-rs/build-rs-2
device-selected to build.rs
- Loading branch information
Showing
6 changed files
with
114 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::env; | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
enum GetOneError { | ||
None, | ||
Multiple, | ||
} | ||
|
||
trait IteratorExt: Iterator { | ||
fn get_one(self) -> Result<Self::Item, GetOneError>; | ||
} | ||
|
||
impl<T: Iterator> IteratorExt for T { | ||
fn get_one(mut self) -> Result<Self::Item, GetOneError> { | ||
match (self.next(), self.next()) { | ||
(Some(res), None) => Ok(res), | ||
(None, _) => Err(GetOneError::None), | ||
_ => Err(GetOneError::Multiple), | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
let _chip_name = match env::vars() | ||
.map(|(a, _)| a) | ||
.filter(|x| x.starts_with("CARGO_FEATURE_STM32F4")) | ||
.get_one() | ||
{ | ||
Ok(x) => x, | ||
Err(GetOneError::None) => panic!("No stm32xx Cargo feature enabled"), | ||
Err(GetOneError::Multiple) => panic!("Multiple stm32xx Cargo features enabled"), | ||
} | ||
.strip_prefix("CARGO_FEATURE_") | ||
.unwrap() | ||
.to_ascii_lowercase(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.