use std::{env, fs, path::PathBuf};
fn main() {
let version = env::var("CARGO_PKG_VERSION").expect("Cargo supplies package version");
let source = PathBuf::from("docs/features/release-notes").join(format!("{version}.md"));
println!("cargo:rerun-if-changed=docs/features/release-notes");
let notes = match fs::read_to_string(&source) {
Ok(notes) => {
assert!(
notes.len() <= 16 * 1024,
"welcome release notes exceed 16 KiB"
);
assert!(
!notes.chars().any(|c| c.is_control() && c != '\n'),
"release notes contain control characters"
);
notes
}
Err(error) if error.kind() == std::io::ErrorKind::NotFound => String::new(),
Err(error) => panic!("cannot read {}: {error}", source.display()),
};
fs::write(
PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("welcome-release-notes.txt"),
notes,
)
.expect("write bundled release notes");
}