Skip to main content

nik_rev/
lib.rs

1use std::{env, fs};
2
3pub fn export_env_vars_for_docs() {
4    let repo_name = env::var("CARGO_PKG_REPOSITORY").unwrap();
5    let repo_name = repo_name.strip_prefix("https://github.com/").unwrap();
6    let pkg_name = env::var("CARGO_PKG_NAME").unwrap();
7    let msrv = env::var("CARGO_PKG_RUST_VERSION").unwrap();
8    let msrv = if msrv.is_empty() {
9        "nightly".into()
10    } else {
11        msrv
12    };
13
14    let badges = format!(
15            "[![crates.io](https://img.shields.io/crates/v/{pkg_name}?style=flat-square&logo=rust)](https://crates.io/crates/{pkg_name})
16[![docs.rs](https://img.shields.io/docsrs/{pkg_name}?style=flat-square&logo=docs.rs)](https://docs.rs/{pkg_name})
17![license](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue?style=flat-square)
18![msrv](https://img.shields.io/badge/msrv-{msrv}-blue?style=flat-square&logo=rust)
19[![github](https://img.shields.io/github/stars/{repo_name})](https://github.com/{repo_name})"
20        );
21
22    let pkg_name = env::var("CARGO_PKG_NAME").unwrap();
23    let major = env::var("CARGO_PKG_VERSION_MAJOR").unwrap();
24    let minor = env::var("CARGO_PKG_VERSION_MINOR").unwrap();
25
26    let add_dep = format!("```toml\n{pkg_name} = \"{major}.{minor}\"\n```\n");
27
28    let out_dir = env::var("OUT_DIR").unwrap();
29
30    fs::write(format!("{out_dir}/GENERATED_BADGES"), badges).unwrap();
31    fs::write(format!("{out_dir}/GENERATED_ADD_DEP"), add_dep).unwrap();
32}