@@ -18,6 +18,38 @@ static LIBS: Lazy<[&str; 7]> = Lazy::new(|| {
18
18
]
19
19
} ) ;
20
20
21
+ static SYS_STATIC_LIBS : Lazy < HashMap < & str , Vec < & str > > > = Lazy :: new ( || {
22
+ if cfg ! ( target_os = "windows" ) {
23
+ // Statically linking FFmpeg on Windows requires additional dependencies. This is a map
24
+ // of FFmpeg library name to system libraries. In the future, if
25
+ // https://github.com/CCExtractor/rusty_ffmpeg/issues/128 is addressed, we will want to
26
+ // selectively choose which system libraries to link based on chosen FFmpeg features.
27
+ //
28
+ // Note that the values were obtained by building FFmpeg using vcpkg with the
29
+ // x64-windows-static triplet, and then examining the generated .pc files in the pkgconfig
30
+ // directory.
31
+ HashMap :: from ( [
32
+ (
33
+ "avcodec" ,
34
+ vec ! [ "mfuuid" , "ole32" , "strmiids" , "ole32" , "user32" ] ,
35
+ ) ,
36
+ (
37
+ "avdevice" ,
38
+ vec ! [
39
+ "psapi" , "ole32" , "strmiids" , "uuid" , "oleaut32" , "shlwapi" , "gdi32" , "vfw32" ,
40
+ ] ,
41
+ ) ,
42
+ ( "avfilter" , vec ! [ ] ) ,
43
+ ( "avformat" , vec ! [ "secur32" , "ws2_32" ] ) ,
44
+ ( "avutil" , vec ! [ "user32" , "bcrypt" ] ) ,
45
+ ( "swresample" , vec ! [ ] ) ,
46
+ ( "swscale" , vec ! [ ] ) ,
47
+ ] )
48
+ } else {
49
+ HashMap :: new ( )
50
+ }
51
+ } ) ;
52
+
21
53
/// Whitelist of the headers we want to generate bindings
22
54
static HEADERS : Lazy < Vec < PathBuf > > = Lazy :: new ( || {
23
55
[
@@ -399,6 +431,16 @@ fn dynamic_linking(env_vars: &EnvVars) {
399
431
fn static_linking ( env_vars : & EnvVars ) {
400
432
let output_binding_path = & env_vars. out_dir . as_ref ( ) . unwrap ( ) . join ( "binding.rs" ) ;
401
433
434
+ fn static_link_sys_libs ( ) {
435
+ // Statically linking to FFmpeg may also require us to link to some system libraries.
436
+ let mut sys_libs: Vec < _ > = SYS_STATIC_LIBS . values ( ) . flatten ( ) . collect ( ) ;
437
+ sys_libs. sort ( ) ;
438
+ sys_libs. dedup ( ) ;
439
+ for sys_lib in sys_libs {
440
+ println ! ( "cargo:rustc-link-lib={sys_lib}" ) ;
441
+ }
442
+ }
443
+
402
444
#[ cfg( not( target_os = "windows" ) ) ]
403
445
{
404
446
fn static_linking_with_pkg_config_and_bindgen (
@@ -419,6 +461,7 @@ fn static_linking(env_vars: &EnvVars) {
419
461
. write_to_file ( output_binding_path)
420
462
. expect ( "Cannot write binding to file." ) ;
421
463
}
464
+ static_link_sys_libs ( ) ;
422
465
Ok ( ( ) )
423
466
}
424
467
// Hint: set PKG_CONFIG_PATH to some placeholder value will let pkg_config probing system library.
@@ -491,6 +534,7 @@ Enable `link_vcpkg_ffmpeg` feature if you want to link ffmpeg libraries installe
491
534
{
492
535
if let Some ( ffmpeg_libs_dir) = env_vars. ffmpeg_libs_dir . as_ref ( ) {
493
536
static_linking_with_libs_dir ( & * LIBS , ffmpeg_libs_dir) ;
537
+ static_link_sys_libs ( ) ;
494
538
if let Some ( ffmpeg_binding_path) = env_vars. ffmpeg_binding_path . as_ref ( ) {
495
539
use_prebuilt_binding ( ffmpeg_binding_path, output_binding_path) ;
496
540
} else if let Some ( ffmpeg_include_dir) = env_vars. ffmpeg_include_dir . as_ref ( ) {
0 commit comments