Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dtolnay/efg
Conditional compilation using boolean expression syntax, rather than any(), all(), not()
https://github.com/dtolnay/efg
Last synced: 5 days ago
JSON representation
Conditional compilation using boolean expression syntax, rather than any(), all(), not()
- Host: GitHub
- URL: https://github.com/dtolnay/efg
- Owner: dtolnay
- License: apache-2.0
- Archived: true
- Created: 2021-12-05T18:38:04.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-12-18T20:47:04.000Z (almost 2 years ago)
- Last Synced: 2024-05-09T09:38:25.208Z (6 months ago)
- Language: Rust
- Homepage:
- Size: 91.8 KB
- Stars: 295
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE-APACHE
Awesome Lists containing this project
README
Conditional compilation expressions
===================================[](https://github.com/dtolnay/efg)
[](https://crates.io/crates/efg)
[](https://docs.rs/efg)
[](https://github.com/dtolnay/efg/actions?query=branch%3Amaster)Conditional compilation using boolean expression syntax, rather than *any()*,
*all()*, *not()*.```toml
[dependencies]
efg = "0.1"
```
## Summary
Rust's `cfg` and `cfg_attr` conditional compilation attributes use a restrictive
domain-specific language for specifying configuration predicates. The syntax is
described in the *[Conditional compilation]* page of the Rust reference. The
reason for this syntax as opposed to ordinary boolean expressions was to
accommodate restrictions that old versions of rustc used to have on the grammar
of attributes.However, all restrictions on the attribute grammar were lifted in Rust 1.18.0 by
[rust-lang/rust#40346]. This crate explores implementing conditional compilation
using ordinary boolean expressions
instead: `&&`, `||`, `!` as usual in Rust syntax.[Conditional compilation]: https://doc.rust-lang.org/1.57.0/reference/conditional-compilation.html
[rust-lang/rust#40346]: https://github.com/rust-lang/rust/pull/40346built into rustcthis crate
#[cfg(any(thing1, thing2, …))]
#[efg(thing1 || thing2 || …)]
#[cfg(all(thing1, thing2, …))]
#[efg(thing1 && thing2 && …)]
#[cfg(not(thing))]
#[efg(!thing)]
## Examples
A real-world example from the `quote` crate:
```rust
#[efg(feature "proc-macro" && !(target_arch "wasm32" && target_os "unknown"))]
extern crate proc_macro;
```and from the `proc-macro2` crate:
```rust
#[efg(super_unstable || feature "span-locations")]
pub fn start(&self) -> LineColumn {
```
#### License
Licensed under either of Apache License, Version
2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.