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

Related tags

Data structures efg
Overview

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 rustc this 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.
You might also like...
Eternally liquid. Forward compatible. Nested, conditional, & Multi-resourced NFTs.
Eternally liquid. Forward compatible. Nested, conditional, & Multi-resourced NFTs.

RMRK Substrate Rust Setup First, complete the basic Rust setup instructions. Run Use Rust's native cargo command to build and launch the template node

Simple expression transformer that is not Coq.

Noq Not Coq. Simple expression transformer that is not Coq. Quick Start $ cargo run ./examples/add.noq Main Idea The Main Idea is being able to define

Rust regex in ECMAScript regular expression syntax!

ecma_regex The goal of ecma_regex is to provide the same functionality as the regex crate in ECMAScript regular expression syntax. Reliable regex engi

Bitpack a boolean into a pointer using bit magic.

ptr-bool tl;dr: a pointer and boolean with the same size as a pointer. A convenience crate used to bitpack a boolean and pointer into the same eight b

An expression based data notation, aimed at transpiling itself to any cascaded data notation.

Lala An expression oriented data notation, aimed at transpiling itself to any cascaded data notation. Lala is separated into three components: Nana, L

A working example of multi targets compilation for Rust using Github Actions.

A working example of multi targets compilation for Rust using Github Actions. Supports Windows, MacOSX, x86_64, ARM and Raspberry PI Linux.

Compiler & Interpreter for the (rather new and very experimental) Y programming language.

Y Lang Why would anyone build a new (and rather experimental) language with no real world use case. Design Y (pronounced as why) is based on the idea

Choose Rust types at compile-time via boolean constants

condtype Choose Rust types at compile-time via boolean constants, brought to you by Nikolai Vazquez. If you find this library useful, consider starrin

Supporting code for the paper "Optimized Homomorphic Evaluation of Boolean Functions" submitted to Eurocrypt 2024

This repository contains the code related to the paper Optimized Homomorphic Evaluation of Boolean Functions. The folder search_algorithm contains the

Single-side boolean deserializers.

serde-bool Single value, true or false, boolean deserializers. Examples Supporting serde untagged enums where only one boolean value is valid, allowin

Simple library to host lv2 plugins. Is not meant to support any kind of GUI.

lv2-host-minimal Simple library to host lv2 plugins. Is not meant to support any kind of GUI. Host fx plugins (audio in, audio out) Set parameters Hos

A lightweight microkernel/IPC based operating system built with Rust which is not a clone of any existing operating system
A lightweight microkernel/IPC based operating system built with Rust which is not a clone of any existing operating system

Noble Operating System Noble is a lightweight microkernel and IPC based operating system built with Rust which is not a clone of any existing operatin

ISG lets you use YouTube as cloud storage for ANY files, not just video
ISG lets you use YouTube as cloud storage for ANY files, not just video

I was working on this instead of my finals, hope you appreciate it. I'll add all relevant executables when I can Infinite-Storage-Glitch AKA ISG (writ

A special rope, designed to work with any data type that is not String

AnyRope AnyRope is an arbitrary data type rope for Rust, designed for similar operations that a rope would do, but targeted at data types that are not

syntect is a syntax highlighting library for Rust that uses Sublime Text syntax definitions.
syntect is a syntax highlighting library for Rust that uses Sublime Text syntax definitions.

syntect is a syntax highlighting library for Rust that uses Sublime Text syntax definitions. It aims to be a good solution for any Rust project that needs syntax highlighting, including deep integration with text editors written in Rust.

Count your code by tokens, types of syntax tree nodes, and patterns in the syntax tree. A tokei/scc/cloc alternative.

tcount (pronounced "tee-count") Count your code by tokens, types of syntax tree nodes, and patterns in the syntax tree. Quick Start Simply run tcount

A language that ports⚓: examining the limits of compilation⚙️.
A language that ports⚓: examining the limits of compilation⚙️.

⚓ harbor ⚓ A language that ports: examining the limits of compilation. Demo | Crates | Contact Me Written in Rust 🦀 💖 NOTE: Click the images above f

Create target folder as a RAMdisk for faster Rust compilation.

cargo-ramdisk This crate is only supported for unix like systems! cargo-ramdisk creates a ramdisk at the target folder of your project for ridiculousl

auto-rust is an experimental project that aims to automatically generate Rust code with LLM (Large Language Models) during compilation, utilizing procedural macros.
auto-rust is an experimental project that aims to automatically generate Rust code with LLM (Large Language Models) during compilation, utilizing procedural macros.

