Skip to content

Commit f5d72ad

Browse files
d-e-s-odanielocfb
authored andcommitted
dev: Use vmlinux.h repository as build-dependency
Use vmlinux.h as a proper build-dependency instead of shelling out to Cargo, now that we are in a context that even Cargo recognizes as dev-only. Signed-off-by: Daniel Müller <[email protected]>
1 parent acae225 commit f5d72ad

File tree

4 files changed

+7
-31
lines changed

4 files changed

+7
-31
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libbpf-cargo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ clap = { version = "4.0.32", features = ["derive"] }
4242

4343
[dev-dependencies]
4444
goblin = "0.6"
45-
vmlinux = { version = "0.0", git = "https://github.com/libbpf/vmlinux.h.git", rev = "a9c092aa771310bf8b00b5018f7d40a1fdb6ec82" }
45+
vmlinux = { git = "https://github.com/libbpf/vmlinux.h.git", rev = "a9c092aa771310bf8b00b5018f7d40a1fdb6ec82" }

libbpf-rs/dev/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ dont-generate-test-files = []
2121
[build-dependencies]
2222
libbpf-sys = { version = "1.4.1", default-features = false, optional = true }
2323
tempfile = { version = "3.3", optional = true }
24+
vmlinux = { git = "https://github.com/libbpf/vmlinux.h.git", rev = "a9c092aa771310bf8b00b5018f7d40a1fdb6ec82" }

libbpf-rs/dev/build.rs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::io::ErrorKind;
99
use std::io::Result;
1010
use std::ops::Deref as _;
1111
use std::path::Path;
12-
use std::path::PathBuf;
1312
use std::process::Command;
1413
use std::process::Output;
1514
use std::process::Stdio;
@@ -67,19 +66,13 @@ where
6766
}
6867

6968

70-
fn run_impl<C, A, S>(command: C, args: A, stdout: Stdio, cwd: Option<&Path>) -> Result<Output>
69+
fn run_impl<C, A, S>(command: C, args: A, stdout: Stdio) -> Result<Output>
7170
where
7271
C: AsRef<OsStr>,
7372
A: IntoIterator<Item = S> + Clone,
7473
S: AsRef<OsStr>,
7574
{
76-
let mut builder = Command::new(command.as_ref());
77-
78-
if let Some(cwd) = cwd {
79-
builder.current_dir(cwd);
80-
}
81-
82-
let output = builder
75+
let output = Command::new(command.as_ref())
8376
.stdin(Stdio::null())
8477
.stdout(stdout)
8578
.env_clear()
@@ -107,23 +100,10 @@ where
107100
A: IntoIterator<Item = S> + Clone,
108101
S: AsRef<OsStr>,
109102
{
110-
let cwd = None;
111-
let _output = run_impl(command, args, Stdio::null(), cwd)?;
103+
let _output = run_impl(command, args, Stdio::null())?;
112104
Ok(())
113105
}
114106

115-
/// Run a command and capture its output.
116-
fn output<C, A, S, P>(command: C, args: A, cwd: P) -> Result<Vec<u8>>
117-
where
118-
C: AsRef<OsStr>,
119-
A: IntoIterator<Item = S> + Clone,
120-
S: AsRef<OsStr>,
121-
P: AsRef<Path>,
122-
{
123-
let output = run_impl(command, args, Stdio::piped(), Some(cwd.as_ref()))?;
124-
Ok(output.stdout)
125-
}
126-
127107
fn adjust_mtime(path: &Path) -> Result<()> {
128108
// Note that `OUT_DIR` is only present at runtime.
129109
let out_dir = env::var("OUT_DIR").unwrap();
@@ -219,13 +199,7 @@ where
219199
fn prepare_test_files(crate_root: &Path) {
220200
let bin_dir = crate_root.join("tests").join("bin");
221201
let src_dir = bin_dir.join("src");
222-
let include_root = output(
223-
"cargo",
224-
["run", "--quiet"],
225-
crate_root.parent().unwrap().join("vmlinux-include"),
226-
)
227-
.unwrap();
228-
let include = PathBuf::from(&String::from_utf8(include_root).unwrap().trim_end()).join(ARCH);
202+
let include = vmlinux::include_path_root().join(ARCH);
229203

230204
with_bpf_headers(|bpf_hdr_dir| {
231205
for result in read_dir(&src_dir).unwrap() {

0 commit comments

Comments
 (0)