Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
/ efg Public archive

Conditional compilation using boolean expression syntax, rather than any(), all(), not()

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

dtolnay/efg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Conditional compilation expressions

github crates.io docs.rs build status

Conditional compilation using boolean expression syntax, rather than any(), all(), not().

[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.

built 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:

#[efg(feature "proc-macro" && !(target_arch "wasm32" && target_os "unknown"))]
extern crate proc_macro;

and from the proc-macro2 crate:

#[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.

About

Conditional compilation using boolean expression syntax, rather than any(), all(), not()

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Code of conduct

Security policy

Stars

Watchers

Forks

Languages