Auto Rust auto-rust is an experimental project that aims to automatically generate Rust code with LLM (Large Language Models) during compilation, util

Comments
  • Suggestion: change `=` operator to `==` and add `!=` in 0.2

    Suggestion: change `=` operator to `==` and add `!=` in 0.2

    First of all, I think this crate is a great idea! It always irked me how verbose the syntax for cfg was compared to regular Rust.

    Suggestion: if we're going for syntax simplification, I'd love to also simplify frequent not(feature = "somefeature") not only to !(feature = "somefeature") but all the way to feature != "somefeature".

    It feels a lot more natural to use != operator, but I suspect it will also require changing = to more Rust-like ==. It would be a breaking change, but perhaps a good thing for consistency with the rest of Rust syntax.

    opened by RReverser 5
  • specifying ranges

    specifying ranges

    https://github.com/rust-lang/rfcs/pull/3036 describes a family of predicates to target minimum versions of platform APIs. For example min_libc_version would return the version of libc. It was expected that max_* variants would be specified eventually as well [^max], allowing ranges of OS versions to be targeted.

    Unfortunately the RFC hasn't seen any updates in a while, but the challenges it attempts to address still exist. I'm wondering whether efg could help prototype syntax to specify ranges within attributes. It'd be neat if we could target a specific version range Windows by writing something like this:

    #[cfg(windows && os_version >= "6.0.6000" && os_version < "7.3.5000")]
    

    Or possibly taking it further and allowing shorthands such as:

    #[cfg(windows && "6.0.6000" <= os_version < "7.3.5000")]
    

    I'm not sure what this feature should look like, but I think having the ability to specify ranges using shorthands would be neat as well. What do you think?

    [^max]: Being able to specify the maximum OS version is useful when you're writing polyfills for older versions. This would allow a developers to say something like: "This code runs on windows 10+ only", which can be leveraged to produce more optimized code.

    opened by yoshuawuyts 2
Releases(0.1.3)
Owner
David Tolnay
David Tolnay
Algorithms and Data Structures of all kinds written in Rust.

Classic Algorithms in Rust This repo contains the implementation of various classic algorithms for educational purposes in Rust. Right now, it is in i

Alexander González 49 Dec 14, 2022
All Algorithms implemented in Rust

The Algorithms - Rust All algorithms implemented in Rust (for educational purposes) These are for demonstration purposes only. RESTART BUILD Sort Algo

The Algorithms 13.1k Dec 26, 2022
enum-map enum-map xfix/enum-map [enum-map] — An optimized map implementation for enums using an array to store values.

enum-map A library providing enum map providing type safe enum array. It is implemented using regular Rust arrays, so using them is as fast as using r

Konrad Borowski 57 Dec 19, 2022
Library containing various Data Structures implemented using Rust.

rust-data-structures Library containing various Data Structures implemented using Rust. Running You can test the library by running cargo test, an exa

c1m50c 1 Jan 6, 2022
Coding-challenge - Algorithms and Data-structures, problems and solutions in Rust language using cargo-workspaces

Coding Challenge LeetCode/Hackerrank e.t.c Using this as an opportunity to improve my knowledge of rust lang If you found this repo useful to you, add

Tolumide Shopein 17 Apr 24, 2022
Starlight is a JS engine in Rust which focuses on performance rather than ensuring 100% safety of JS runtime.

starlight Starlight is a JS engine in Rust which focuses on performance rather than ensuring 100% safety of JS runtime. Features Bytecode interpreter

null 453 Dec 31, 2022
GGML bindings that aim to be idiomatic Rust rather than directly corresponding to the C/C++ interface

rusty-ggml GGML bindings that aim to be idiomatic Rust rather than directly corresponding to the C/C++ interface. GG-what? See: https://github.com/gge

Kerfuffle 6 May 16, 2023
🧮 Boolean expression evaluation engine. A Rust port of boolrule.

coolrule My blog post: Porting Boolrule to Rust Boolean expression evaluation engine (a port of boolrule to Rust). // Without context let expr = coolr

Andrew Healey 3 Aug 21, 2023
Explain semver requirements by converting them into less than, greater than, and/or equal to form.

semver-explain Convert SemVer requirements to their most-obvious equivalents. semver-explain is a CLI tool to explain Semantic Versioning requirements

Andrew Lilley Brinker 27 Oct 29, 2022
Pure Rust port of CRFsuite: a fast implementation of Conditional Random Fields (CRFs)

crfs-rs Pure Rust port of CRFsuite: a fast implementation of Conditional Random Fields (CRFs) Currently only support prediction, model training is not

messense 24 Nov 23, 2022