Skip to content

Commit 303544b

Browse files
d-e-s-oanakryiko
authored andcommitted
examples/rust: Use CARGO_CFG_TARGET_ARCH environment variable
As per libbpf#257, it appears as if `std::env::consts::ARCH` does not get updated to the target architecture in a cross-compilation context. Switch to using the `CARGO_CFG_TARGET_ARCH` environment variable in the hopes that we get the desired behavior. Signed-off-by: Daniel Müller <deso@posteo.net>
1 parent b0c8234 commit 303544b

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

examples/rust/profile/build.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::env;
2-
use std::env::consts::ARCH;
32
use std::path::Path;
43
use std::path::PathBuf;
54

@@ -12,18 +11,21 @@ fn main() {
1211
PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR must be set in build script"));
1312
out.push("profile.skel.rs");
1413

14+
let arch = env::var("CARGO_CFG_TARGET_ARCH")
15+
.expect("CARGO_CFG_TARGET_ARCH must be set in build script");
16+
1517
SkeletonBuilder::new()
1618
.source(SRC)
1719
.clang_args(format!(
1820
"-I{}",
1921
Path::new("../../../vmlinux")
20-
.join(match ARCH {
22+
.join(match arch.as_ref() {
2123
"aarch64" => "arm64",
2224
"loongarch64" => "loongarch",
2325
"powerpc64" => "powerpc",
2426
"riscv64" => "riscv",
2527
"x86_64" => "x86",
26-
_ => ARCH,
28+
_ => &arch,
2729
})
2830
.display()
2931
))

examples/rust/tracecon/build.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::env;
2-
use std::env::consts::ARCH;
32
use std::path::Path;
43
use std::path::PathBuf;
54

@@ -12,18 +11,21 @@ fn main() {
1211
PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR must be set in build script"));
1312
out.push("tracecon.skel.rs");
1413

14+
let arch = env::var("CARGO_CFG_TARGET_ARCH")
15+
.expect("CARGO_CFG_TARGET_ARCH must be set in build script");
16+
1517
SkeletonBuilder::new()
1618
.source(SRC)
1719
.clang_args(format!(
1820
"-I{}",
1921
Path::new("../../../vmlinux")
20-
.join(match ARCH {
22+
.join(match arch.as_ref() {
2123
"aarch64" => "arm64",
2224
"loongarch64" => "loongarch",
2325
"powerpc64" => "powerpc",
2426
"riscv64" => "riscv",
2527
"x86_64" => "x86",
26-
_ => ARCH,
28+
_ => &arch,
2729
})
2830
.display()
2931
))

examples/rust/xdp/build.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::env;
2-
use std::env::consts::ARCH;
32
use std::path::Path;
43
use std::path::PathBuf;
54

@@ -12,18 +11,21 @@ fn main() {
1211
PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR must be set in build script"));
1312
out.push("xdppass.skel.rs");
1413

14+
let arch = env::var("CARGO_CFG_TARGET_ARCH")
15+
.expect("CARGO_CFG_TARGET_ARCH must be set in build script");
16+
1517
SkeletonBuilder::new()
1618
.source(SRC)
1719
.clang_args(format!(
1820
"-I{}",
1921
Path::new("../../../vmlinux")
20-
.join(match ARCH {
22+
.join(match arch.as_ref() {
2123
"aarch64" => "arm64",
2224
"loongarch64" => "loongarch",
2325
"powerpc64" => "powerpc",
2426
"riscv64" => "riscv",
2527
"x86_64" => "x86",
26-
_ => ARCH,
28+
_ => &arch,
2729
})
2830
.display()
2931
))

0 commit comments

Comments
 (0)