From c5e44b117bbbdb1af0385e73c310284067d20420 Mon Sep 17 00:00:00 2001 From: 0xd34d10cc <0xd34d10cc@gmail.com> Date: Sat, 20 Jun 2020 12:45:29 +0000 Subject: [PATCH] Add vcpkg support on windows Closes #2. Signed-off-by: Zhiming Wang --- sys/Cargo.toml | 3 +++ sys/build.rs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/sys/Cargo.toml b/sys/Cargo.toml index dc87807..681463b 100644 --- a/sys/Cargo.toml +++ b/sys/Cargo.toml @@ -25,6 +25,9 @@ pkg-config = "0.3" bindgen = "0.54" regex = "1.3" +[target.'cfg(target_env = "msvc")'.build-dependencies] +vcpkg = "0.2" + [features] default = ["avcodec", "avdevice", "avfilter", "avformat", "swresample", "swscale"] diff --git a/sys/build.rs b/sys/build.rs index db880e0..0215afa 100644 --- a/sys/build.rs +++ b/sys/build.rs @@ -341,6 +341,25 @@ fn build() -> io::Result<()> { Ok(()) } +#[cfg(not(target_env = "msvc"))] +fn try_vcpkg(_statik: bool) -> Option> { + None +} + +#[cfg(target_env = "msvc")] +fn try_vcpkg(statik: bool) -> Option> { + if !statik { + env::set_var("VCPKGRS_DYNAMIC", "1"); + } + + vcpkg::find_package("ffmpeg") + .map_err(|e| { + println!("Could not find ffmpeg with vcpkg: {}", e); + }) + .map(|library| library.include_paths) + .ok() +} + fn check_features( include_paths: Vec, infos: &Vec<(&'static str, Option<&'static str>, &'static str)>, @@ -574,6 +593,24 @@ fn main() { ); link_to_libraries(statik); vec![ffmpeg_dir.join("include")] + } else if let Some(paths) = try_vcpkg(statik) { + // vcpkg doesn't detect the "system" dependencies + if statik { + if cfg!(feature = "avcodec") || cfg!(feature = "avdevice") { + println!("cargo:rustc-link-lib=ole32"); + } + + if cfg!(feature = "avformat") { + println!("cargo:rustc-link-lib=secur32"); + println!("cargo:rustc-link-lib=ws2_32"); + } + + // avutil depdendencies + println!("cargo:rustc-link-lib=bcrypt"); + println!("cargo:rustc-link-lib=user32"); + } + + paths } // Fallback to pkg-config else {