Debian Codegraph @

debian/missing-sources/cfg-expr/README.md

raw symbols SCIP
1 <!-- markdownlint-disable no-inline-html first-line-heading -->
2
3 <div align="center">
4
5 # `⚙️ cfg-expr`
6
7 **A parser and evaluator for Rust `cfg()` expressions. Builtin targets as of [1.93.0] are supported.**
8
9 [![Build Status](https://github.com/EmbarkStudios/cfg-expr/workflows/CI/badge.svg)](https://github.com/EmbarkStudios/cfg-expr/actions?workflow=CI)
10 [![Crates.io](https://img.shields.io/crates/v/cfg-expr.svg)](https://crates.io/crates/cfg-expr)
11 [![Docs](https://docs.rs/cfg-expr/badge.svg)](https://docs.rs/cfg-expr)
12 [![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)
13 [![Rust Targets](https://img.shields.io/badge/Rust%20Targets-1.93.0-blue.svg)](https://forge.rust-lang.org/release/platform-support.html)
14 [![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-v2.0%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)
15 [![Embark](https://img.shields.io/badge/embark-open%20source-blueviolet.svg)](https://embark.dev)
16 </div>
17
18 ## Alternatives
19
20 - [cargo-platform](https://crates.io/crates/cargo-platform)
21 - [parse_cfg](https://crates.io/crates/parse_cfg)
22
23 ## Usage
24
25 `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.
26
27 It contains a list of all builtin targets known to rustc as of [1.93.0] that can be used to determine if a particular cfg expression is satisfiable.
28
29 ```rust
30 use cfg_expr::{targets::get_builtin_target_by_triple, Expression, Predicate};
31
32 let specific = Expression::parse(
33 r#"all(
34 target_os = "windows",
35 target_arch = "x86",
36 windows,
37 target_env = "msvc",
38 target_feature = "fxsr",
39 target_feature = "sse",
40 target_feature = "sse2",
41 target_pointer_width = "32",
42 target_endian = "little",
43 not(target_vendor = "uwp"),
44 feature = "cool_thing",
45 )"#,
46 ).unwrap();
47
48 // cfg_expr includes a list of every builtin target in rustc
49 let x86_win = get_builtin_target_by_triple("i686-pc-windows-msvc").unwrap();
50 let uwp_win = get_builtin_target_by_triple("i686-uwp-windows-msvc").unwrap();
51 let mac = get_builtin_target_by_triple("x86_64-apple-darwin").unwrap();
52
53 let avail_target_feats = ["fxsr", "sse", "sse2"];
54
55 // This will satisfy all requirements
56 assert!(specific.eval(|pred| {
57 match pred {
58 Predicate::Target(tp) => tp.matches(x86_win),
59 Predicate::TargetFeature(feat) => avail_target_feats.contains(feat),
60 Predicate::Feature(feat) => *feat == "cool_thing",
61 _ => false,
62 }
63 }));
64
65 // This will *not* satisfy the vendor predicate
66 assert!(!specific.eval(|pred| {
67 match pred {
68 Predicate::Target(tp) => tp.matches(uwp_win),
69 Predicate::TargetFeature(feat) => avail_target_feats.contains(feat),
70 _ => false,
71 }
72 }));
73
74 // This will *not* satisfy the vendor, os, or env predicates
75 assert!(!specific.eval(|pred| {
76 match pred {
77 Predicate::Target(tp) => tp.matches(mac),
78 Predicate::TargetFeature(feat) => avail_target_feats.contains(feat),
79 _ => false,
80 }
81 }));
82 ```
83
84 ## Contributing
85
86 We welcome community contributions to this project.
87
88 Please read our [Contributor Guide](CONTRIBUTING.md) for more information on how to get started.
89
90 ## License
91
92 Licensed under either of
93
94 - Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
95 - MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
96
97 at your option.
98
99 ### Contribution
100
101 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.
102
103 [1.93.0]: (https://forge.rust-lang.org/release/platform-support.html)