Skip to content

Commit 4b7f047

Browse files
committed
Parse target_abi if it's present even though it's unstable
1 parent 1065ebc commit 4b7f047

File tree

6 files changed

+282
-2
lines changed

6 files changed

+282
-2
lines changed

src/expr.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ use crate::targets as targ;
3030
/// All predicates that pertains to a target, except for `target_feature`
3131
#[derive(Clone, PartialEq, Eq, Debug)]
3232
pub enum TargetPredicate {
33+
/// [target_abi](https://github.com/rust-lang/rust/issues/80970)
34+
Abi(targ::Abi),
3335
/// [target_arch](https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch)
3436
Arch(targ::Arch),
3537
/// [target_endian](https://doc.rust-lang.org/reference/conditional-compilation.html#target_endian)
@@ -59,10 +61,15 @@ pub trait TargetMatcher {
5961
impl TargetMatcher for targ::TargetInfo {
6062
fn matches(&self, tp: &TargetPredicate) -> bool {
6163
use TargetPredicate::{
62-
Arch, Endian, Env, Family, HasAtomic, Os, Panic, PointerWidth, Vendor,
64+
Abi, Arch, Endian, Env, Family, HasAtomic, Os, Panic, PointerWidth, Vendor,
6365
};
6466

6567
match tp {
68+
// The ABI is allowed to be an empty string
69+
Abi(abi) => match &self.abi {
70+
Some(a) => abi == a,
71+
None => abi.0.is_empty(),
72+
},
6673
Arch(a) => a == &self.arch,
6774
Endian(end) => *end == self.endian,
6875
// The environment is allowed to be an empty string
@@ -90,10 +97,14 @@ impl TargetMatcher for target_lexicon::Triple {
9097
fn matches(&self, tp: &TargetPredicate) -> bool {
9198
use target_lexicon::*;
9299
use TargetPredicate::{
93-
Arch, Endian, Env, Family, HasAtomic, Os, Panic, PointerWidth, Vendor,
100+
Abi, Arch, Endian, Env, Family, HasAtomic, Os, Panic, PointerWidth, Vendor,
94101
};
95102

96103
match tp {
104+
Abi(_) => {
105+
// `target_abi` is unstable. Assume false for this.
106+
false
107+
}
97108
Arch(arch) => {
98109
if arch == &targ::Arch::x86 {
99110
matches!(self.architecture, Architecture::X86_32(_))
@@ -356,6 +367,7 @@ impl TargetPredicate {
356367

357368
#[derive(Clone, Debug)]
358369
pub(crate) enum Which {
370+
Abi,
359371
Arch,
360372
Endian(targ::Endian),
361373
Env,
@@ -419,6 +431,9 @@ impl InnerPredicate {
419431

420432
match self {
421433
IP::Target(it) => match &it.which {
434+
Which::Abi => Target(TargetPredicate::Abi(targ::Abi::new(
435+
s[it.span.clone().unwrap()].to_owned(),
436+
))),
422437
Which::Arch => Target(TargetPredicate::Arch(targ::Arch::new(
423438
s[it.span.clone().unwrap()].to_owned(),
424439
))),

src/expr/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ impl Expression {
144144
}
145145

146146
let tp = match &target_key[7..] {
147+
"abi" => tp!(Abi),
147148
"arch" => tp!(Arch),
148149
"feature" => {
149150
if val.is_empty() {

src/targets.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ pub use builtins::ALL_BUILTINS;
1111
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
1212
pub struct Triple(pub Cow<'static, str>);
1313

14+
/// The "abi" field
15+
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
16+
pub struct Abi(pub Cow<'static, str>);
17+
1418
/// The "architecture" field
1519
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
1620
pub struct Arch(pub Cow<'static, str>);
@@ -79,6 +83,7 @@ macro_rules! field_impls {
7983
}
8084

8185
field_impls!(Triple);
86+
field_impls!(Abi);
8287
field_impls!(Arch);
8388
field_impls!(Vendor);
8489
field_impls!(Os);
@@ -316,6 +321,9 @@ pub struct TargetInfo {
316321
/// [target_os](https://doc.rust-lang.org/reference/conditional-compilation.html#target_os)
317322
/// predicate.
318323
pub os: Option<Os>,
324+
/// The target's ABI, if any. Used by the
325+
/// [target_abi](https://github.com/rust-lang/rust/issues/80970) predicate.
326+
pub abi: Option<Abi>,
319327
/// The target's CPU architecture. Used by the
320328
/// [target_arch](https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch)
321329
/// predicate.

0 commit comments

Comments
 (0)