Expand description
Build-time generation of dependency license notices.
This crate is the build-script half of the notalawyer family. Called from
a crate’s build.rs, it gathers the license texts of all dependencies
(using the cargo_about library) and writes a single NOTICE file into
OUT_DIR.
The other two crates consume that file at compile time and runtime:
notalawyer-build(this crate) writes theNOTICEfile frombuild.rs.notalawyerembeds it viainclude_notice!.notalawyer-clapexposes it behind a--license-noticeCLI flag.
License acceptance and gathering are configured through an about.toml
file, searched for from the consuming crate’s manifest directory upward;
see cargo-about for its
format.
§Choosing a renderer
There are three entry points, in increasing order of control:
buildwrites the built-in default format. This is all most crates need.build_withgathers the data, hands you aNotice, and writes whateverStringyour closure returns.try_build_withis the fallible variant for renderers (templating engines, etc.) that can fail.
gather is the lowest level: it returns a Notice and writes nothing,
so you can inspect or serialize the data yourself. The Notice,
License, UsedBy and Package types are owned and implement
serde::Serialize, so you can feed them straight into your own
templating engine without any of cargo-about’s lifetime-bound types
leaking into your build script.
§Example
Add notalawyer-build as a build dependency and call build from the
main of your build.rs:
// build.rs
println!("cargo:rerun-if-changed=Cargo.toml");
notalawyer_build::build();To customize the output, render a Notice yourself:
// build.rs
use std::fmt::Write as _;
notalawyer_build::build_with(|notice| {
let mut out = String::new();
for license in ¬ice.licenses {
writeln!(out, "## {} ({})", license.name, license.id).unwrap();
out.push_str(&license.text);
}
out
});Structs§
- License
- A single license text and the crates that use it.
- Notice
- A complete license notice: every distinct license text and the flat list of crates it was gathered from.
- Package
- An owned description of a single crate/package.
- UsedBy
- A single “crate uses this license” entry.
Enums§
- Error
- An error from
try_build_with.
Functions§
- build
- Gather dependency licenses and write the
NOTICEfile intoOUT_DIRusing the built-in default format. - build_
with - Gather licenses, render them with
render, and write the result to$OUT_DIR/notalawyer. - gather
- Gather dependency license data without writing anything.
- try_
build_ with - Fallible variant of
build_withfor renderers that can fail (templating engines, etc.).