From 4b0ddfc2b0f671d43fbcdeb78c9e46b099404f53 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 29 Oct 2025 07:44:57 -0400 Subject: [PATCH] aya-build: simplify Cargo sets `CARGO_CFG_BPF_TARGET_ARCH` so we don't have to inspect `CARGO_ENCODED_RUSTFLAGS`. --- aya-build/src/lib.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/aya-build/src/lib.rs b/aya-build/src/lib.rs index bc1a01e0..0013d042 100644 --- a/aya-build/src/lib.rs +++ b/aya-build/src/lib.rs @@ -202,14 +202,13 @@ impl<'a> Toolchain<'a> { /// Emit cfg flags that describe the desired BPF target architecture. pub fn emit_bpf_target_arch_cfg() { - const RUSTFLAGS: &str = "CARGO_ENCODED_RUSTFLAGS"; - - println!("cargo:rerun-if-env-changed={RUSTFLAGS}"); - let rustc_cfgs = std::env::var_os(RUSTFLAGS).unwrap_or_else(|| panic!("{RUSTFLAGS} not set")); - let rustc_cfgs = rustc_cfgs - .to_str() - .unwrap_or_else(|| panic!("{RUSTFLAGS}={rustc_cfgs:?} not unicode")); - if !rustc_cfgs.contains("bpf_target_arch") { + // The presence of this environment variable indicates that `--cfg + // bpf_target_arch="..."` was passed to the compiler, so we don't need to + // emit it again. Note that we cannot *set* this environment variable - it + // is set by cargo. + const BPF_TARGET_ARCH: &str = "CARGO_CFG_BPF_TARGET_ARCH"; + println!("cargo:rerun-if-env-changed={BPF_TARGET_ARCH}"); + if std::env::var_os(BPF_TARGET_ARCH).is_none() { let bpf_target_arch = target_arch(); println!("cargo:rustc-cfg=bpf_target_arch=\"{bpf_target_arch}\""); }