Skip to content

Commit

Permalink
examples/rust: Include proper vmlinux.h
Browse files Browse the repository at this point in the history
The example need to include the correct vmlinux.h header for the current
architecture if they aim to build on arches other than x86. Adjust the
logic accordingly.

Fixes: #247

Signed-off-by: Daniel Müller <[email protected]>
  • Loading branch information
d-e-s-o committed Jan 12, 2024
1 parent ef652aa commit ffe6e98
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
15 changes: 15 additions & 0 deletions examples/rust/profile/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::env;
use std::env::consts::ARCH;
use std::path::Path;
use std::path::PathBuf;

use libbpf_cargo::SkeletonBuilder;
Expand All @@ -12,6 +14,19 @@ fn main() {

SkeletonBuilder::new()
.source(SRC)
.clang_args(format!(
"-I{}",
Path::new("../../../vmlinux")
.join(match ARCH {
"aarch64" => "arm64",
"loongarch64" => "loongarch",
"powerpc64" => "powerpc",
"riscv64" => "riscv",
"x86_64" => "x86",
_ => ARCH,
})
.display()
))
.build_and_generate(out)
.expect("bpf compilation failed");
println!("cargo:rerun-if-changed={}", SRC);
Expand Down
1 change: 0 additions & 1 deletion examples/rust/profile/src/bpf/vmlinux.h

This file was deleted.

15 changes: 15 additions & 0 deletions examples/rust/tracecon/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::env;
use std::env::consts::ARCH;
use std::path::Path;
use std::path::PathBuf;

use libbpf_cargo::SkeletonBuilder;
Expand All @@ -12,6 +14,19 @@ fn main() {

SkeletonBuilder::new()
.source(SRC)
.clang_args(format!(
"-I{}",
Path::new("../../../vmlinux")
.join(match ARCH {
"aarch64" => "arm64",
"loongarch64" => "loongarch",
"powerpc64" => "powerpc",
"riscv64" => "riscv",
"x86_64" => "x86",
_ => ARCH,
})
.display()
))
.build_and_generate(&out)
.expect("bpf compilation failed");
println!("cargo:rerun-if-changed={}", SRC);
Expand Down
1 change: 0 additions & 1 deletion examples/rust/tracecon/src/bpf/vmlinux.h

This file was deleted.

15 changes: 15 additions & 0 deletions examples/rust/xdp/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::env;
use std::env::consts::ARCH;
use std::path::Path;
use std::path::PathBuf;

use libbpf_cargo::SkeletonBuilder;
Expand All @@ -12,6 +14,19 @@ fn main() {

SkeletonBuilder::new()
.source(SRC)
.clang_args(format!(
"-I{}",
Path::new("../../../vmlinux")
.join(match ARCH {
"aarch64" => "arm64",
"loongarch64" => "loongarch",
"powerpc64" => "powerpc",
"riscv64" => "riscv",
"x86_64" => "x86",
_ => ARCH,
})
.display()
))
.build_and_generate(out)
.unwrap();
println!("cargo:rerun-if-changed={}", SRC);
Expand Down
1 change: 0 additions & 1 deletion examples/rust/xdp/src/bpf/vmlinux.h

This file was deleted.

0 comments on commit ffe6e98

Please sign in to comment.