Skip to content

Commit

Permalink
export feature for each found dependency
Browse files Browse the repository at this point in the history
This can be used to check if an optional dep has been found or not.

Fix #27
  • Loading branch information
Guillaume Desmottes authored and gdesmott committed Feb 10, 2021
1 parent 0e3cf72 commit 2feeb8c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,19 @@
//!
//! ```toml
//! [package.metadata.system-deps]
//! testdata = { version = "4.5", optional = true }
//! test-data = { version = "4.5", optional = true }
//! testmore = { version = "2", v3 = { version = "3.0", optional = true }}
//! ```
//!
//! `system-deps` will automatically export for each dependency a feature `system_deps_have_$DEP` where `$DEP`
//! is the `toml` key defining the dependency in [snake_case](https://en.wikipedia.org/wiki/Snake_case).
//! This can be used to check if an optional dependency has been found or not:
//!
//! ```
//! #[cfg(system_deps_have_testdata)]
//! println!("found test-data");
//! ```
//!
//! # Overriding library name
//! `toml` keys cannot contain dot characters so if your library name does you can define it using the `name` field:
//!
Expand Down Expand Up @@ -131,7 +140,7 @@ extern crate lazy_static;
#[cfg(test)]
mod test;

use heck::ShoutySnakeCase;
use heck::{ShoutySnakeCase, SnakeCase};
use std::collections::HashMap;
use std::env;
use std::fmt;
Expand Down Expand Up @@ -314,6 +323,10 @@ impl Config {
// Output cargo flags
println!("{}", flags);

for (name, _) in libraries.iter() {
println!("cargo:rustc-cfg=system_deps_have_{}", name.to_snake_case());
}

Ok(libraries)
}

Expand Down

0 comments on commit 2feeb8c

Please sign in to comment.