-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
35 lines (32 loc) · 1.47 KB
/
build.rs
File metadata and controls
35 lines (32 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use std::env;
use std::path::PathBuf;
fn main() {
// Build libversion static library using cc.
// The cmake-generated headers (config.h, export.h) are pre-committed under
// generated/ — run `bash scripts/generate-headers.sh` to regenerate them
// whenever the libversion submodule is updated.
cc::Build::new()
.file("libversion/libversion/compare.c")
.file("libversion/libversion/private/compare.c")
.file("libversion/libversion/private/parse.c")
.include("libversion") // source headers (libversion/version.h, etc.)
.include("generated") // pre-generated headers (libversion/config.h, libversion/export.h)
.define("LIBVERSION_STATIC_DEFINE", None)
.compile("version");
// Generate FFI bindings via bindgen
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.clang_arg("-Igenerated") // pre-generated config.h, export.h
.clang_arg("-Ilibversion") // source headers
.clang_arg("-DLIBVERSION_STATIC_DEFINE")
.default_enum_style(bindgen::EnumVariation::Consts)
.allowlist_function("version_compare.*")
.allowlist_var("VERSIONFLAG_.*")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}