-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
62 lines (52 loc) · 2.05 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
// Copyright (C) 2020 Gilberto "jibi" Bertin <[email protected]>
//
// This file is part of hydrogen peroxyde.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
extern crate bindgen;
use std::env;
use std::path::PathBuf;
use std::process::Command;
fn main() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
println!("cargo:rerun-if-changed=src/xsk/sys/wrapper.h");
println!("cargo:rerun-if-changed=deps/libbpf/src/libbpf.so");
println!("cargo:rerun-if-changed=kern/xsk_kern.c");
println!("cargo:rerun-if-changed=kern/utils.h");
println!(
"cargo:rustc-link-search=native={}/deps/libbpf/src",
manifest_dir
);
println!("cargo:rustc-link-lib=static=bpf");
println!("cargo:rustc-link-lib=elf");
println!("cargo:rustc-link-lib=z");
let bindings = bindgen::Builder::default()
.header("src/xsk/sys/wrapper.h")
.clang_arg("-Ideps/libbpf/include/uapi")
.clang_arg("-Ideps/libbpf/src")
.generate()
.expect("Unable to generate XSK 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!");
Command::new("make")
.args(&["-C", "kern"])
.status()
.expect("Failed to build XSK kernel object");
Command::new("make")
.args(&["-C", "deps/libbpf/src"])
.status()
.expect("Failed to build libbpf");
}