Realia
This crate provides macros for conditional compilation based on various checks.
These macros are analogous to #[cfg(...)] and #[cfg_attr(...)].
Realia is inspired by and heavily based on rustversion.
Attributes
Primary:
- Environment variables:
#[realia::env("FOO")]- Checks if the
FOOenvironment variable exists.
- Checks if the
#[realia::env("FOO", "bar")]- Checks if the
FOOenvironment variable has the valuebar.
- Checks if the
- Executables:
#[realia::cmd("foo")]- Checks if the executable
fooexists in thePATHenvironment variable.
- Checks if the executable
The above can be refined or augmented by these additional attributes:
#[realia::not(env("FOO"))]- Inverts the condition.
#[realia::any(env("FOO"), env("bar"))]- Checks if any of the conditions are met.
#[realia::all(env("FOO"), env("bar"))]- Checks if all of the conditions are met.
#[realia::attr(env("FOO"), some_attr)]- Applies
#[some_attr]if the condition is met. You can also specifyconstthis way.
- Applies
Triggering build on changed conditions
To trigger builds when the conditions change, you'll need to include a
build.rs in your project with the environment variables you check.