@@ -93,6 +93,8 @@ static HEADERS: Lazy<[&str; 64]> = Lazy::new(|| {
93
93
static PATH : Lazy < String > = Lazy :: new ( || env:: var ( "PATH" ) . unwrap ( ) ) ;
94
94
static OUT_DIR : Lazy < String > = Lazy :: new ( || env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
95
95
static FFMPEG_DIR : Lazy < String > = Lazy :: new ( || format ! ( "{}/ffmpeg" , env:: var( "OUT_DIR" ) . unwrap( ) ) ) ;
96
+ static BINDING_FILE_PATH : Lazy < String > =
97
+ Lazy :: new ( || format ! ( "{}/binding.rs" , env:: var( "OUT_DIR" ) . unwrap( ) ) ) ;
96
98
static NUM_CPUS : Lazy < usize > = Lazy :: new ( ncpus:: get) ;
97
99
98
100
/// Filter out all symbols in the HashSet, and for others things it will act
@@ -114,6 +116,19 @@ impl callbacks::ParseCallbacks for FilterCargoCallbacks {
114
116
}
115
117
116
118
fn main ( ) {
119
+ // If it's a documentation generation from docs.rs, just copy the bindings
120
+ // generated locally to `OUT_DIR`. We do this because the building
121
+ // environment of docs.rs doesn't have an network connection, so we cannot
122
+ // git clone the FFmpeg. And they also have a limitation on crate's size:
123
+ // 10MB, which is not enough to fit in full FFmpeg source files. So the only
124
+ // thing we can do is copy the locally generated binding files to the
125
+ // `OUT_DIR`.
126
+ if env:: var ( "DOCS_RS" ) . is_ok ( ) {
127
+ fs:: copy ( "src/binding.rs" , & * BINDING_FILE_PATH )
128
+ . expect ( "Prebuilt binding file failed to be copied." ) ;
129
+ return ;
130
+ }
131
+
117
132
if env:: var ( "PKG_CONFIG_PATH" ) . is_err ( ) {
118
133
// All outputs are stored in ./ffmpeg/build/{bin, lib, share, include}
119
134
// If no prebuilt FFmpeg libraries provided, we custom build a FFmpeg.
@@ -336,12 +351,10 @@ fn main() {
336
351
);
337
352
*/
338
353
339
- // Is it correct to generate binding to one file? :-/
340
- let output_path: path:: PathBuf = [ & * OUT_DIR , "binding.rs" ] . iter ( ) . collect ( ) ;
341
-
342
354
builder
343
355
. generate ( )
344
356
. expect ( "Binding generation failed." )
345
- . write_to_file ( output_path)
357
+ // Is it correct to generate binding to one file? :-/
358
+ . write_to_file ( & * BINDING_FILE_PATH )
346
359
. expect ( "Cannot write binding to file!" )
347
360
}
0 commit comments