diff options
| author | Odd Stranne <odd@mullvad.net> | 2019-06-18 11:50:11 +0200 |
|---|---|---|
| committer | Odd Stranne <odd@mullvad.net> | 2019-06-26 11:57:33 +0200 |
| commit | 44c7a551d34aaa43bcc1db56b931eecc6ca2089a (patch) | |
| tree | cd75b53ae94ff73a66b7cb9a30c6be0a458f237d | |
| parent | eb2a4702980c8d0ed7190d26cfcf7cfaac3674b9 (diff) | |
| download | mullvadvpn-44c7a551d34aaa43bcc1db56b931eecc6ca2089a.tar.xz mullvadvpn-44c7a551d34aaa43bcc1db56b931eecc6ca2089a.zip | |
Update build scripts
| -rwxr-xr-x | build_windows_modules.sh | 5 | ||||
| -rw-r--r-- | mullvad-daemon/build.rs | 54 |
2 files changed, 58 insertions, 1 deletions
diff --git a/build_windows_modules.sh b/build_windows_modules.sh index d533973f6c..d7b5c8fc1d 100755 --- a/build_windows_modules.sh +++ b/build_windows_modules.sh @@ -164,14 +164,17 @@ function main local winfw_root_path=${CPP_ROOT_PATH:-"./windows/winfw"} local windns_root_path=${CPP_ROOT_PATH:-"./windows/windns"} local winnet_root_path=${CPP_ROOT_PATH:-"./windows/winnet"} - + local winutil_root_path=${CPP_ROOT_PATH:-"./windows/winutil"} + build_solution "$winfw_root_path" "winfw.sln" build_solution "$windns_root_path" "windns.sln" build_solution "$winnet_root_path" "winnet.sln" + build_solution "$winutil_root_path" "winutil.sln" copy_outputs $winfw_root_path "winfw.dll" copy_outputs $windns_root_path "windns.dll" copy_outputs $winnet_root_path "winnet.dll" + copy_outputs $winutil_root_path "winutil.dll" build_nsis_plugins } diff --git a/mullvad-daemon/build.rs b/mullvad-daemon/build.rs index 09181c1013..4d01169d14 100644 --- a/mullvad-daemon/build.rs +++ b/mullvad-daemon/build.rs @@ -1,5 +1,51 @@ use std::{env, fs, path::PathBuf, process::Command}; +#[cfg(windows)] +mod win { + use std::{env, path::PathBuf}; + + pub static WINUTIL_BUILD_DIR: &'static str = "..\\windows\\winutil\\bin"; + + pub fn default_windows_build_artifact_dir(build_dir: &str) -> PathBuf { + manifest_dir().join(build_dir).join(&target_platform_dir()) + } + + fn target_platform_dir() -> PathBuf { + let target = env::var("TARGET").expect("TARGET env var not set"); + + let target_dir = match target.as_str() { + "i686-pc-windows-msvc" => format!("Win32-{}", get_build_mode()), + "x86_64-pc-windows-msvc" => format!("x64-{}", get_build_mode()), + _ => panic!("uncrecognized target: {}", target), + }; + target_dir.into() + } + + fn get_build_mode() -> &'static str { + let profile = env::var("PROFILE").expect("PROFILE env var not set"); + if profile == "release" { + "Release" + } else { + "Debug" + } + } + + pub fn declare_library(env_var: &str, default_dir: &str, lib_name: &str) { + println!("cargo:rerun-if-env-changed={}", env_var); + let lib_dir = env::var_os(env_var) + .map(PathBuf::from) + .unwrap_or_else(|| default_windows_build_artifact_dir(default_dir)); + println!("cargo:rustc-link-search={}", lib_dir.display()); + println!("cargo:rustc-link-lib=dylib={}", lib_name); + } + + fn manifest_dir() -> PathBuf { + env::var("CARGO_MANIFEST_DIR") + .map(PathBuf::from) + .expect("CARGO_MANIFEST_DIR env var not set") + } +} + fn main() { let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); @@ -27,6 +73,14 @@ fn main() { } res.compile().expect("Unable to generate windows resources"); } + + #[cfg(windows)] + { + use crate::win::*; + + const WINUTIL_DIR_VAR: &str = "WINUTIL_LIB_DIR"; + declare_library(WINUTIL_DIR_VAR, WINUTIL_BUILD_DIR, "winutil"); + } } fn commit_date() -> String { |
