diff options
| author | Dániel Buga <[email protected]> | 2024-11-06 10:44:01 +0100 |
|---|---|---|
| committer | Dániel Buga <[email protected]> | 2024-11-06 10:48:59 +0100 |
| commit | 1e850ae79149e737c1ba39a383596eabcb0bb940 (patch) | |
| tree | a9b9c47c01b444f370ed8194653f3ef45c72cbc8 /embassy-executor/build_common.rs | |
| parent | e4f611b97c886582dc99b03e93e8f8411f61c45a (diff) | |
Detect and allow older nightlies
Diffstat (limited to 'embassy-executor/build_common.rs')
| -rw-r--r-- | embassy-executor/build_common.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/embassy-executor/build_common.rs b/embassy-executor/build_common.rs index 4f24e6d37..af6bb0618 100644 --- a/embassy-executor/build_common.rs +++ b/embassy-executor/build_common.rs | |||
| @@ -92,3 +92,54 @@ pub fn set_target_cfgs(cfgs: &mut CfgSet) { | |||
| 92 | 92 | ||
| 93 | cfgs.set("has_fpu", target.ends_with("-eabihf")); | 93 | cfgs.set("has_fpu", target.ends_with("-eabihf")); |
| 94 | } | 94 | } |
| 95 | |||
| 96 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] | ||
| 97 | pub struct CompilerDate { | ||
| 98 | year: u16, | ||
| 99 | month: u8, | ||
| 100 | day: u8, | ||
| 101 | } | ||
| 102 | |||
| 103 | impl CompilerDate { | ||
| 104 | fn parse(date: &str) -> Option<Self> { | ||
| 105 | let mut parts = date.split('-'); | ||
| 106 | let year = parts.next()?.parse().ok()?; | ||
| 107 | let month = parts.next()?.parse().ok()?; | ||
| 108 | let day = parts.next()?.parse().ok()?; | ||
| 109 | Some(Self { year, month, day }) | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | impl PartialEq<&str> for CompilerDate { | ||
| 114 | fn eq(&self, other: &&str) -> bool { | ||
| 115 | let Some(other) = Self::parse(other) else { | ||
| 116 | return false; | ||
| 117 | }; | ||
| 118 | self.eq(&other) | ||
| 119 | } | ||
| 120 | } | ||
| 121 | |||
| 122 | impl PartialOrd<&str> for CompilerDate { | ||
| 123 | fn partial_cmp(&self, other: &&str) -> Option<std::cmp::Ordering> { | ||
| 124 | Self::parse(other).map(|other| self.cmp(&other)) | ||
| 125 | } | ||
| 126 | } | ||
| 127 | |||
| 128 | pub struct CompilerInfo { | ||
| 129 | #[allow(unused)] | ||
| 130 | pub version: rustc_version::Version, | ||
| 131 | pub channel: rustc_version::Channel, | ||
| 132 | pub commit_date: Option<CompilerDate>, | ||
| 133 | } | ||
| 134 | |||
| 135 | pub fn compiler_info() -> Option<CompilerInfo> { | ||
| 136 | let Ok(meta) = rustc_version::version_meta() else { | ||
| 137 | return None; | ||
| 138 | }; | ||
| 139 | |||
| 140 | Some(CompilerInfo { | ||
| 141 | version: meta.semver, | ||
| 142 | channel: meta.channel, | ||
| 143 | commit_date: meta.commit_date.as_deref().and_then(CompilerDate::parse), | ||
| 144 | }) | ||
| 145 | } | ||
