MCPcopy Index your code
hub / github.com/EmbarkStudios/cfg-expr

github.com/EmbarkStudios/cfg-expr @0.20.8

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.20.8 ↗ · + Follow
103 symbols 148 edges 12 files 8 documented · 8%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

⚙️ cfg-expr

A parser and evaluator for Rust cfg() expressions. Builtin targets as of 1.96.0 are supported.

Build Status crates.io Docs Minimum Supported Rust Version Rust Targets Contributor Covenant Embark

Alternatives

Usage

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.96.0 that can be used to determine if a particular cfg expression is satisfiable.

use cfg_expr::{targets::get_builtin_target_by_triple, Expression, Predicate};

let specific = Expression::parse(
    r#"all(
        target_os = "windows",
        target_arch = "x86",
        windows,
        target_env = "msvc",
        target_feature = "fxsr",
        target_feature = "sse",
        target_feature = "sse2",
        target_pointer_width = "32",
        target_endian = "little",
        not(target_vendor = "uwp"),
        feature = "cool_thing",
    )"#,
).unwrap();

// cfg_expr includes a list of every builtin target in rustc
let x86_win = get_builtin_target_by_triple("i686-pc-windows-msvc").unwrap();
let uwp_win = get_builtin_target_by_triple("i686-uwp-windows-msvc").unwrap();
let mac = get_builtin_target_by_triple("x86_64-apple-darwin").unwrap();

let avail_target_feats = ["fxsr", "sse", "sse2"];

// This will satisfy all requirements
assert!(specific.eval(|pred| {
    match pred {
        Predicate::Target(tp) => tp.matches(x86_win),
        Predicate::TargetFeature(feat) => avail_target_feats.contains(feat),
        Predicate::Feature(feat) => *feat == "cool_thing",
        _ => false,
    }
}));

// This will *not* satisfy the vendor predicate
assert!(!specific.eval(|pred| {
    match pred {
        Predicate::Target(tp) => tp.matches(uwp_win),
        Predicate::TargetFeature(feat) => avail_target_feats.contains(feat),
        _ => false,
    }
}));

// This will *not* satisfy the vendor, os, or env predicates
assert!(!specific.eval(|pred| {
    match pred {
        Predicate::Target(tp) => tp.matches(mac),
        Predicate::TargetFeature(feat) => avail_target_feats.contains(feat),
        _ => false,
    }
}));

Contributing

We welcome community contributions to this project.

Please read our Contributor Guide for more information on how to get started.

License

Licensed under either of

at your option.

Contribution

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.

Extension points exported contracts — how you extend this code

Logic (Interface)
A propositional logic used to evaluate `Expression` instances. An `Expression` consists of some predicates and the `any [2 …
src/expr.rs
GroupElement (Interface)
(no doc) [2 implementers]
update/src/main.rs
TargetMatcher (Interface)
(no doc) [2 implementers]
src/expr.rs

Core symbols most depended-on inside this repo

len
called by 15
src/expr/lexer.rs
write_impls
called by 7
update/src/main.rs
get_builtin_target_by_triple
called by 6
src/targets.rs
insert
called by 6
update/src/main.rs
write_group_str
called by 4
update/src/main.rs
contains
called by 2
src/targets.rs
to_pred
called by 2
src/expr.rs
insert_group
called by 2
update/src/main.rs

Shape

Function 38
Method 33
Class 19
Enum 10
Interface 3

Languages

Rust100%

Modules by API surface

src/targets.rs25 symbols
src/expr.rs23 symbols
update/src/main.rs15 symbols
tests/eval.rs9 symbols
src/expr/lexer.rs9 symbols
tests/parser.rs8 symbols
tests/lexer.rs6 symbols
src/error.rs5 symbols
src/expr/parser.rs2 symbols
examples/eval.rs1 symbols

For agents

$ claude mcp add cfg-expr \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact