Skip to content

Commit

Permalink
dev: Use vmlinux.h repository as build-dependency
Browse files Browse the repository at this point in the history
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 <deso@posteo.net>
  • Loading branch information
d-e-s-o authored and danielocfb committed Oct 11, 2024
1 parent acae225 commit f5d72ad
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 31 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libbpf-cargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ clap = { version = "4.0.32", features = ["derive"] }

[dev-dependencies]
goblin = "0.6"
vmlinux = { version = "0.0", git = "https://github.com/libbpf/vmlinux.h.git", rev = "a9c092aa771310bf8b00b5018f7d40a1fdb6ec82" }
vmlinux = { git = "https://github.com/libbpf/vmlinux.h.git", rev = "a9c092aa771310bf8b00b5018f7d40a1fdb6ec82" }
1 change: 1 addition & 0 deletions libbpf-rs/dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ dont-generate-test-files = []
[build-dependencies]
libbpf-sys = { version = "1.4.1", default-features = false, optional = true }
tempfile = { version = "3.3", optional = true }
vmlinux = { git = "https://github.com/libbpf/vmlinux.h.git", rev = "a9c092aa771310bf8b00b5018f7d40a1fdb6ec82" }
34 changes: 4 additions & 30 deletions libbpf-rs/dev/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::io::ErrorKind;
use std::io::Result;
use std::ops::Deref as _;
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
use std::process::Output;
use std::process::Stdio;
Expand Down Expand Up @@ -67,19 +66,13 @@ where
}


fn run_impl<C, A, S>(command: C, args: A, stdout: Stdio, cwd: Option<&Path>) -> Result<Output>
fn run_impl<C, A, S>(command: C, args: A, stdout: Stdio) -> Result<Output>
where
C: AsRef<OsStr>,
A: IntoIterator<Item = S> + Clone,
S: AsRef<OsStr>,
{
let mut builder = Command::new(command.as_ref());

if let Some(cwd) = cwd {
builder.current_dir(cwd);
}

let output = builder
let output = Command::new(command.as_ref())
.stdin(Stdio::null())
.stdout(stdout)
.env_clear()
Expand Down Expand Up @@ -107,23 +100,10 @@ where
A: IntoIterator<Item = S> + Clone,
S: AsRef<OsStr>,
{
let cwd = None;
let _output = run_impl(command, args, Stdio::null(), cwd)?;
let _output = run_impl(command, args, Stdio::null())?;
Ok(())
}

/// Run a command and capture its output.
fn output<C, A, S, P>(command: C, args: A, cwd: P) -> Result<Vec<u8>>
where
C: AsRef<OsStr>,
A: IntoIterator<Item = S> + Clone,
S: AsRef<OsStr>,
P: AsRef<Path>,
{
let output = run_impl(command, args, Stdio::piped(), Some(cwd.as_ref()))?;
Ok(output.stdout)
}

fn adjust_mtime(path: &Path) -> Result<()> {
// Note that `OUT_DIR` is only present at runtime.
let out_dir = env::var("OUT_DIR").unwrap();
Expand Down Expand Up @@ -219,13 +199,7 @@ where
fn prepare_test_files(crate_root: &Path) {
let bin_dir = crate_root.join("tests").join("bin");
let src_dir = bin_dir.join("src");
let include_root = output(
"cargo",
["run", "--quiet"],
crate_root.parent().unwrap().join("vmlinux-include"),
)
.unwrap();
let include = PathBuf::from(&String::from_utf8(include_root).unwrap().trim_end()).join(ARCH);
let include = vmlinux::include_path_root().join(ARCH);

with_bpf_headers(|bpf_hdr_dir| {
for result in read_dir(&src_dir).unwrap() {
Expand Down

0 comments on commit f5d72ad

Please # to comment.