Skip to content

Commit

Permalink
allow vcpkg on all targets
Browse files Browse the repository at this point in the history
  • Loading branch information
ns-mkusper committed Jul 22, 2024
1 parent 19557c8 commit e7e8618
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ libc = "0.2"
bindgen = "0.69"
camino = "1.0.9"
once_cell = "1.12"
vcpkg = { version = "0.2", optional = true }

[target.'cfg(not(windows))'.build-dependencies]
pkg-config = "0.3"
Expand All @@ -38,6 +39,8 @@ vcpkg = "0.2"
[features]
# linking system ffmpeg as fallback.
link_system_ffmpeg = []
# link against vcpkg ffmpeg
link_vcpkg_ffmpeg = ["vcpkg"]
# FFmpeg 5.* support
ffmpeg5 = []
# FFmpeg 6.* support
Expand Down
35 changes: 22 additions & 13 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,14 @@ mod non_windows {
}
}

#[cfg(target_os = "windows")]
mod windows {
#[cfg(all(feature = "link_vcpkg_ffmpeg", feature = "link_system_ffmpeg"))]
compile_error!("Features link_vcpkg_ffmpeg and link_system_ffmpeg features are mutually exclusive and cannot be enabled together.");

#[cfg(any(feature = "link_vcpkg_ffmpeg", target_os = "windows"))]
mod vcpkg_linking {
use super::*;
pub fn static_linking_vcpkg(_env_vars: &EnvVars, _library_names: &[&str]) -> Vec<PathBuf> {

fn static_linking_vcpkg(_env_vars: &EnvVars, _library_names: &[&str]) -> Vec<PathBuf> {
vcpkg::Config::new()
.find_package("ffmpeg")
.unwrap()
Expand All @@ -326,6 +330,17 @@ mod windows {
.map(|x| PathBuf::from_path_buf(x).unwrap())
.collect()
}

pub fn generate_vcpkg_bindings(env_vars: &EnvVars, output_binding_path: &Path) {
let include_paths = static_linking_vcpkg(env_vars, &*LIBS);
if let Some(ffmpeg_binding_path) = env_vars.ffmpeg_binding_path.as_ref() {
use_prebuilt_binding(ffmpeg_binding_path, output_binding_path);
} else {
generate_bindings(&include_paths[0], &HEADERS)
.write_to_file(output_binding_path)
.expect("Cannot write binding to file.");
}
}
}

fn dynamic_linking(env_vars: &EnvVars) {
Expand Down Expand Up @@ -411,13 +426,14 @@ fn static_linking(env_vars: &EnvVars) {
} else {
#[cfg(feature = "link_system_ffmpeg")]
link_and_bindgen(env_vars, output_binding_path);
#[cfg(not(feature = "link_system_ffmpeg"))]
#[cfg(feature = "link_vcpkg_ffmpeg")]
vcpkg_linking::generate_vcpkg_bindings(env_vars, output_binding_path);
#[cfg(not(any(feature = "link_system_ffmpeg", feature = "link_vcpkg_ffmpeg")))]
panic!("No linking method set!");
};
}
#[cfg(target_os = "windows")]
{
use windows::*;
if let Some(ffmpeg_libs_dir) = env_vars.ffmpeg_libs_dir.as_ref() {
static_linking_with_libs_dir(&*LIBS, ffmpeg_libs_dir);
if let Some(ffmpeg_binding_path) = env_vars.ffmpeg_binding_path.as_ref() {
Expand All @@ -430,14 +446,7 @@ fn static_linking(env_vars: &EnvVars) {
panic!("No binding generation method is set!");
}
} else {
let include_paths = static_linking_vcpkg(env_vars, &*LIBS);
if let Some(ffmpeg_binding_path) = env_vars.ffmpeg_binding_path.as_ref() {
use_prebuilt_binding(ffmpeg_binding_path, output_binding_path);
} else {
generate_bindings(&include_paths[0], &HEADERS)
.write_to_file(output_binding_path)
.expect("Cannot write binding to file.");
}
vcpkg_linking::generate_vcpkg_bindings(env_vars, output_binding_path);
}
}
}
Expand Down

0 comments on commit e7e8618

Please sign in to comment.