diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..3d31fa7 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,79 @@ +[target.'cfg(all())'] +rustflags = [ + # BEGIN - Embark standard lints v6 for Rust 1.55+ + # do not change or add/remove here, but one can add exceptions after this section + # for more info see: + "-Dunsafe_code", + "-Wclippy::all", + "-Wclippy::await_holding_lock", + "-Wclippy::char_lit_as_u8", + "-Wclippy::checked_conversions", + "-Wclippy::dbg_macro", + "-Wclippy::debug_assert_with_mut_call", + "-Wclippy::doc_markdown", + "-Wclippy::empty_enum", + "-Wclippy::enum_glob_use", + "-Wclippy::exit", + "-Wclippy::expl_impl_clone_on_copy", + "-Wclippy::explicit_deref_methods", + "-Wclippy::explicit_into_iter_loop", + "-Wclippy::fallible_impl_from", + "-Wclippy::filter_map_next", + "-Wclippy::flat_map_option", + "-Wclippy::float_cmp_const", + "-Wclippy::fn_params_excessive_bools", + "-Wclippy::from_iter_instead_of_collect", + "-Wclippy::if_let_mutex", + "-Wclippy::implicit_clone", + "-Wclippy::imprecise_flops", + "-Wclippy::inefficient_to_string", + "-Wclippy::invalid_upcast_comparisons", + "-Wclippy::large_digit_groups", + "-Wclippy::large_stack_arrays", + "-Wclippy::large_types_passed_by_value", + "-Wclippy::let_unit_value", + "-Wclippy::linkedlist", + "-Wclippy::lossy_float_literal", + "-Wclippy::macro_use_imports", + "-Wclippy::manual_ok_or", + "-Wclippy::map_err_ignore", + "-Wclippy::map_flatten", + "-Wclippy::map_unwrap_or", + "-Wclippy::match_on_vec_items", + "-Wclippy::match_same_arms", + "-Wclippy::match_wild_err_arm", + "-Wclippy::match_wildcard_for_single_variants", + "-Wclippy::mem_forget", + "-Wclippy::mismatched_target_os", + "-Wclippy::missing_enforced_import_renames", + "-Wclippy::mut_mut", + "-Wclippy::mutex_integer", + "-Wclippy::needless_borrow", + "-Wclippy::needless_continue", + "-Wclippy::needless_for_each", + "-Wclippy::option_option", + "-Wclippy::path_buf_push_overwrite", + "-Wclippy::ptr_as_ptr", + "-Wclippy::rc_mutex", + "-Wclippy::ref_option_ref", + "-Wclippy::rest_pat_in_fully_bound_structs", + "-Wclippy::same_functions_in_if_condition", + "-Wclippy::semicolon_if_nothing_returned", + "-Wclippy::single_match_else", + "-Wclippy::string_add_assign", + "-Wclippy::string_add", + "-Wclippy::string_lit_as_bytes", + "-Wclippy::string_to_string", + "-Wclippy::todo", + "-Wclippy::trait_duplication_in_bounds", + "-Wclippy::unimplemented", + "-Wclippy::unnested_or_patterns", + "-Wclippy::unused_self", + "-Wclippy::useless_transmute", + "-Wclippy::verbose_file_reads", + "-Wclippy::zero_sized_map_values", + "-Wfuture_incompatible", + "-Wnonstandard_style", + "-Wrust_2018_idioms", + # END - Embark standard lints v6 for Rust 1.55+ +] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fffba5e..78c0af2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,22 +12,19 @@ name: CI jobs: lint: name: Lint - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable with: - toolchain: stable - override: true + components: "clippy, rustfmt" # make sure all code has been formatted with rustfmt - - run: rustup component add rustfmt - name: check rustfmt run: cargo fmt -- --check --color always # run clippy to verify we have no warnings - run: cargo fetch - - run: rustup component add clippy - name: cargo clippy run: cargo clippy --all-targets --all-features -- -D warnings @@ -35,14 +32,13 @@ jobs: name: Test strategy: matrix: - toolchain: [1.54, stable] - runs-on: ubuntu-20.04 + toolchain: [1.58.0, stable] + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.toolchain }} - override: true - run: cargo fetch - name: cargo test build run: cargo build --tests --release @@ -55,20 +51,17 @@ jobs: deny-check: name: cargo-deny - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: EmbarkStudios/cargo-deny-action@v1 publish-check: name: Publish Check runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable - run: cargo fetch - name: cargo publish check run: cargo publish --dry-run diff --git a/CHANGELOG.md b/CHANGELOG.md index 296c587..6e66c4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +### Changed +- [PR#51](https://github.com/EmbarkStudios/cfg-expr/pull/51) updated the builtin target list to 1.64.0. Thanks [@sunshowers](https://github.com/sunshowers)! +- [PR#51](https://github.com/EmbarkStudios/cfg-expr/pull/51) bumped the MSRV to 1.58.0. + ## [0.10.3] - 2022-05-19 ### Added - [PR#49](https://github.com/EmbarkStudios/cfg-expr/pull/49) added support for the `has_target_atomic = ""` and `panic = ""` predicates. Thanks [@sunshowers](https://github.com/sunshowers)! diff --git a/Cargo.toml b/Cargo.toml index b2b671e..ccc5f1d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,9 +7,10 @@ authors = [ "Embark ", "Jake Shadle ", ] -edition = "2018" +edition = "2021" license = "MIT OR Apache-2.0" readme = "README.md" +rust-version = "1.58.0" documentation = "https://docs.rs/cfg-expr" homepage = "https://github.com/EmbarkStudios/cfg-expr" keywords = ["cargo", "rustc", "cfg"] diff --git a/README.md b/README.md index 1ea4a88..292376d 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ [![Build Status](https://github.com/EmbarkStudios/cfg-expr/workflows/CI/badge.svg)](https://github.com/EmbarkStudios/cfg-expr/actions?workflow=CI) [![Crates.io](https://img.shields.io/crates/v/cfg-expr.svg)](https://crates.io/crates/cfg-expr) [![Docs](https://docs.rs/cfg-expr/badge.svg)](https://docs.rs/cfg-expr) -[![Minimum Stable Rust Version](https://img.shields.io/badge/Rust%20MSRV-1.54.0-blue?color=fc8d62&logo=rust)](https://blog.rust-lang.org/2021/07/29/Rust-1.54.0.html) -[![Rust Targets](https://img.shields.io/badge/Rust%20Targets-1.58.0-blue.svg)](https://forge.rust-lang.org/release/platform-support.html) +[![Minimum Stable Rust Version](https://img.shields.io/badge/Rust%20MSRV-1.58.0-blue?color=fc8d62&logo=rust)](https://blog.rust-lang.org/2022/01/13/Rust-1.58.0.html) +[![Rust Targets](https://img.shields.io/badge/Rust%20Targets-1.64.0-blue.svg)](https://forge.rust-lang.org/release/platform-support.html) [![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-v2.0%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md) [![Embark](https://img.shields.io/badge/embark-open%20source-blueviolet.svg)](https://embark.dev) diff --git a/clippy.toml b/clippy.toml index 79d4f25..aed39d9 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,2 +1,2 @@ -msrv = "1.52" +msrv = "1.58.0" avoid-breaking-exported-api = false diff --git a/src/error.rs b/src/error.rs index 52787c4..a71b7dc 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,7 +1,7 @@ use std::{error::Error, fmt}; /// An error related to parsing of a cfg expression -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub struct ParseError { /// The string that was parsed pub original: String, @@ -13,7 +13,7 @@ pub struct ParseError { } /// The particular reason for a `ParseError` -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum Reason { /// not() takes exactly 1 predicate, unlike all() and any() InvalidNot(usize), @@ -54,18 +54,18 @@ impl fmt::Display for ParseError { // Mismatched parens/quotes have a slightly different output // than the other errors match &self.reason { - r @ Reason::UnclosedParens | r @ Reason::UnclosedQuotes => { - f.write_fmt(format_args!("- {}", r)) + r @ (Reason::UnclosedParens | Reason::UnclosedQuotes) => { + f.write_fmt(format_args!("- {r}")) } - r @ Reason::UnopenedParens | r @ Reason::UnopenedQuotes => { - f.write_fmt(format_args!("^ {}", r)) + r @ (Reason::UnopenedParens | Reason::UnopenedQuotes) => { + f.write_fmt(format_args!("^ {r}")) } other => { for _ in self.span.start..self.span.end { f.write_str("^")?; } - f.write_fmt(format_args!(" {}", other)) + f.write_fmt(format_args!(" {other}")) } } } @@ -91,7 +91,7 @@ impl fmt::Display for Reason { f.write_str("expected one of ")?; for (i, exp) in expected.iter().enumerate() { - f.write_fmt(format_args!("{}`{}`", if i > 0 { ", " } else { "" }, exp))?; + f.write_fmt(format_args!("{}`{exp}`", if i > 0 { ", " } else { "" }))?; } f.write_str(" here") } else if !expected.is_empty() { @@ -100,7 +100,7 @@ impl fmt::Display for Reason { f.write_str("the term was not expected here") } } - InvalidNot(np) => f.write_fmt(format_args!("not() takes 1 predicate, found {}", np)), + InvalidNot(np) => f.write_fmt(format_args!("not() takes 1 predicate, found {np}")), InvalidInteger => f.write_str("invalid integer"), MultipleRootPredicates => f.write_str("multiple root predicates"), InvalidHasAtomic => f.write_str("expected integer or \"ptr\""), diff --git a/src/expr.rs b/src/expr.rs index f46fdc6..fcd66ff 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -28,7 +28,7 @@ pub enum Func { use crate::targets as targ; /// All predicates that pertains to a target, except for `target_feature` -#[derive(Clone, PartialEq, Debug)] +#[derive(Clone, PartialEq, Eq, Debug)] pub enum TargetPredicate { /// [target_arch](https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch) Arch(targ::Arch), @@ -136,13 +136,15 @@ impl TargetMatcher for target_lexicon::Triple { OperatingSystem::Redox => env == &targ::Env::relibc, OperatingSystem::VxWorks => env == &targ::Env::gnu, OperatingSystem::Freebsd => match self.architecture { - Architecture::Arm(ArmArchitecture::Armv6) - | Architecture::Arm(ArmArchitecture::Armv7) => env == &targ::Env::gnueabihf, + Architecture::Arm(ArmArchitecture::Armv6 | ArmArchitecture::Armv7) => { + env == &targ::Env::gnueabihf + } _ => env.0.is_empty(), }, OperatingSystem::Netbsd => match self.architecture { - Architecture::Arm(ArmArchitecture::Armv6) - | Architecture::Arm(ArmArchitecture::Armv7) => env == &targ::Env::eabihf, + Architecture::Arm(ArmArchitecture::Armv6 | ArmArchitecture::Armv7) => { + env == &targ::Env::eabihf + } _ => env.0.is_empty(), }, OperatingSystem::None_ @@ -372,7 +374,7 @@ pub(crate) struct InnerTarget { } /// A single predicate in a `cfg()` expression -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum Predicate<'a> { /// A target predicate, with the `target_` prefix Target(TargetPredicate), diff --git a/src/expr/parser.rs b/src/expr/parser.rs index 98646f5..ba937b4 100644 --- a/src/expr/parser.rs +++ b/src/expr/parser.rs @@ -216,7 +216,7 @@ impl Expression { ($span:expr) => {{ let expected: &[&str] = match last_token { None => &["", "all", "any", "not"], - Some(Token::All) | Some(Token::Any) | Some(Token::Not) => &["("], + Some(Token::All | Token::Any | Token::Not) => &["("], Some(Token::CloseParen) => &[")", ","], Some(Token::Comma) => &[")", ""], Some(Token::Equals) => &["\""], @@ -242,29 +242,32 @@ impl Expression { 'outer: for lt in lexer { let lt = lt?; match <.token { - Token::Key(k) => match last_token { - None | Some(Token::OpenParen) | Some(Token::Comma) => { + Token::Key(k) => { + if matches!(last_token, None | Some(Token::OpenParen | Token::Comma)) { pred_key = Some((k, lt.span.clone())); + } else { + token_err!(lt.span) } - _ => token_err!(lt.span), - }, - Token::Value(v) => match last_token { - Some(Token::Equals) => { + } + Token::Value(v) => { + if matches!(last_token, Some(Token::Equals)) { // We only record the span for keys and values // so that the expression doesn't need a lifetime // but in the value case we need to strip off // the quotes so that the proper raw string is // provided to callers when evaluating the expression pred_val = Some((v, lt.span.start + 1..lt.span.end - 1)); + } else { + token_err!(lt.span) } - _ => token_err!(lt.span), - }, - Token::Equals => match last_token { - Some(Token::Key(_)) => {} - _ => token_err!(lt.span), - }, - Token::All | Token::Any | Token::Not => match last_token { - None | Some(Token::OpenParen) | Some(Token::Comma) => { + } + Token::Equals => { + if !matches!(last_token, Some(Token::Key(_))) { + token_err!(lt.span) + } + } + Token::All | Token::Any | Token::Not => { + if matches!(last_token, None | Some(Token::OpenParen | Token::Comma)) { let new_fn = match lt.token { // the 0 is a dummy value -- it will be substituted for the real // number of predicates in the `CloseParen` branch below. @@ -285,23 +288,26 @@ impl Expression { predicates: SmallVec::new(), nest_level: 0, }); + } else { + token_err!(lt.span) } - _ => token_err!(lt.span), - }, - Token::OpenParen => match last_token { - Some(Token::All) | Some(Token::Any) | Some(Token::Not) => { + } + Token::OpenParen => { + if matches!(last_token, Some(Token::All | Token::Any | Token::Not)) { if let Some(ref mut fs) = func_stack.last_mut() { fs.parens_index = lt.span.start; } - } - _ => token_err!(lt.span), - }, - Token::CloseParen => match last_token { - None | Some(Token::All) | Some(Token::Any) | Some(Token::Not) - | Some(Token::Equals) => { + } else { token_err!(lt.span) } - _ => { + } + Token::CloseParen => { + if matches!( + last_token, + None | Some(Token::All | Token::Any | Token::Not | Token::Equals) + ) { + token_err!(lt.span) + } else { if let Some(top) = func_stack.pop() { let key = pred_key.take(); let val = pred_val.take(); @@ -352,15 +358,16 @@ impl Expression { reason: Reason::UnopenedParens, }); } - }, - Token::Comma => match last_token { - None - | Some(Token::OpenParen) - | Some(Token::All) - | Some(Token::Any) - | Some(Token::Not) - | Some(Token::Equals) => token_err!(lt.span), - _ => { + } + Token::Comma => { + if matches!( + last_token, + None | Some( + Token::OpenParen | Token::All | Token::Any | Token::Not | Token::Equals + ) + ) { + token_err!(lt.span) + } else { let key = pred_key.take(); let val = pred_val.take(); @@ -378,7 +385,7 @@ impl Expression { _ => {} } } - }, + } } last_token = Some(lt.token); @@ -393,49 +400,46 @@ impl Expression { } // If we still have functions on the stack, it means we have an unclosed parens - match func_stack.pop() { - Some(top) => { - if top.parens_index != 0 { - Err(ParseError { - original: original.to_owned(), - span: top.parens_index..original.len(), - reason: Reason::UnclosedParens, - }) - } else { - Err(ParseError { - original: original.to_owned(), - span: top.span, - reason: Reason::Unexpected(&["("]), - }) - } + if let Some(top) = func_stack.pop() { + if top.parens_index != 0 { + Err(ParseError { + original: original.to_owned(), + span: top.parens_index..original.len(), + reason: Reason::UnclosedParens, + }) + } else { + Err(ParseError { + original: original.to_owned(), + span: top.span, + reason: Reason::Unexpected(&["("]), + }) } - None => { - let key = pred_key.take(); - let val = pred_val.take(); + } else { + let key = pred_key.take(); + let val = pred_val.take(); - if let Some(key) = key { - root_predicate_count += 1; - expr_queue.push(ExprNode::Predicate(parse_predicate(key, val)?)); - } + if let Some(key) = key { + root_predicate_count += 1; + expr_queue.push(ExprNode::Predicate(parse_predicate(key, val)?)); + } - if expr_queue.is_empty() { - Err(ParseError { - original: original.to_owned(), - span: 0..original.len(), - reason: Reason::Empty, - }) - } else if root_predicate_count > 1 { - Err(ParseError { - original: original.to_owned(), - span: 0..original.len(), - reason: Reason::MultipleRootPredicates, - }) - } else { - Ok(Expression { - original: original.to_owned(), - expr: expr_queue, - }) - } + if expr_queue.is_empty() { + Err(ParseError { + original: original.to_owned(), + span: 0..original.len(), + reason: Reason::Empty, + }) + } else if root_predicate_count > 1 { + Err(ParseError { + original: original.to_owned(), + span: 0..original.len(), + reason: Reason::MultipleRootPredicates, + }) + } else { + Ok(Expression { + original: original.to_owned(), + expr: expr_queue, + }) } } } diff --git a/src/lib.rs b/src/lib.rs index 6346c06..30cb38c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,84 +1,4 @@ #![doc = include_str!("../README.md")] -// BEGIN - Embark standard lints v5 for Rust 1.55+ -// do not change or add/remove here, but one can add exceptions after this section -// for more info see: -#![deny(unsafe_code)] -#![warn( - clippy::all, - clippy::await_holding_lock, - clippy::char_lit_as_u8, - clippy::checked_conversions, - clippy::dbg_macro, - clippy::debug_assert_with_mut_call, - clippy::doc_markdown, - clippy::empty_enum, - clippy::enum_glob_use, - clippy::exit, - clippy::expl_impl_clone_on_copy, - clippy::explicit_deref_methods, - clippy::explicit_into_iter_loop, - clippy::fallible_impl_from, - clippy::filter_map_next, - clippy::flat_map_option, - clippy::float_cmp_const, - clippy::fn_params_excessive_bools, - clippy::from_iter_instead_of_collect, - clippy::if_let_mutex, - clippy::implicit_clone, - clippy::imprecise_flops, - clippy::inefficient_to_string, - clippy::invalid_upcast_comparisons, - clippy::large_digit_groups, - clippy::large_stack_arrays, - clippy::large_types_passed_by_value, - clippy::let_unit_value, - clippy::linkedlist, - clippy::lossy_float_literal, - clippy::macro_use_imports, - clippy::manual_ok_or, - clippy::map_err_ignore, - clippy::map_flatten, - clippy::map_unwrap_or, - clippy::match_on_vec_items, - clippy::match_same_arms, - clippy::match_wild_err_arm, - clippy::match_wildcard_for_single_variants, - clippy::mem_forget, - clippy::mismatched_target_os, - clippy::missing_enforced_import_renames, - clippy::mut_mut, - clippy::mutex_integer, - clippy::needless_borrow, - clippy::needless_continue, - clippy::needless_for_each, - clippy::option_option, - clippy::path_buf_push_overwrite, - clippy::ptr_as_ptr, - clippy::rc_mutex, - clippy::ref_option_ref, - clippy::rest_pat_in_fully_bound_structs, - clippy::same_functions_in_if_condition, - clippy::semicolon_if_nothing_returned, - clippy::single_match_else, - clippy::string_add_assign, - clippy::string_add, - clippy::string_lit_as_bytes, - clippy::string_to_string, - clippy::todo, - clippy::trait_duplication_in_bounds, - clippy::unimplemented, - clippy::unnested_or_patterns, - clippy::unused_self, - clippy::useless_transmute, - clippy::verbose_file_reads, - clippy::zero_sized_map_values, - future_incompatible, - nonstandard_style, - rust_2018_idioms -)] -// END - Embark standard lints v0.5 for Rust 1.55+ -// crate-specific exceptions: -#![allow(clippy::single_match_else)] /// Types related to parse errors pub mod error; diff --git a/src/targets.rs b/src/targets.rs index 2150312..8d458b8 100644 --- a/src/targets.rs +++ b/src/targets.rs @@ -364,7 +364,7 @@ pub fn get_builtin_target_by_triple(triple: &str) -> Option<&'static TargetInfo> /// versions. /// /// ``` -/// assert_eq!("1.61.0", cfg_expr::targets::rustc_version()); +/// assert_eq!("1.64.0", cfg_expr::targets::rustc_version()); /// ``` pub fn rustc_version() -> &'static str { builtins::RUSTC_VERSION diff --git a/src/targets/builtins.rs b/src/targets/builtins.rs index ac0265e..8a2d3c0 100644 --- a/src/targets/builtins.rs +++ b/src/targets/builtins.rs @@ -10,7 +10,7 @@ use super::*; -pub(crate) const RUSTC_VERSION: &str = "1.61.0"; +pub(crate) const RUSTC_VERSION: &str = "1.64.0"; pub const ALL_BUILTINS: &[TargetInfo] = &[ TargetInfo { @@ -73,6 +73,18 @@ pub const ALL_BUILTINS: &[TargetInfo] = &[ has_atomics: HasAtomics::atomic_8_16_32_64_128_ptr, panic: Panic::unwind, }, + TargetInfo { + triple: Triple::new_const("aarch64-apple-watchos-sim"), + os: Some(Os::watchos), + arch: Arch::aarch64, + env: None, + vendor: Some(Vendor::apple), + families: Families::unix, + pointer_width: 64, + endian: Endian::little, + has_atomics: HasAtomics::atomic_8_16_32_64_128_ptr, + panic: Panic::unwind, + }, TargetInfo { triple: Triple::new_const("aarch64-fuchsia"), os: Some(Os::fuchsia), @@ -109,6 +121,30 @@ pub const ALL_BUILTINS: &[TargetInfo] = &[ has_atomics: HasAtomics::atomic_8_16_32_64_128_ptr, panic: Panic::unwind, }, + TargetInfo { + triple: Triple::new_const("aarch64-nintendo-switch-freestanding"), + os: Some(Os::horizon), + arch: Arch::aarch64, + env: None, + vendor: Some(Vendor::unknown), + families: Families::new_const(&[]), + pointer_width: 64, + endian: Endian::little, + has_atomics: HasAtomics::atomic_8_16_32_64_128_ptr, + panic: Panic::abort, + }, + TargetInfo { + triple: Triple::new_const("aarch64-pc-windows-gnullvm"), + os: Some(Os::windows), + arch: Arch::aarch64, + env: Some(Env::gnu), + vendor: Some(Vendor::pc), + families: Families::windows, + pointer_width: 64, + endian: Endian::little, + has_atomics: HasAtomics::atomic_8_16_32_64_ptr, + panic: Panic::unwind, + }, TargetInfo { triple: Triple::new_const("aarch64-pc-windows-msvc"), os: Some(Os::windows), @@ -361,6 +397,18 @@ pub const ALL_BUILTINS: &[TargetInfo] = &[ has_atomics: HasAtomics::atomic_8_16_32_64_ptr, panic: Panic::unwind, }, + TargetInfo { + triple: Triple::new_const("arm64_32-apple-watchos"), + os: Some(Os::watchos), + arch: Arch::aarch64, + env: None, + vendor: Some(Vendor::apple), + families: Families::unix, + pointer_width: 32, + endian: Endian::little, + has_atomics: HasAtomics::atomic_8_16_32_64_ptr, + panic: Panic::unwind, + }, TargetInfo { triple: Triple::new_const("armebv7r-none-eabi"), os: None, @@ -649,6 +697,18 @@ pub const ALL_BUILTINS: &[TargetInfo] = &[ has_atomics: HasAtomics::atomic_8_16_32_64_ptr, panic: Panic::abort, }, + TargetInfo { + triple: Triple::new_const("armv7k-apple-watchos"), + os: Some(Os::watchos), + arch: Arch::arm, + env: None, + vendor: Some(Vendor::apple), + families: Families::unix, + pointer_width: 32, + endian: Endian::little, + has_atomics: HasAtomics::atomic_8_16_32_64_ptr, + panic: Panic::unwind, + }, TargetInfo { triple: Triple::new_const("armv7r-none-eabi"), os: None, @@ -1441,6 +1501,18 @@ pub const ALL_BUILTINS: &[TargetInfo] = &[ has_atomics: HasAtomics::atomic_8_16_32_ptr, panic: Panic::abort, }, + TargetInfo { + triple: Triple::new_const("riscv32imac-unknown-xous-elf"), + os: Some(Os::xous), + arch: Arch::riscv32, + env: None, + vendor: Some(Vendor::unknown), + families: Families::new_const(&[]), + pointer_width: 32, + endian: Endian::little, + has_atomics: HasAtomics::atomic_8_16_32_ptr, + panic: Panic::abort, + }, TargetInfo { triple: Triple::new_const("riscv32imc-esp-espidf"), os: Some(Os::espidf), @@ -1861,6 +1933,18 @@ pub const ALL_BUILTINS: &[TargetInfo] = &[ has_atomics: HasAtomics::atomic_8_16_32_64_ptr, panic: Panic::unwind, }, + TargetInfo { + triple: Triple::new_const("x86_64-apple-watchos-sim"), + os: Some(Os::watchos), + arch: Arch::x86_64, + env: None, + vendor: Some(Vendor::apple), + families: Families::unix, + pointer_width: 64, + endian: Endian::little, + has_atomics: HasAtomics::atomic_8_16_32_64_ptr, + panic: Panic::unwind, + }, TargetInfo { triple: Triple::new_const("x86_64-fortanix-unknown-sgx"), os: Some(Os::unknown), @@ -1921,6 +2005,18 @@ pub const ALL_BUILTINS: &[TargetInfo] = &[ has_atomics: HasAtomics::atomic_8_16_32_64_ptr, panic: Panic::unwind, }, + TargetInfo { + triple: Triple::new_const("x86_64-pc-windows-gnullvm"), + os: Some(Os::windows), + arch: Arch::x86_64, + env: Some(Env::gnu), + vendor: Some(Vendor::pc), + families: Families::windows, + pointer_width: 64, + endian: Endian::little, + has_atomics: HasAtomics::atomic_8_16_32_64_ptr, + panic: Panic::unwind, + }, TargetInfo { triple: Triple::new_const("x86_64-pc-windows-msvc"), os: Some(Os::windows), @@ -2229,7 +2325,9 @@ impl super::Os { pub const unknown: Os = Os::new_const("unknown"); pub const vxworks: Os = Os::new_const("vxworks"); pub const wasi: Os = Os::new_const("wasi"); + pub const watchos: Os = Os::new_const("watchos"); pub const windows: Os = Os::new_const("windows"); + pub const xous: Os = Os::new_const("xous"); } impl super::Family { diff --git a/tests/eval.rs b/tests/eval.rs index 1b8baa7..b2a89de 100644 --- a/tests/eval.rs +++ b/tests/eval.rs @@ -7,7 +7,7 @@ use cfg_expr::{ struct Target { builtin: &'static cfg_expr::targets::TargetInfo, #[cfg(feature = "targets")] - lexicon: target_lexicon::Triple, + lexicon: Option, } impl Target { @@ -22,16 +22,22 @@ impl Target { // the presence of this triple in most normal cases use target_lexicon as tl; match s { - "avr-unknown-gnu-atmega328" => tl::Triple { + "avr-unknown-gnu-atmega328" => Some(tl::Triple { architecture: tl::Architecture::Avr, vendor: tl::Vendor::Unknown, operating_system: tl::OperatingSystem::Unknown, environment: tl::Environment::Unknown, binary_format: tl::BinaryFormat::Unknown, - }, + }), triple => match triple.parse() { - Ok(l) => l, - Err(e) => panic!("failed to parse '{}': {:?}", triple, e), + Ok(l) => Some(l), + Err(e) => { + // There are enough new weird architectures added in each version of + // Rust that it is difficult to keep target-lexicon aware of all of + // them. So try parsing this triple, but don't fail if it doesn't work. + eprintln!("failed to parse '{}': {:?}", triple, e); + None + } }, } }, @@ -49,14 +55,16 @@ macro_rules! tg_match { if !matches!(tg, TargetPredicate::HasAtomic(_)) && !matches!(tg, TargetPredicate::Panic(_)) { - let linfo = tg.matches(&$target.lexicon); - assert_eq!( - tinfo, linfo, - "{:#?} builtin didn't match lexicon {:#?} for predicate {:#?}", - $target.builtin, $target.lexicon, tg, - ); - - return linfo; + if let Some(l) = &$target.lexicon { + let linfo = tg.matches(l); + assert_eq!( + tinfo, linfo, + "{:#?} builtin didn't match lexicon {:#?} for predicate {:#?}", + $target.builtin, $target.lexicon, tg, + ); + + return linfo; + } } tinfo @@ -74,14 +82,16 @@ macro_rules! tg_match { if !matches!(tg, TargetPredicate::HasAtomic(_)) && !matches!(tg, TargetPredicate::Panic(_)) { - let linfo = tg.matches(&$target.lexicon); - assert_eq!( - tinfo, linfo, - "{:#?} builtin didn't match lexicon {:#?} for predicate {:#?}", - $target.builtin, $target.lexicon, tg, - ); - - return linfo; + if let Some(l) = &$target.lexicon { + let linfo = tg.matches(l); + assert_eq!( + tinfo, linfo, + "{:#?} builtin didn't match lexicon {:#?} for predicate {:#?}", + $target.builtin, $target.lexicon, tg, + ); + + return linfo; + } } tinfo @@ -178,11 +188,7 @@ fn very_specific() { } else { "".to_owned() }, - target - .env - .as_ref() - .map(|e| e.as_str()) - .unwrap_or_else(|| ""), + target.env.as_ref().map_or("", |e| e.as_str()), ); let specific = Expression::parse(&expr).unwrap();