#license #build-time #fetch #embed #find #build-script #about

build license-fetcher

Fetch licenses of dependencies at build time and embed them into your program

11 releases (5 breaking)

0.6.3 Jan 27, 2025
0.6.2 Jan 27, 2025
0.5.0 Oct 27, 2024
0.4.1 Oct 11, 2024
0.1.1 Sep 16, 2024

#176 in Build Utils

Download history 128/week @ 2024-10-22 44/week @ 2024-10-29 12/week @ 2024-11-05 7/week @ 2024-11-19 18/week @ 2024-11-26 1/week @ 2024-12-03 20/week @ 2024-12-10 1/week @ 2024-12-31 130/week @ 2025-01-14 991/week @ 2025-01-21 463/week @ 2025-01-28 47/week @ 2025-02-04

1,631 downloads per month
Used in 2 crates

BSL-1.0 license

65KB
502 lines

license-fetcher

Fetch licenses of dependencies at build time and embed them into your program.

Crates.io Version GitHub License docs.rs dependency status

Aspirations

  1. Fetch licenses!
  2. Fast!
  3. Do it in the build step!

Workings

Crates that are compiled with your program are fetched via cargo metadata. License texts are read from the .cargo/registry/src folder. The data is then serialized and compressed.

Usage

Include Dependency

[!WARNING] Include this library as build dependency and as normal dependeny!

cargo add --build --features build license-fetcher
cargo add license-fetcher

Build Script

This library requires you to execute it for fetching licenses in a build script. Creat a file called build.rs in the root of your project and add following contents:

use license_fetcher::build_script::generate_package_list_with_licenses;

fn main() {
    generate_package_list_with_licenses().write();
    println!("cargo::rerun-if-changed=build.rs");
    println!("cargo::rerun-if-changed=Cargo.lock");
    println!("cargo::rerun-if-changed=Cargo.toml");
}

Main

Add following content to your main.rs:

use license_fetcher::get_package_list_macro;

fn main() {
    let packages = get_package_list_macro!().unwrap();
    println!("{}", packages);
}

Alternatives

license-retriever

Pros

  • Also retrieves licenses in the build step and loads them into the program.

Cons

  • Does not fetch licenses from local source files.
  • Very slow.
  • Does not compress licenses.

cargo-about

Pros

  • Generates very nice html.

Cons

  • Is not a library to access said data but rather a command line tool.
  • Does not fetch licenses from local source files.

Screenshots

Display trait included 😉

Screenshot

Dependencies

~0.3–12MB
~68K SLoC