forked from OSSystems/compress-tools-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
binding_script.rs
74 lines (64 loc) · 2.99 KB
/
binding_script.rs
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// cargo-deps: bindgen = "0.51.1", pkg-config = "0.3.17"
use std::path::PathBuf;
fn main() {
let mut lib = pkg_config::Config::new()
.atleast_version("3.2.2")
.probe("libarchive")
.expect("Fail to detect the libarchive library");
let include_path = lib
.include_paths
.pop()
.unwrap_or(PathBuf::from("usr/include"));
let bindings = bindgen::Builder::default()
// Set rustfmt setting
.rustfmt_configuration_file(Some(".rustfmt.toml".into()))
// Set include path
.header(format!("{}/archive.h", include_path.display()))
.header(format!("{}/archive_entry.h", include_path.display()))
// We need to add this as raw_line to pass cargo clippy warning about
// convert to upper camel case
.raw_line("#![allow(non_camel_case_types)]\n")
// We need to add this as raw_line otherwise bindgen generates this as
// u32, causing type mismatch
.raw_line("pub const ARCHIVE_EOF: i32 = 1;")
.raw_line("pub const ARCHIVE_OK: i32 = 0;")
// Binding whitelist
.whitelist_var("ARCHIVE_EXTRACT_TIME")
.whitelist_var("ARCHIVE_EXTRACT_PERM")
.whitelist_var("ARCHIVE_EXTRACT_ACL")
.whitelist_var("ARCHIVE_EXTRACT_FFLAGS")
.whitelist_var("ARCHIVE_EXTRACT_OWNER")
.whitelist_var("ARCHIVE_EXTRACT_FFLAGS")
.whitelist_var("ARCHIVE_EXTRACT_XATTR")
.whitelist_function("archive_read_new")
.whitelist_function("archive_read_support_filter_all")
.whitelist_function("archive_read_support_format_all")
.whitelist_function("archive_read_support_format_raw")
.whitelist_function("archive_read_close")
.whitelist_function("archive_read_free")
.whitelist_function("archive_read_data_block")
.whitelist_function("archive_read_next_header")
.whitelist_function("archive_read_open")
.whitelist_function("archive_write_disk_new")
.whitelist_function("archive_write_disk_set_options")
.whitelist_function("archive_write_disk_set_standard_lookup")
.whitelist_function("archive_write_header")
.whitelist_function("archive_write_finish_entry")
.whitelist_function("archive_write_data_block")
.whitelist_function("archive_write_close")
.whitelist_function("archive_write_free")
.whitelist_function("archive_entry_pathname")
.whitelist_function("archive_entry_free")
.whitelist_function("archive_entry_set_pathname")
.whitelist_function("archive_entry_set_hardlink")
.whitelist_function("archive_entry_hardlink")
.whitelist_function("archive_set_error")
.whitelist_function("archive_error_string")
.whitelist_function("archive_errno")
.generate()
.expect("Unable to generate bindings");
bindings
.write_to_file(PathBuf::from("src/ffi.rs"))
.expect("Couldn't write bindings!");
println!("Sucessfully generated bindings for libarchive.");
}