summaryrefslogtreecommitdiffhomepage
path: root/talpid-wireguard/build.rs
blob: ab3500330c262e40cbcdc59113f2acaa57b095f9 (plain)
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
use std::{env, path::PathBuf};

fn main() {
    let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set");
    // Keep track if `binaries/wireguard-nt` changes
    if target_os == "windows" {
        declare_libs_dir("../dist-assets/binaries");
    }
    // Wireguard-Go can be used on all platforms except Windows
    println!("cargo::rustc-check-cfg=cfg(wireguard_go)");
    if matches!(target_os.as_str(), "linux" | "macos" | "android") {
        println!("cargo::rustc-cfg=wireguard_go");
    }
    // Enable DAITA by default on desktop and android
    println!("cargo::rustc-check-cfg=cfg(daita)");
    println!("cargo::rustc-cfg=daita");
}

fn declare_libs_dir(base: &str) {
    let target_triplet = env::var("TARGET").expect("TARGET is not set");
    let lib_dir = manifest_dir().join(base).join(target_triplet);
    println!("cargo::rerun-if-changed={}", lib_dir.display());
    println!("cargo::rustc-link-search={}", lib_dir.display());
}

fn manifest_dir() -> PathBuf {
    env::var("CARGO_MANIFEST_DIR")
        .map(PathBuf::from)
        .expect("CARGO_MANIFEST_DIR env var not set")
}