use std::env;
use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;
fn main() -> Result<(), std::io::Error> {
let src = env::current_dir()?;
let mut pc_in = PathBuf::from(&src);
pc_in.push("pep_engine_sequoia_backend.pc.in");
let mut build_dir = PathBuf::from(&src);
if let Some(target_dir) = env::var_os("CARGO_TARGET_DIR") {
build_dir.push(target_dir);
} else {
build_dir.push("target");
}
let profile = env::var_os("PROFILE")
.expect("PROFILE not set");
build_dir.push(&profile);
let mut pc = build_dir.clone();
pc.push("pep_engine_sequoia_backend.pc");
let mut pc_in = File::open(pc_in)?;
let mut content = Vec::new();
pc_in.read_to_end(&mut content)?;
let content = String::from_utf8(content).unwrap()
.replace("REQUIRES",
if cfg!(feature = "crypto-botan2") {
"botan-2"
} else if cfg!(feature = "crypto-botan3") {
"botan-3"
} else if cfg!(feature = "crypto-nettle") {
"nettle"
} else if cfg!(feature = "crypto-cng") {
""
} else {
panic!("Don't know dependencies to add to .pc file")
})
.replace("LIBDIR",
&build_dir
.to_str()
.expect("build directory is not UTF-8 encoded"))
.replace("VERSION",
&env::var_os("CARGO_PKG_VERSION")
.expect("CARGO_PKG_VERSION not set")
.into_string()
.expect("CARGO_PKG_VERSION is not UTF-8 encoded"));
let mut pc = File::create(&pc).expect(
&format!("Creating {:?} (CARGO_TARGET_DIR: {:?})",
pc, env::var_os("CARGO_TARGET_DIR")));
pc.write_all(content.as_bytes())?;
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=pep_engine_sequoia_backend.pc.in");
eprintln!("Generated {:?} with:\n{}\nEOF", pc, content);
Ok(())
}