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

update targets to Rust 1.80 #70

Merged
merged 2 commits into from
Jul 29, 2024
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

# `⚙️ cfg-expr`

**A parser and evaluator for Rust `cfg()` expressions. Builtin targets as of [1.77.2] are supported.**
**A parser and evaluator for Rust `cfg()` expressions. Builtin targets as of [1.80.0] are supported.**

[![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.70.0-blue?color=fc8d62&logo=rust)](https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html)
[![Rust Targets](https://img.shields.io/badge/Rust%20Targets-1.77.2-blue.svg)](https://forge.rust-lang.org/release/platform-support.html)
[![Rust Targets](https://img.shields.io/badge/Rust%20Targets-1.80.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)
</div>
Expand All @@ -24,7 +24,7 @@

`cfg-expr` is a crate that can be used to parse and evaluate Rust `cfg()` expressions, both as declarable in Rust code itself, as well in cargo manifests' `[target.'cfg()'.dependencies]` sections.

It contains a list of all builtin targets known to rustc as of [1.77.2] that can be used to determine if a particular cfg expression is satisfiable.
It contains a list of all builtin targets known to rustc as of [1.80.0] that can be used to determine if a particular cfg expression is satisfiable.

```rust
use cfg_expr::{targets::get_builtin_target_by_triple, Expression, Predicate};
Expand Down Expand Up @@ -110,4 +110,4 @@ at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

[1.77.2]: (https://forge.rust-lang.org/release/platform-support.html)
[1.80.0]: (https://forge.rust-lang.org/release/platform-support.html)
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct ParseError {
/// The particular reason for a `ParseError`
#[derive(Debug, PartialEq, Eq)]
pub enum Reason {
/// not() takes exactly 1 predicate, unlike all() and any()
/// `not()` takes exactly 1 predicate, unlike `all()` and `any()`
InvalidNot(usize),
/// The characters are not valid in an cfg expression
InvalidCharacters,
Expand All @@ -34,7 +34,7 @@ pub enum Reason {
Unexpected(&'static [&'static str]),
/// Failed to parse an integer value
InvalidInteger,
/// The root cfg() may only contain a single predicate
/// The root `cfg()` may only contain a single predicate
MultipleRootPredicates,
/// A `target_has_atomic` predicate didn't correctly parse.
InvalidHasAtomic,
Expand Down
65 changes: 41 additions & 24 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ impl TargetMatcher for target_lexicon::Triple {
OperatingSystem::VxWorks => env == &targ::Env::gnu,
OperatingSystem::Freebsd => match self.architecture {
Architecture::Arm(ArmArchitecture::Armv6 | ArmArchitecture::Armv7) => {
env == &targ::Env::gnueabihf
env == &targ::Env::gnu
}
_ => env.0.is_empty(),
},
OperatingSystem::Netbsd => match self.architecture {
Architecture::Arm(ArmArchitecture::Armv6 | ArmArchitecture::Armv7) => {
env == &targ::Env::eabihf
env.0.is_empty()
}
_ => env.0.is_empty(),
},
Expand All @@ -187,6 +187,8 @@ impl TargetMatcher for target_lexicon::Triple {
Environment::LinuxKernel => env == &targ::Env::gnu,
_ => env.0.is_empty(),
},
OperatingSystem::WasiP1 => env.0.is_empty(),
OperatingSystem::WasiP2 => env == &targ::Env::p2,
_ => {
if env.0.is_empty() {
matches!(
Expand All @@ -198,6 +200,7 @@ impl TargetMatcher for target_lexicon::Triple {
| Environment::Eabi
| Environment::Eabihf
| Environment::Sim
| Environment::None
)
} else {
match env.0.parse::<Environment>() {
Expand Down Expand Up @@ -259,9 +262,9 @@ impl TargetMatcher for target_lexicon::Triple {
Family(fam) => {
use OperatingSystem::{
Aix, AmdHsa, Bitrig, Cloudabi, Cuda, Darwin, Dragonfly, Emscripten, Espidf,
Freebsd, Fuchsia, Haiku, Hermit, Horizon, Illumos, Ios, L4re, Linux, MacOSX,
Nebulet, Netbsd, None_, Openbsd, Redox, Solaris, Tvos, Uefi, Unknown, VxWorks,
Wasi, Watchos, Windows,
Freebsd, Fuchsia, Haiku, Hermit, Horizon, Hurd, Illumos, Ios, L4re, Linux,
MacOSX, Nebulet, Netbsd, None_, Openbsd, Redox, Solaris, Tvos, Uefi, Unknown,
Visionos, VxWorks, Wasi, WasiP1, WasiP2, Watchos, Windows,
};
match self.operating_system {
AmdHsa | Bitrig | Cloudabi | Cuda | Hermit | Nebulet | None_ | Uefi => false,
Expand All @@ -272,6 +275,7 @@ impl TargetMatcher for target_lexicon::Triple {
| Freebsd
| Fuchsia
| Haiku
| Hurd
| Illumos
| Ios
| L4re
Expand All @@ -282,6 +286,7 @@ impl TargetMatcher for target_lexicon::Triple {
| Redox
| Solaris
| Tvos
| Visionos
| VxWorks
| Watchos => fam == &crate::targets::Family::unix,
Emscripten => {
Expand Down Expand Up @@ -311,7 +316,7 @@ impl TargetMatcher for target_lexicon::Triple {
false
}
}
Wasi => fam == &crate::targets::Family::wasm,
Wasi | WasiP1 | WasiP2 => fam == &crate::targets::Family::wasm,
Windows => fam == &crate::targets::Family::windows,
// I really dislike non-exhaustive :(
_ => false,
Expand All @@ -322,25 +327,37 @@ impl TargetMatcher for target_lexicon::Triple {
// this.
false
}
Os(os) => match os.0.parse::<OperatingSystem>() {
Ok(o) => match self.environment {
Environment::HermitKernel => os == &targ::Os::hermit,
_ => self.operating_system == o,
},
Err(_) => {
// Handle special case for darwin/macos, where the triple is
// "darwin", but rustc identifies the OS as "macos"
if os == &targ::Os::macos && self.operating_system == OperatingSystem::Darwin {
true
} else {
// For android, the os is still linux, but the environment is android
os == &targ::Os::android
&& self.operating_system == OperatingSystem::Linux
&& (self.environment == Environment::Android
|| self.environment == Environment::Androideabi)
Os(os) => {
if os == &targ::Os::wasi
&& matches!(
self.operating_system,
OperatingSystem::WasiP1 | OperatingSystem::WasiP2
)
{
return true;
}
match os.0.parse::<OperatingSystem>() {
Ok(o) => match self.environment {
Environment::HermitKernel => os == &targ::Os::hermit,
_ => self.operating_system == o,
},
Err(_) => {
// Handle special case for darwin/macos, where the triple is
// "darwin", but rustc identifies the OS as "macos"
if os == &targ::Os::macos
&& self.operating_system == OperatingSystem::Darwin
{
true
} else {
// For android, the os is still linux, but the environment is android
os == &targ::Os::android
&& self.operating_system == OperatingSystem::Linux
&& (self.environment == Environment::Android
|| self.environment == Environment::Androideabi)
}
}
}
},
}
Panic(_) => {
// panic support depends on the OS. Assume false for this.
false
Expand Down Expand Up @@ -435,7 +452,7 @@ pub enum Predicate<'a> {
/// when compiling without optimizations.
DebugAssertions,
/// [Enabled](https://doc.rust-lang.org/reference/conditional-compilation.html#proc_macro) for
/// crates of the proc_macro type.
/// crates of the `proc_macro` type.
ProcMacro,
/// A [`feature = "<name>"`](https://doc.rust-lang.org/nightly/cargo/reference/features.html)
Feature(&'a str),
Expand Down
6 changes: 3 additions & 3 deletions src/expr/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ pub enum Token<'a> {
Value(&'a str),
/// A '=', joining a key and a value
Equals,
/// Beginning of an all() predicate list
/// Beginning of an `all()` predicate list
All,
/// Beginning of an any() predicate list
/// Beginning of an `any()` predicate list
Any,
/// Beginning of a not() predicate
/// Beginning of a `not()` predicate
Not,
/// A `(` for starting a predicate list
OpenParen,
Expand Down
2 changes: 1 addition & 1 deletion src/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ pub struct TargetInfo {
/// [target_endian](https://doc.rust-lang.org/reference/conditional-compilation.html#target_endian)
/// predicate.
pub endian: Endian,
/// The target's support for atomics. Used by the has_target_atomics predicate.
/// The target's support for atomics. Used by the `has_target_atomics` predicate.
pub has_atomics: HasAtomics,
/// The panic strategy used on this target by default. Used by the
/// [panic](https://doc.rust-lang.org/beta/reference/conditional-compilation.html#panic) predicate.
Expand Down
Loading
Loading