File: build.rs

package info (click to toggle)
rust-gpgme-sys 0.11.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 172 kB
  • sloc: makefile: 4
file content (71 lines) | stat: -rw-r--r-- 2,013 bytes parent folder | download
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    if cfg!(windows) && try_registry() {
        return Ok(());
    }

    system_deps::Config::new().probe()?;
    Ok(())
}

#[cfg(not(windows))]
fn try_registry() -> bool {
    false
}

#[cfg(windows)]
fn try_registry() -> bool {
    use std::{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("SOFTWARE\\GnuPG") {
        Ok(k) => k,
        Err(_) => {
            // check if we are on 64bit windows but have 32bit GnuPG installed
            match hklm.open_subkey("SOFTWARE\\WOW6432Node\\GnuPG") {
                Ok(k) => {
                    // found 32bit library
                    if build::cargo_cfg_pointer_width() == 32 {
                        eprintln!("compile using i586/686 target.");
                        return false;
                    } else {
                        k
                    }
                }
                Err(_) => {
                    eprintln!("unable to retrieve install location");
                    return false;
                }
            }
        }
    };
    let root = match key.get_value::<String, _>("Install Directory") {
        Ok(v) => PathBuf::from(v),
        Err(_) => {
            eprintln!("unable to retrieve install location");
            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
}