forked from chenhengqi/libxdp-sys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
38 lines (32 loc) · 1.32 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
use std::env;
use std::path;
use std::process;
fn main() {
let src_dir = path::PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
let xdptools_dir = src_dir.join("xdp-tools");
let libxdp_dir = xdptools_dir.join("lib/libxdp");
let headers_dir = xdptools_dir.join("headers/xdp");
let libbpf_dir = xdptools_dir.join("lib/libbpf/src");
let bpf_headers_dir = libbpf_dir.join("root/usr/include");
let status = process::Command::new("make")
.arg("libxdp")
.current_dir(&xdptools_dir)
.status()
.expect("could not execute make");
assert!(status.success(), "make failed");
println!("cargo:rustc-link-search={}", libbpf_dir.display());
println!("cargo:rustc-link-search={}", libxdp_dir.display());
println!("cargo:rustc-link-lib=static=bpf");
println!("cargo:rustc-link-lib=static=xdp");
println!("cargo:rustc-link-lib=elf");
println!("cargo:rustc-link-lib=z");
bindgen::Builder::default()
.header("bindings.h")
.generate_inline_functions(true)
.clang_arg(format!("-I{}", bpf_headers_dir.display()))
.clang_arg(format!("-I{}", headers_dir.display()))
.generate()
.expect("Unable to generate bindings")
.write_to_file(src_dir.join("src/bindings.rs"))
.expect("Couldn't write bindings");
}