Skip to content

Commit 62b1d4c

Browse files
committed
Update mp4parse_capi for standard mozilla vendoring
- Remove build.rs in favor of executing cbindgen externally - Remove cbindgen build dependency - Add cbindgen.toml for generated bindings preferences And corresponding changes to test_ffi: - Generate mp4parse_capi header in build.rs - Configure cbindgen via cbindgen.toml - Put generated code in out OUT_DIR - Include generated code indirectly, as mozilla tree does See https://bugzilla.mozilla.org/show_bug.cgi?id=1624056
1 parent 8c0db4a commit 62b1d4c

File tree

6 files changed

+48
-50
lines changed

6 files changed

+48
-50
lines changed

mp4parse_capi/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ num-traits = "0.2.0"
3434
[dev-dependencies]
3535
env_logger = "0.7.1"
3636

37-
[build-dependencies]
38-
cbindgen = "0.5.2"
39-
4037
[features]
4138
# Enable mp4parse_fallible to use fallible memory allocation rather than
4239
# panicking on OOM. Note that this is only safe within Gecko where the system

mp4parse_capi/build.rs

Lines changed: 0 additions & 46 deletions
This file was deleted.

mp4parse_capi/cbindgen.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
header = """/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */"""
4+
autogen_warning = """/* DO NOT MODIFY THIS MANUALLY! This file was generated using cbindgen. */
5+
#ifndef mp4parse_rust_mp4parse_h
6+
#error "Don't include this file directly, instead include mp4parse.h"
7+
#endif
8+
"""
9+
include_version = true
10+
braces = "SameLine"
11+
line_length = 100
12+
tab_width = 2
13+
language = "C"
14+
cpp_compat = true
15+
16+
[enum]
17+
rename_variants = "QualifiedScreamingSnakeCase"

test_ffi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ edition = "2018"
88
mp4parse_capi = { path = "../mp4parse_capi" }
99

1010
[build-dependencies]
11+
cbindgen = "0.14.2"
1112
mp4parse_capi = { path = "../mp4parse_capi" }
1213
cc = "1.0"

test_ffi/build.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1+
extern crate cbindgen;
12
extern crate cc;
23

4+
use cbindgen::{Config, RenameRule};
5+
use std::path::Path;
6+
7+
const CAPI_CRATE: &str = "../mp4parse_capi";
8+
39
fn main() {
10+
println!("cargo:rerun-if-changed={}/src/lib.rs", CAPI_CRATE);
11+
12+
let crate_dir = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).join(CAPI_CRATE);
13+
let generated_include_dir = Path::new(&std::env::var("OUT_DIR").unwrap()).join("include");
14+
let header_path = generated_include_dir.join("mp4parse_ffi_generated.h");
15+
16+
cbindgen::generate(&crate_dir)
17+
.expect("Could not generate header")
18+
.write_to_file(header_path);
19+
420
println!("cargo:rerun-if-changed=src/main.rs");
521
println!("cargo:rerun-if-changed=src/test.cc");
622

723
cc::Build::new()
824
.file("src/test.cc")
925
.cpp(true)
1026
.flag_if_supported("-std=c++11")
11-
.include("../mp4parse_capi/include")
27+
.include("include")
28+
.include(generated_include_dir)
1229
.compile("libtest.a");
1330

1431
#[cfg(unix)]

test_ffi/include/mp4parse.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
#ifndef mp4parse_rust_mp4parse_h
6+
#define mp4parse_rust_mp4parse_h
7+
8+
#include "mp4parse_ffi_generated.h"
9+
10+
// Add any non-generated support code here
11+
12+
#endif

0 commit comments

Comments
 (0)