Add build script for man generation

This commit is contained in:
Andrew 2024-03-05 20:20:45 +13:00 committed by Alejandro González
parent fab3a437e8
commit 58b37840ff
No known key found for this signature in database
3 changed files with 54 additions and 0 deletions

17
Cargo.lock generated
View file

@ -134,6 +134,16 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
[[package]]
name = "clap_mangen"
version = "0.2.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1dd95b5ebb5c1c54581dd6346f3ed6a79a3eef95dd372fc2ac13d535535300e"
dependencies = [
"clap",
"roff",
]
[[package]]
name = "color_quant"
version = "1.1.0"
@ -455,6 +465,7 @@ version = "9.0.0"
dependencies = [
"bitvec",
"clap",
"clap_mangen",
"crossbeam-channel",
"env_logger",
"filetime",
@ -529,6 +540,12 @@ dependencies = [
"bytemuck",
]
[[package]]
name = "roff"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316"
[[package]]
name = "rustc-hash"
version = "1.1.0"

View file

@ -78,6 +78,8 @@ features = ["png"]
version = "0.24.6"
[build-dependencies]
clap = "4.3.8"
clap_mangen = "0.2.20"
rustc_version = "0.4.0"
[features]

35
build.rs Normal file
View file

@ -0,0 +1,35 @@
use clap_mangen::Man;
use std::{env, fs::File, io::Error, path::Path};
include!("src/cli.rs");
fn build_manpages(outdir: &Path) -> Result<(), Error> {
let app = build_command();
let file = Path::new(&outdir).join("oxipng.1");
let mut file = File::create(file)?;
Man::new(app).render(&mut file)?;
Ok(())
}
fn main() -> Result<(), Error> {
println!("cargo:rerun-if-changed=src/cli.rs");
println!("cargo:rerun-if-changed=man");
let outdir = match env::var_os("OUT_DIR") {
None => return Ok(()),
Some(outdir) => outdir,
};
// Create `target/assets/` folder.
let out_path = PathBuf::from(outdir);
let mut path = out_path.ancestors().nth(4).unwrap().to_owned();
path.push("assets");
std::fs::create_dir_all(&path).unwrap();
build_manpages(&path)?;
Ok(())
}