Skip to content

Commit

Permalink
examples: Use vmlinux.h for current architecture
Browse files Browse the repository at this point in the history
In order to compile the BPF byte code the examples need vmlinux.h to be
available. This header is vendored alongside the examples, but it is
specific to x86. That causes issues once said examples are compiled for
any other architecture.
This change fixes this problem by vendoring vmlinux.h for more
architectures (copied from libbpf-bootstrap, where we maintain such a
set of header files already). It also adjusts all examples to pick the
appropriate header file for the architecture currently being targeted.

Fixes: #615

Signed-off-by: Daniel Müller <[email protected]>
  • Loading branch information
d-e-s-o authored and danielocfb committed Jan 18, 2024
1 parent 59b482a commit beff188
Show file tree
Hide file tree
Showing 23 changed files with 845,234 additions and 103,191 deletions.
9 changes: 8 additions & 1 deletion examples/capable/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use libbpf_cargo::SkeletonBuilder;
use std::env;
use std::env::consts::ARCH;
use std::path::Path;
use std::path::PathBuf;

use libbpf_cargo::SkeletonBuilder;

const SRC: &str = "src/bpf/capable.bpf.c";

fn main() {
Expand All @@ -10,6 +13,10 @@ fn main() {
out.push("capable.skel.rs");
SkeletonBuilder::new()
.source(SRC)
.clang_args(format!(
"-I{}",
Path::new("../vmlinux").join(ARCH).display()
))
.build_and_generate(&out)
.unwrap();
println!("cargo:rerun-if-changed={SRC}");
Expand Down
1 change: 0 additions & 1 deletion examples/capable/src/bpf/vmlinux.h

This file was deleted.

9 changes: 8 additions & 1 deletion examples/runqslower/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use libbpf_cargo::SkeletonBuilder;
use std::env;
use std::env::consts::ARCH;
use std::path::Path;
use std::path::PathBuf;

use libbpf_cargo::SkeletonBuilder;

const SRC: &str = "src/bpf/runqslower.bpf.c";

fn main() {
Expand All @@ -10,6 +13,10 @@ fn main() {
out.push("runqslower.skel.rs");
SkeletonBuilder::new()
.source(SRC)
.clang_args(format!(
"-I{}",
Path::new("../vmlinux").join(ARCH).display()
))
.build_and_generate(&out)
.unwrap();
println!("cargo:rerun-if-changed={SRC}");
Expand Down
1 change: 0 additions & 1 deletion examples/runqslower/src/bpf/vmlinux.h

This file was deleted.

9 changes: 8 additions & 1 deletion examples/tc_port_whitelist/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use libbpf_cargo::SkeletonBuilder;
use std::env;
use std::env::consts::ARCH;
use std::path::Path;
use std::path::PathBuf;

use libbpf_cargo::SkeletonBuilder;

const SRC: &str = "src/bpf/tc.bpf.c";

fn main() {
Expand All @@ -10,6 +13,10 @@ fn main() {
out.push("tc.skel.rs");
SkeletonBuilder::new()
.source(SRC)
.clang_args(format!(
"-I{}",
Path::new("../vmlinux").join(ARCH).display()
))
.build_and_generate(&out)
.unwrap();
println!("cargo:rerun-if-changed={SRC}");
Expand Down
1 change: 0 additions & 1 deletion examples/tc_port_whitelist/src/bpf/vmlinux.h

This file was deleted.

10 changes: 8 additions & 2 deletions examples/tproxy/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use libbpf_cargo::SkeletonBuilder;
use std::env;
use std::env::consts::ARCH;
use std::path::Path;
use std::path::PathBuf;

use libbpf_cargo::SkeletonBuilder;

const SRC: &str = "src/bpf/tproxy.bpf.c";

fn main() {
Expand All @@ -10,7 +13,10 @@ fn main() {
out.push("tproxy.skel.rs");
SkeletonBuilder::new()
.source(SRC)
.clang_args("-Wno-compare-distinct-pointer-types")
.clang_args(format!(
"-Wno-compare-distinct-pointer-types -I{}",
Path::new("../vmlinux").join(ARCH).display()
))
.build_and_generate(&out)
.unwrap();
println!("cargo:rerun-if-changed={SRC}");
Expand Down
1 change: 0 additions & 1 deletion examples/tproxy/src/bpf/vmlinux.h

This file was deleted.

1 change: 1 addition & 0 deletions examples/vmlinux/aarch64/vmlinux.h

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

Loading

0 comments on commit beff188

Please sign in to comment.