3 unstable releases
0.2.0 | Jul 13, 2020 |
---|---|
0.1.1 | Jul 12, 2020 |
0.1.0 | Jul 12, 2020 |
#7 in #dep
27KB
477 lines
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
FOO
environment variable exists.
- Checks if the
#[realia::env("FOO", "bar")]
- Checks if the
FOO
environment variable has the valuebar
.
- Checks if the
- Executables:
#[realia::cmd("foo")]
- Checks if the executable
foo
exists in thePATH
environment variable.
- Checks if the executable
- Dependencies (accounts for target-specific ones, but not optional ones currently):
#[realia::dep("your-crate", "foo")]
- Checks if your crate uses any version of the
foo
crate.
- Checks if your crate uses any version of the
#[realia::dep("your-crate", "foo", "1.2.3")]
- Checks if your crate uses the
foo
crate with exactly version 1.2.3.
- Checks if your crate uses the
#[realia::dep_since("your-crate", "foo", "1.2.3")]
- Checks if your crate uses the
foo
crate with version 1.2.3 or newer.
- Checks if your crate uses the
#[realia::dep_before("your-crate", "foo", "1.2.3")]
- Checks if your crate uses the
foo
crate with a version before 1.2.3.
- Checks if your crate uses the
#[realia::dep_from_registry("your-crate", "foo")]
- Checks if your crate uses the
foo
crate from the registry (as opposed to being agit
orpath
dependency). This is useful if you have publishing fallbacks.
- Checks if your crate uses the
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 specifyconst
this way.
- Applies
Triggering build on changed conditions
If you use the env
or cmd
attributes,you'll need to include a build.rs
in your project with any environment variables you check.
fn main() {
// Necessary when using #[realia::env("FOO")]
println!("cargo:rerun-if-env-changed=FOO");
// Necessary when using #[realia::cmd(...)]
println!("cargo:rerun-if-env-changed=PATH");
}
Dependencies
~4–13MB
~183K SLoC