1 // BEGIN - Embark standard lints v0.3
2 // do not change or add/remove here, but one can add exceptions after this section
3 // for more info see: <https://github.com/EmbarkStudios/rust-ecosystem/issues/59>
4 #![deny(unsafe_code)]
5 #![warn(
6     clippy::all,
7     clippy::await_holding_lock,
8     clippy::dbg_macro,
9     clippy::debug_assert_with_mut_call,
10     clippy::doc_markdown,
11     clippy::empty_enum,
12     clippy::enum_glob_use,
13     clippy::exit,
14     clippy::explicit_into_iter_loop,
15     clippy::filter_map_next,
16     clippy::fn_params_excessive_bools,
17     clippy::if_let_mutex,
18     clippy::imprecise_flops,
19     clippy::inefficient_to_string,
20     clippy::large_types_passed_by_value,
21     clippy::let_unit_value,
22     clippy::linkedlist,
23     clippy::lossy_float_literal,
24     clippy::macro_use_imports,
25     clippy::map_err_ignore,
26     clippy::map_flatten,
27     clippy::map_unwrap_or,
28     clippy::match_on_vec_items,
29     clippy::match_same_arms,
30     clippy::match_wildcard_for_single_variants,
31     clippy::mem_forget,
32     clippy::mismatched_target_os,
33     clippy::needless_borrow,
34     clippy::needless_continue,
35     clippy::option_option,
36     clippy::pub_enum_variant_names,
37     clippy::ref_option_ref,
38     clippy::rest_pat_in_fully_bound_structs,
39     clippy::string_add_assign,
40     clippy::string_add,
41     clippy::string_to_string,
42     clippy::suboptimal_flops,
43     clippy::todo,
44     clippy::unimplemented,
45     clippy::unnested_or_patterns,
46     clippy::unused_self,
47     clippy::verbose_file_reads,
48     future_incompatible,
49     nonstandard_style,
50     rust_2018_idioms
51 )]
52 // END - Embark standard lints v0.3
53 
54 //! cfg-expr is a crate that can be used to parse and evaluate Rust cfg() expressions,
55 //! both as declarable in Rust code itself, as well in cargo's `[target.'cfg()'.dependencies]` sections.
56 //!
57 //! It contains a list of all builtin targets known to rustc as of 1.41 that can be used
58 //! to determine if a particular cfg expression is satisfiable.
59 //!
60 //! ```
61 //! use cfg_expr::{targets::get_builtin_target_by_triple, Expression, Predicate};
62 //!
63 //! let specific = Expression::parse(
64 //!     r#"all(
65 //!         target_os = "windows",
66 //!         target_arch = "x86",
67 //!         windows,
68 //!         target_env = "msvc",
69 //!         target_feature = "fxsr",
70 //!         target_feature = "sse",
71 //!         target_feature = "sse2",
72 //!         target_pointer_width = "32",
73 //!         target_endian = "little",
74 //!         not(target_vendor = "uwp"),
75 //!         feature = "cool_thing",
76 //!     )"#,
77 //! )
78 //! .unwrap();
79 //!
80 //! // cfg_expr includes a list of every builtin target in rustc (as of 1.41)
81 //! let x86_win = get_builtin_target_by_triple("i686-pc-windows-msvc").unwrap();
82 //! let x86_pentium_win = get_builtin_target_by_triple("i586-pc-windows-msvc").unwrap();
83 //! let uwp_win = get_builtin_target_by_triple("i686-uwp-windows-msvc").unwrap();
84 //! let mac = get_builtin_target_by_triple("x86_64-apple-darwin").unwrap();
85 //!
86 //! let avail_targ_feats = ["fxsr", "sse", "sse2"];
87 //!
88 //! // This will satisfy all requirements
89 //! assert!(specific.eval(|pred| {
90 //!     match pred {
91 //!         Predicate::Target(tp) => tp.matches(x86_win),
92 //!         Predicate::TargetFeature(feat) => avail_targ_feats.contains(feat),
93 //!         Predicate::Feature(feat) => *feat == "cool_thing",
94 //!         _ => false,
95 //!     }
96 //! }));
97 //!
98 //! // This won't, it doesnt' have the cool_thing feature!
99 //! assert!(!specific.eval(|pred| {
100 //!     match pred {
101 //!         Predicate::Target(tp) => tp.matches(x86_pentium_win),
102 //!         Predicate::TargetFeature(feat) => avail_targ_feats.contains(feat),
103 //!         _ => false,
104 //!     }
105 //! }));
106 //!
107 //! // This will *not* satisfy the vendor predicate
108 //! assert!(!specific.eval(|pred| {
109 //!     match pred {
110 //!         Predicate::Target(tp) => tp.matches(uwp_win),
111 //!         Predicate::TargetFeature(feat) => avail_targ_feats.contains(feat),
112 //!         _ => false,
113 //!     }
114 //! }));
115 //!
116 //! // This will *not* satisfy the vendor, os, or env predicates
117 //! assert!(!specific.eval(|pred| {
118 //!     match pred {
119 //!         Predicate::Target(tp) => tp.matches(mac),
120 //!         Predicate::TargetFeature(feat) => avail_targ_feats.contains(feat),
121 //!         _ => false,
122 //!     }
123 //! }));
124 //! ```
125 
126 /// Types related to parse errors
127 pub mod error;
128 /// Types related to cfg expressions
129 pub mod expr;
130 /// Types related to rustc targets
131 pub mod targets;
132 
133 pub use error::ParseError;
134 pub use expr::{Expression, Predicate, TargetPredicate};
135 
136 #[cfg(feature = "targets")]
137 pub use target_lexicon;
138