nftnl-sys 0.6.3

Low level FFI bindings to libnftnl. Provides low-level userspace access to the in-kernel nf_tables subsystem
Documentation
extern crate pkg_config;

use std::{env, path::PathBuf};

cfg_if::cfg_if! {
    if #[cfg(feature = "nftnl-1-1-2")] {
        const MIN_VERSION: &str = "1.1.2";
    } else if #[cfg(feature = "nftnl-1-1-1")] {
        const MIN_VERSION: &str = "1.1.1";
    } else if #[cfg(feature = "nftnl-1-1-0")] {
        const MIN_VERSION: &str = "1.1.0";
    } else if #[cfg(feature = "nftnl-1-0-9")] {
        const MIN_VERSION: &str = "1.0.9";
    } else if #[cfg(feature = "nftnl-1-0-8")] {
        const MIN_VERSION: &str = "1.0.8";
    } else if #[cfg(feature = "nftnl-1-0-7")] {
        const MIN_VERSION: &str = "1.0.7";
    } else {
        const MIN_VERSION: &str = "1.0.6";
    }
}

fn get_env(var: &'static str) -> Option<PathBuf> {
    println!("cargo:rerun-if-env-changed={}", var);
    env::var_os(var).map(PathBuf::from)
}

fn main() {
    // Do NOT link when building documentation on docs.rs. The native libraries are not
    // present on their build machines and just makes the compilation fail. Documentation
    // generation will work without linking.
    if std::env::var("DOCS_RS").is_ok() {
        return;
    }

    if let Some(lib_dir) = get_env("LIBNFTNL_LIB_DIR") {
        if !lib_dir.is_dir() {
            panic!(
                "libnftnl library directory does not exist: {}",
                lib_dir.display()
            );
        }
        println!("cargo:rustc-link-search=native={}", lib_dir.display());
        println!("cargo:rustc-link-lib=nftnl");
    } else {
        // Trying with pkg-config instead
        println!("Minimum libnftnl version: {}", MIN_VERSION);
        pkg_config::Config::new()
            .atleast_version(MIN_VERSION)
            .probe("libnftnl")
            .unwrap();
    }
}