Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for abi if it is present #54

Merged
merged 2 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use crate::targets as targ;
/// All predicates that pertains to a target, except for `target_feature`
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum TargetPredicate {
/// [target_abi](https://github.com/rust-lang/rust/issues/80970)
Abi(targ::Abi),
/// [target_arch](https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch)
Arch(targ::Arch),
/// [target_endian](https://doc.rust-lang.org/reference/conditional-compilation.html#target_endian)
Expand Down Expand Up @@ -59,10 +61,15 @@ pub trait TargetMatcher {
impl TargetMatcher for targ::TargetInfo {
fn matches(&self, tp: &TargetPredicate) -> bool {
use TargetPredicate::{
Arch, Endian, Env, Family, HasAtomic, Os, Panic, PointerWidth, Vendor,
Abi, Arch, Endian, Env, Family, HasAtomic, Os, Panic, PointerWidth, Vendor,
};

match tp {
// The ABI is allowed to be an empty string
Abi(abi) => match &self.abi {
Some(a) => abi == a,
None => abi.0.is_empty(),
},
Arch(a) => a == &self.arch,
Endian(end) => *end == self.endian,
// The environment is allowed to be an empty string
Expand Down Expand Up @@ -90,10 +97,14 @@ impl TargetMatcher for target_lexicon::Triple {
fn matches(&self, tp: &TargetPredicate) -> bool {
use target_lexicon::*;
use TargetPredicate::{
Arch, Endian, Env, Family, HasAtomic, Os, Panic, PointerWidth, Vendor,
Abi, Arch, Endian, Env, Family, HasAtomic, Os, Panic, PointerWidth, Vendor,
};

match tp {
Abi(_) => {
// `target_abi` is unstable. Assume false for this.
false
}
Arch(arch) => {
if arch == &targ::Arch::x86 {
matches!(self.architecture, Architecture::X86_32(_))
Expand Down Expand Up @@ -359,6 +370,7 @@ impl TargetPredicate {

#[derive(Clone, Debug)]
pub(crate) enum Which {
Abi,
Arch,
Endian(targ::Endian),
Env,
Expand Down Expand Up @@ -422,6 +434,9 @@ impl InnerPredicate {

match self {
IP::Target(it) => match &it.which {
Which::Abi => Target(TargetPredicate::Abi(targ::Abi::new(
s[it.span.clone().unwrap()].to_owned(),
))),
Which::Arch => Target(TargetPredicate::Arch(targ::Arch::new(
s[it.span.clone().unwrap()].to_owned(),
))),
Expand Down
1 change: 1 addition & 0 deletions src/expr/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ impl Expression {
}

let tp = match &target_key[7..] {
"abi" => tp!(Abi),
"arch" => tp!(Arch),
"feature" => {
if val.is_empty() {
Expand Down
8 changes: 8 additions & 0 deletions src/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ pub use builtins::ALL_BUILTINS;
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Triple(pub Cow<'static, str>);

/// The "abi" field
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Abi(pub Cow<'static, str>);

/// The "architecture" field
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Arch(pub Cow<'static, str>);
Expand Down Expand Up @@ -79,6 +83,7 @@ macro_rules! field_impls {
}

field_impls!(Triple);
field_impls!(Abi);
field_impls!(Arch);
field_impls!(Vendor);
field_impls!(Os);
Expand Down Expand Up @@ -316,6 +321,9 @@ pub struct TargetInfo {
/// [target_os](https://doc.rust-lang.org/reference/conditional-compilation.html#target_os)
/// predicate.
pub os: Option<Os>,
/// The target's ABI, if any. Used by the
/// [target_abi](https://github.com/rust-lang/rust/issues/80970) predicate.
pub abi: Option<Abi>,
/// The target's CPU architecture. Used by the
/// [target_arch](https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch)
/// predicate.
Expand Down
Loading