Skip to content

Commit 704543e

Browse files
kxxtd-e-s-o
authored andcommitted
Use runtime CARGO_CFG_TARGET_ARCH in build-script
option_env retrieves the CARGO_CFG_TARGET_ARCH at compile-time, which is not correct for the usage here. Instead, we should retrieve the variable using env::var at runtime in the build-script.
1 parent 90d3c34 commit 704543e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

libbpf-cargo/src/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::HashSet;
2+
use std::env;
23
use std::env::consts::ARCH;
34
use std::ffi::OsStr;
45
use std::ffi::OsString;
@@ -184,7 +185,8 @@ fn compile_one(
184185
{
185186
// We may end up being invoked by a build script, in which case
186187
// `CARGO_CFG_TARGET_ARCH` would represent the target architecture.
187-
let arch = option_env!("CARGO_CFG_TARGET_ARCH").unwrap_or(ARCH);
188+
let arch = env::var("CARGO_CFG_TARGET_ARCH");
189+
let arch = arch.as_deref().unwrap_or(ARCH);
188190
let arch = match arch {
189191
"x86_64" => "x86",
190192
"aarch64" => "arm64",

0 commit comments

Comments
 (0)