@@ -11,8 +11,10 @@ use std::path::PathBuf;
11
11
use std:: process:: Command ;
12
12
use std:: str;
13
13
14
+ use bindgen:: callbacks:: {
15
+ EnumVariantCustomBehavior , EnumVariantValue , IntKind , MacroParsingBehavior , ParseCallbacks ,
16
+ } ;
14
17
use regex:: Regex ;
15
- use bindgen:: callbacks:: { EnumVariantCustomBehavior , EnumVariantValue , IntKind , ParseCallbacks , MacroParsingBehavior } ;
16
18
17
19
#[ derive( Debug ) ]
18
20
struct Library {
@@ -31,15 +33,42 @@ impl Library {
31
33
}
32
34
33
35
static LIBRARIES : & [ Library ] = & [
34
- Library { name : "avcodec" , is_feature : true } ,
35
- Library { name : "avdevice" , is_feature : true } ,
36
- Library { name : "avfilter" , is_feature : true } ,
37
- Library { name : "avformat" , is_feature : true } ,
38
- Library { name : "avresample" , is_feature : true } ,
39
- Library { name : "avutil" , is_feature : false } ,
40
- Library { name : "postproc" , is_feature : true } ,
41
- Library { name : "swresample" , is_feature : true } ,
42
- Library { name : "swscale" , is_feature : true } ,
36
+ Library {
37
+ name : "avcodec" ,
38
+ is_feature : true ,
39
+ } ,
40
+ Library {
41
+ name : "avdevice" ,
42
+ is_feature : true ,
43
+ } ,
44
+ Library {
45
+ name : "avfilter" ,
46
+ is_feature : true ,
47
+ } ,
48
+ Library {
49
+ name : "avformat" ,
50
+ is_feature : true ,
51
+ } ,
52
+ Library {
53
+ name : "avresample" ,
54
+ is_feature : true ,
55
+ } ,
56
+ Library {
57
+ name : "avutil" ,
58
+ is_feature : false ,
59
+ } ,
60
+ Library {
61
+ name : "postproc" ,
62
+ is_feature : true ,
63
+ } ,
64
+ Library {
65
+ name : "swresample" ,
66
+ is_feature : true ,
67
+ } ,
68
+ Library {
69
+ name : "swscale" ,
70
+ is_feature : true ,
71
+ } ,
43
72
] ;
44
73
45
74
#[ derive( Debug ) ]
@@ -52,11 +81,13 @@ impl ParseCallbacks for Callbacks {
52
81
let codec_flag = Regex :: new ( r"^AV_CODEC_FLAG" ) . unwrap ( ) ;
53
82
let error_max_size = Regex :: new ( r"^AV_ERROR_MAX_STRING_SIZE" ) . unwrap ( ) ;
54
83
55
- if value >= i64:: min_value ( ) as i64 && value <= i64:: max_value ( ) as i64
84
+ if value >= i64:: min_value ( ) as i64
85
+ && value <= i64:: max_value ( ) as i64
56
86
&& ch_layout. is_match ( _name)
57
87
{
58
88
Some ( IntKind :: ULongLong )
59
- } else if value >= i32:: min_value ( ) as i64 && value <= i32:: max_value ( ) as i64
89
+ } else if value >= i32:: min_value ( ) as i64
90
+ && value <= i32:: max_value ( ) as i64
60
91
&& ( codec_cap. is_match ( _name) || codec_flag. is_match ( _name) )
61
92
{
62
93
Some ( IntKind :: UInt )
@@ -132,13 +163,13 @@ fn search() -> PathBuf {
132
163
133
164
fn fetch ( ) -> io:: Result < ( ) > {
134
165
let status = Command :: new ( "git" )
135
- . current_dir ( & output ( ) )
136
- . arg ( "clone" )
137
- . arg ( "-b" )
138
- . arg ( format ! ( "release/{}" , version( ) ) )
139
- . arg ( "https://github.com/FFmpeg/FFmpeg" )
140
- . arg ( format ! ( "ffmpeg-{}" , version( ) ) )
141
- . status ( ) ?;
166
+ . current_dir ( & output ( ) )
167
+ . arg ( "clone" )
168
+ . arg ( "-b" )
169
+ . arg ( format ! ( "release/{}" , version( ) ) )
170
+ . arg ( "https://github.com/FFmpeg/FFmpeg" )
171
+ . arg ( format ! ( "ffmpeg-{}" , version( ) ) )
172
+ . status ( ) ?;
142
173
143
174
if status. success ( ) {
144
175
Ok ( ( ) )
@@ -150,8 +181,7 @@ fn fetch() -> io::Result<()> {
150
181
fn switch ( configure : & mut Command , feature : & str , name : & str ) {
151
182
let arg = if env:: var ( "CARGO_FEATURE_" . to_string ( ) + feature) . is_ok ( ) {
152
183
"--enable-"
153
- }
154
- else {
184
+ } else {
155
185
"--disable-"
156
186
} ;
157
187
configure. arg ( arg. to_string ( ) + name) ;
@@ -185,11 +215,11 @@ fn build() -> io::Result<()> {
185
215
configure. arg ( "--disable-programs" ) ;
186
216
187
217
macro_rules! enable {
188
- ( $conf: expr, $feat: expr, $name: expr) => (
218
+ ( $conf: expr, $feat: expr, $name: expr) => {
189
219
if env:: var( concat!( "CARGO_FEATURE_" , $feat) ) . is_ok( ) {
190
220
$conf. arg( concat!( "--enable-" , $name) ) ;
191
221
}
192
- )
222
+ } ;
193
223
}
194
224
195
225
// macro_rules! disable {
@@ -294,21 +324,21 @@ fn build() -> io::Result<()> {
294
324
295
325
// run make
296
326
if !Command :: new ( "make" )
297
- . arg ( "-j" )
298
- . arg ( num_cpus:: get ( ) . to_string ( ) )
299
- . current_dir ( & source ( ) )
300
- . status ( ) ?
301
- . success ( )
327
+ . arg ( "-j" )
328
+ . arg ( num_cpus:: get ( ) . to_string ( ) )
329
+ . current_dir ( & source ( ) )
330
+ . status ( ) ?
331
+ . success ( )
302
332
{
303
333
return Err ( io:: Error :: new ( io:: ErrorKind :: Other , "make failed" ) ) ;
304
334
}
305
335
306
336
// run make install
307
337
if !Command :: new ( "make" )
308
- . current_dir ( & source ( ) )
309
- . arg ( "install" )
310
- . status ( ) ?
311
- . success ( )
338
+ . current_dir ( & source ( ) )
339
+ . arg ( "install" )
340
+ . status ( ) ?
341
+ . success ( )
312
342
{
313
343
return Err ( io:: Error :: new ( io:: ErrorKind :: Other , "make install failed" ) ) ;
314
344
}
@@ -386,7 +416,8 @@ fn check_features(
386
416
"# ,
387
417
includes_code = includes_code,
388
418
main_code = main_code
389
- ) . expect ( "Write failed" ) ;
419
+ )
420
+ . expect ( "Write failed" ) ;
390
421
391
422
let executable = out_dir. join ( if cfg ! ( windows) { "check.exe" } else { "check" } ) ;
392
423
let mut compiler = cc:: Build :: new ( ) . get_compiler ( ) . to_command ( ) ;
@@ -481,8 +512,7 @@ fn search_include(include_paths: &Vec<PathBuf>, header: &str) -> String {
481
512
fn link_to_libraries ( statik : bool ) {
482
513
let ffmpeg_ty = if statik { "static" } else { "dylib" } ;
483
514
for lib in LIBRARIES {
484
- let feat_is_enabled =
485
- lib. feature_name ( ) . and_then ( |f| env:: var ( & f) . ok ( ) ) . is_some ( ) ;
515
+ let feat_is_enabled = lib. feature_name ( ) . and_then ( |f| env:: var ( & f) . ok ( ) ) . is_some ( ) ;
486
516
if !lib. is_feature || feat_is_enabled {
487
517
println ! ( "cargo:rustc-link-lib={}={}" , ffmpeg_ty, lib. name) ;
488
518
}
@@ -567,7 +597,7 @@ fn main() {
567
597
. unwrap ( )
568
598
. include_paths ;
569
599
}
570
- } ;
600
+ }
571
601
572
602
pkg_config:: Config :: new ( )
573
603
. statik ( statik)
@@ -1018,9 +1048,10 @@ fn main() {
1018
1048
}
1019
1049
1020
1050
// Finish the builder and generate the bindings.
1021
- let bindings = builder. generate ( )
1022
- // Unwrap the Result and panic on failure.
1023
- . expect ( "Unable to generate bindings" ) ;
1051
+ let bindings = builder
1052
+ . generate ( )
1053
+ // Unwrap the Result and panic on failure.
1054
+ . expect ( "Unable to generate bindings" ) ;
1024
1055
1025
1056
// Write the bindings to the $OUT_DIR/bindings.rs file.
1026
1057
bindings
0 commit comments