detours 0.2.0

Detours is a software package for monitoring and instrumenting API calls on Windows.
use std::{env, path::PathBuf};

fn main() {
    cc::windows_registry::find(&env::var("TARGET").unwrap(), "nmake.exe")
        .expect("nmake not found")
        .current_dir("src")
        .status()
        .expect("failed to execute nmake");

    bindgen::builder()
        .header("windows.h")
        .header("include/detours.h")
        .clang_arg("-DWIN32_LEAN_AND_MEAN")
        .allowlist_file(r".*[\\/]detours\.h")
        .generate()
        .expect("failed to generate bindings")
        .write_to_file(PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs"))
        .expect("failed to write bindings");

    println!(
        "cargo:rustc-link-search={}/lib.{}",
        env::var("CARGO_MANIFEST_DIR").unwrap(),
        match env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() {
            "windows" => match env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() {
                "x86" => "X86",
                "x86_64" => "X64",
                value => unimplemented!("unsupported target architecture: {}", value),
            },
            value => unimplemented!("unsupported target operating system: {}", value),
        }
    );
    println!("cargo:rustc-link-lib=static=detours");
}