Crates.io | realia |
lib.rs | realia |
version | 0.2.0 |
source | src |
created_at | 2020-07-12 00:42:54.18538 |
updated_at | 2020-07-13 17:30:15.44067 |
description | Extra conditional compilation macros |
homepage | |
repository | https://github.com/mtkennerly/realia |
max_upload_size | |
id | 264238 |
size | 32,831 |
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.
Primary:
#[realia::env("FOO")]
FOO
environment variable exists.#[realia::env("FOO", "bar")]
FOO
environment variable has the value bar
.#[realia::cmd("foo")]
foo
exists in the PATH
environment variable.#[realia::dep("your-crate", "foo")]
foo
crate.#[realia::dep("your-crate", "foo", "1.2.3")]
foo
crate with exactly version 1.2.3.#[realia::dep_since("your-crate", "foo", "1.2.3")]
foo
crate with version 1.2.3 or newer.#[realia::dep_before("your-crate", "foo", "1.2.3")]
foo
crate with a version before 1.2.3.#[realia::dep_from_registry("your-crate", "foo")]
foo
crate from the registry (as opposed to
being a git
or path
dependency). This is useful if you have
publishing fallbacks.The above can be refined or augmented by these additional attributes:
#[realia::not(env("FOO"))]
#[realia::any(env("FOO"), env("bar"))]
#[realia::all(env("FOO"), env("bar"))]
#[realia::attr(env("FOO"), some_attr)]
#[some_attr]
if the condition is met.
You can also specify const
this way.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");
}