Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- next-header -->
## [Unreleased] - ReleaseDate
### Changed
- [PR#85](https://github.com/EmbarkStudios/cfg-expr/pull/85) updated the builtin target list to 1.92.0.

## [0.20.4] - 2025-10-31
### Changed
- [PR#83](https://github.com/EmbarkStudios/cfg-expr/pull/83) updated the builtin target list to 1.91.0.
Expand Down
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.91.0] are supported.**
**A parser and evaluator for Rust `cfg()` expressions. Builtin targets as of [1.92.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.91.0-blue.svg)](https://forge.rust-lang.org/release/platform-support.html)
[![Rust Targets](https://img.shields.io/badge/Rust%20Targets-1.92.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.91.0] 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.92.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 @@ -100,4 +100,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.91.0]: (https://forge.rust-lang.org/release/platform-support.html)
[1.92.0]: (https://forge.rust-lang.org/release/platform-support.html)
26 changes: 24 additions & 2 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ impl TargetMatcher for target_lexicon::Triple {
const NUTTX: tl::Vendor = tl::Vendor::Custom(tl::CustomVendor::Static("nuttx"));
const RTEMS: tl::Vendor = tl::Vendor::Custom(tl::CustomVendor::Static("rtems"));
const WALI: tl::Vendor = tl::Vendor::Custom(tl::CustomVendor::Static("wali"));
const WASIP3: tl::Vendor = tl::Vendor::Custom(tl::CustomVendor::Static("wasip3"));

match tp {
Abi(_) => {
Expand Down Expand Up @@ -205,6 +206,8 @@ impl TargetMatcher for target_lexicon::Triple {
| env::Sim
| env::None
)
} else if env == &targ::Env::p3 {
self.vendor == WASIP3
} else {
match env.0.parse::<env>() {
Ok(e) => {
Expand Down Expand Up @@ -332,7 +335,9 @@ impl TargetMatcher for target_lexicon::Triple {
false
}
Os(os) => {
if os == &targ::Os::wasi && matches!(self.operating_system, os::WasiP1 | os::WasiP2)
if os == &targ::Os::wasi
&& (matches!(self.operating_system, os::WasiP1 | os::WasiP2)
|| self.vendor == WASIP3)
|| (os == &targ::Os::nuttx && self.vendor == NUTTX)
|| (os == &targ::Os::rtems && self.vendor == RTEMS)
{
Expand Down Expand Up @@ -367,7 +372,10 @@ impl TargetMatcher for target_lexicon::Triple {
Vendor(ven) => match ven.0.parse::<target_lexicon::Vendor>() {
Ok(v) => {
if self.vendor == v
|| ((self.vendor == NUTTX || self.vendor == RTEMS || self.vendor == WALI)
|| ((self.vendor == NUTTX
|| self.vendor == RTEMS
|| self.vendor == WALI
|| self.vendor == WASIP3)
&& ven == &targ::Vendor::unknown)
{
true
Expand Down Expand Up @@ -700,6 +708,20 @@ impl PartialEq for Expression {
}
}

impl std::str::FromStr for Expression {
type Err = crate::error::ParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Expression::parse(s)
}
}

impl std::fmt::Display for Expression {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.original)
}
}

/// A propositional logic used to evaluate `Expression` instances.
///
/// An `Expression` consists of some predicates and the `any`, `all` and `not` operators. An
Expand Down
30 changes: 29 additions & 1 deletion src/targets/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use super::*;

pub(crate) const RUSTC_VERSION: &str = "1.91.0";
pub(crate) const RUSTC_VERSION: &str = "1.92.0";

pub const ALL_BUILTINS: &[TargetInfo] = &[
TargetInfo {
Expand Down Expand Up @@ -3224,6 +3224,19 @@ pub const ALL_BUILTINS: &[TargetInfo] = &[
has_atomics: HasAtomics::atomic_8_16_32_64_ptr,
panic: Panic::abort,
},
TargetInfo {
triple: Triple::new_const("wasm32-wasip3"),
os: Some(Os::wasi),
abi: None,
arch: Arch::wasm32,
env: Some(Env::p3),
vendor: Some(Vendor::unknown),
families: Families::wasm,
pointer_width: 32,
endian: Endian::little,
has_atomics: HasAtomics::atomic_8_16_32_64_ptr,
panic: Panic::abort,
},
TargetInfo {
triple: Triple::new_const("wasm32v1-none"),
os: None,
Expand Down Expand Up @@ -3653,6 +3666,19 @@ pub const ALL_BUILTINS: &[TargetInfo] = &[
has_atomics: HasAtomics::atomic_8_16_32_64_ptr,
panic: Panic::unwind,
},
TargetInfo {
triple: Triple::new_const("x86_64-unknown-motor"),
os: Some(Os::motor),
abi: None,
arch: Arch::x86_64,
env: None,
vendor: Some(Vendor::unknown),
families: Families::new_const(&[]),
pointer_width: 64,
endian: Endian::little,
has_atomics: HasAtomics::atomic_8_16_32_64_ptr,
panic: Panic::abort,
},
TargetInfo {
triple: Triple::new_const("x86_64-unknown-netbsd"),
os: Some(Os::netbsd),
Expand Down Expand Up @@ -3987,6 +4013,7 @@ impl super::Os {
pub const lynxos178: Os = Os::new_const("lynxos178");
pub const macos: Os = Os::new_const("macos");
pub const managarm: Os = Os::new_const("managarm");
pub const motor: Os = Os::new_const("motor");
pub const netbsd: Os = Os::new_const("netbsd");
pub const nto: Os = Os::new_const("nto");
pub const nuttx: Os = Os::new_const("nuttx");
Expand Down Expand Up @@ -4045,6 +4072,7 @@ impl super::Env {
pub const ohos: Env = Env::new_const("ohos");
pub const p1: Env = Env::new_const("p1");
pub const p2: Env = Env::new_const("p2");
pub const p3: Env = Env::new_const("p3");
pub const relibc: Env = Env::new_const("relibc");
pub const sgx: Env = Env::new_const("sgx");
pub const sim: Env = Env::new_const("sim");
Expand Down