1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
#[cfg(windows)]
if try_registry() {
return Ok(());
}
system_deps::Config::new().probe()?;
Ok(())
}
#[cfg(windows)]
fn try_registry() -> bool {
use std::{ffi::OsString, fs, path::PathBuf};
use winreg::{enums::*, RegKey};
if !build::cargo_cfg_windows() {
eprintln!("cross compiling. disabling registry detection.");
return false;
}
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let key = match hklm.open_subkey_with_flags(r"SOFTWARE\GnuPG", KEY_WOW64_32KEY | KEY_READ) {
Ok(x) => x,
Err(e) => {
eprintln!("Unable to retrieve install location: {e}");
return false;
}
};
let root = match key
.get_value::<OsString, _>("Install Directory")
.map(PathBuf::from)
{
Ok(x) => x,
Err(e) => {
eprintln!("Unable to retrieve install location: {e}");
return false;
}
};
println!("detected install via registry: {}", root.display());
if root.join("lib/libgpg-error.imp").exists() {
if let Err(e) = fs::copy(
root.join("lib/libgpg-error.imp"),
build::out_dir().join("libgpg-error.a"),
) {
eprintln!("unable to rename library: {e}");
return false;
}
}
build::rustc_link_search(build::out_dir());
build::rustc_link_lib("gpg-error");
true
}
|