Skip to content

Commit ffe6e98

Browse files
committed
examples/rust: Include proper vmlinux.h
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: libbpf#247 Signed-off-by: Daniel Müller <[email protected]>
1 parent ef652aa commit ffe6e98

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

examples/rust/profile/build.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use std::env;
2+
use std::env::consts::ARCH;
3+
use std::path::Path;
24
use std::path::PathBuf;
35

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

1315
SkeletonBuilder::new()
1416
.source(SRC)
17+
.clang_args(format!(
18+
"-I{}",
19+
Path::new("../../../vmlinux")
20+
.join(match ARCH {
21+
"aarch64" => "arm64",
22+
"loongarch64" => "loongarch",
23+
"powerpc64" => "powerpc",
24+
"riscv64" => "riscv",
25+
"x86_64" => "x86",
26+
_ => ARCH,
27+
})
28+
.display()
29+
))
1530
.build_and_generate(out)
1631
.expect("bpf compilation failed");
1732
println!("cargo:rerun-if-changed={}", SRC);

examples/rust/profile/src/bpf/vmlinux.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/rust/tracecon/build.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use std::env;
2+
use std::env::consts::ARCH;
3+
use std::path::Path;
24
use std::path::PathBuf;
35

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

1315
SkeletonBuilder::new()
1416
.source(SRC)
17+
.clang_args(format!(
18+
"-I{}",
19+
Path::new("../../../vmlinux")
20+
.join(match ARCH {
21+
"aarch64" => "arm64",
22+
"loongarch64" => "loongarch",
23+
"powerpc64" => "powerpc",
24+
"riscv64" => "riscv",
25+
"x86_64" => "x86",
26+
_ => ARCH,
27+
})
28+
.display()
29+
))
1530
.build_and_generate(&out)
1631
.expect("bpf compilation failed");
1732
println!("cargo:rerun-if-changed={}", SRC);

examples/rust/tracecon/src/bpf/vmlinux.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/rust/xdp/build.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use std::env;
2+
use std::env::consts::ARCH;
3+
use std::path::Path;
24
use std::path::PathBuf;
35

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

1315
SkeletonBuilder::new()
1416
.source(SRC)
17+
.clang_args(format!(
18+
"-I{}",
19+
Path::new("../../../vmlinux")
20+
.join(match ARCH {
21+
"aarch64" => "arm64",
22+
"loongarch64" => "loongarch",
23+
"powerpc64" => "powerpc",
24+
"riscv64" => "riscv",
25+
"x86_64" => "x86",
26+
_ => ARCH,
27+
})
28+
.display()
29+
))
1530
.build_and_generate(out)
1631
.unwrap();
1732
println!("cargo:rerun-if-changed={}", SRC);

examples/rust/xdp/src/bpf/vmlinux.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)