embed_licensing/lib.rs
1// SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
2//
3// SPDX-License-Identifier: MPL-2.0
4
5//! Proc-macro for embedding licensing information about a crate.
6//!
7//! It also exposes its internal functions that allow
8//! either collecting licensing information at runtime (with [`collect()`]),
9//! when in the directory of the manifest,
10//! or collecting licensing information from a specific manifest file (with
11//! [`collect_from_manifest`]).
12//!
13//! However, the recommended way to use this crate is the macro [`collect!`]:
14//!
15//! ```rust
16//! # #[cfg(feature = "macros")]
17//! # {
18//! let licensing = embed_licensing::collect!();
19//!
20//! for package in licensing.packages {
21//! if let embed_licensing::CrateLicense::SpdxExpression(expr) = package.license {
22//! println!("{} {} ({})", package.name, package.version, expr);
23//! } else {
24//! println!("{} {} uses custom license", package.name, package.version);
25//! }
26//! }
27//! # }
28//! ```
29
30#![cfg_attr(docsrs, feature(doc_cfg))]
31#![cfg_attr(docsrs, feature(doc_auto_cfg))]
32
33pub use embed_licensing_core::{
34 collect, collect_from_manifest, CollectConfig, CollectPlatform, Crate, CrateLicense, Error,
35 Licensing,
36};
37
38/// Collect licensing information at build-time.
39///
40/// It takes the same arguments as [`CollectConfig`].
41/// Please see the examples for the format.
42///
43/// # Examples
44///
45/// ```
46/// # #[macro_use] extern crate embed_licensing_macros;
47/// # use embed_licensing_core::*;
48/// collect!(); // collect only normal dependencies
49/// collect!(build); // collect normal and build dependencies
50/// collect!(dev); // collect normal and (direct) development dependencies
51/// collect!(build, dev); // collect normal, build and (direct) development dependencies
52///
53/// collect!(build = true); // boolean arguments can also be explicitly set to true
54/// collect!(build = false); // … or to false (which is the default for `build`)
55///
56/// collect!(platform(any)); // collect dependencies regardless of platform
57/// // only collect dependencies corresponding to the specified platform
58/// collect!(platform(static(target = "aarch64-apple-darwin", cfg(target_os = "macos", target_family = "unix", unix))));
59/// #[cfg(feature = "current_platform")]
60/// collect!(platform(current)); // collect dependencies for current platform
61/// ```
62#[cfg(feature = "macros")]
63pub use embed_licensing_macros::collect;