-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
72 lines (64 loc) · 2.18 KB
/
build.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
use pkg_config::Config;
use std::env;
use std::path::PathBuf;
fn main() {
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
println!("cargo:rerun-if-changed=src/wrapper.h");
let libdpdk = Config::new()
.atleast_version("21.11.0")
.probe("libdpdk")
.expect("failed to probe dpdk");
let link_paths = libdpdk.link_paths.clone();
cc::Build::new()
.include("src")
.includes(link_paths)
.flag("-march=native")
.file("src/stub.c")
.cargo_metadata(true)
.shared_flag(true)
.compile("rte_stub");
for lib in libdpdk.libs {
println!("cargo:rustc-link-lib={lib}");
}
for path in libdpdk.link_paths {
let path = path.to_string_lossy();
println!("cargo:rustc-link-search=native={path}");
}
let include_args = libdpdk
.include_paths
.iter()
.map(|p| format!("-I{}", p.to_str().unwrap()))
.collect::<Vec<String>>();
let bindings = bindgen::builder()
.clang_args(include_args)
.header("src/wrapper.h")
.header("src/stub.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.allowlist_type("rte_.*")
.allowlist_var("RTE_.*")
.allowlist_var("rte_.*")
.allowlist_function("rte_.*")
.allowlist_function("__rte_pktmbuf_.*")
.blocklist_function("rte_flow_.*")
.blocklist_item("rte_flow_.*")
.blocklist_type("rte_flow_.*")
.blocklist_type("rte_mbuf")
.blocklist_type("rte_arp_ipv4")
.blocklist_type("rte_arp_hdr")
.blocklist_type("rte_ecpri_common_hdr")
.blocklist_type("rte_ecpri_combined_msg_hdr")
.blocklist_type("rte_l2tpv2_common_hdr")
.blocklist_type("rte_l2tpv2_combined_msg_hdr")
.blocklist_type("rte_ipv4_hdr")
.derive_copy(true)
.derive_debug(true)
.derive_default(false)
.generate_comments(true)
.size_t_is_usize(true)
.rustfmt_bindings(true)
.generate()
.expect("failed to generate bindings to dpdk");
bindings
.write_to_file(out_dir.join("bindings.rs"))
.expect("failed to write bindings");
}