Skip to content

Commit 4cf5de7

Browse files
committed
Correct document generation of docs.rs
1 parent db46b9b commit 4cf5de7

File tree

4 files changed

+36813
-4
lines changed

4 files changed

+36813
-4
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,21 @@ jobs:
213213
cd ..
214214
- name: BindingBuild
215215
run: PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" cargo build --verbose
216+
217+
# Check if correct documentation can be generated by docs.rs
218+
docs_rs_check:
219+
runs-on: ubuntu-latest
220+
steps:
221+
- uses: actions/checkout@v2
222+
223+
- name: Install latest nightly
224+
uses: actions-rs/toolchain@v1
225+
with:
226+
profile: minimal
227+
toolchain: nightly
228+
override: true
229+
230+
- name: BindingBuild
231+
run: DOCS_RS=1 cargo build --verbose
232+
- name: DocumentGeneration
233+
run: cargo doc --verbose

build.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ static HEADERS: Lazy<[&str; 64]> = Lazy::new(|| {
9393
static PATH: Lazy<String> = Lazy::new(|| env::var("PATH").unwrap());
9494
static OUT_DIR: Lazy<String> = Lazy::new(|| env::var("OUT_DIR").unwrap());
9595
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()));
9698
static NUM_CPUS: Lazy<usize> = Lazy::new(ncpus::get);
9799

98100
/// Filter out all symbols in the HashSet, and for others things it will act
@@ -114,6 +116,19 @@ impl callbacks::ParseCallbacks for FilterCargoCallbacks {
114116
}
115117

116118
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+
117132
if env::var("PKG_CONFIG_PATH").is_err() {
118133
// All outputs are stored in ./ffmpeg/build/{bin, lib, share, include}
119134
// If no prebuilt FFmpeg libraries provided, we custom build a FFmpeg.
@@ -336,12 +351,10 @@ fn main() {
336351
);
337352
*/
338353

339-
// Is it correct to generate binding to one file? :-/
340-
let output_path: path::PathBuf = [&*OUT_DIR, "binding.rs"].iter().collect();
341-
342354
builder
343355
.generate()
344356
.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)
346359
.expect("Cannot write binding to file!")
347360
}

src/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The `binding.rs` is only used for document generation from docs.rs, which should be updated on crate's version changing.

0 commit comments

Comments
 (0)