Browse Source

aya-build: simplify

Cargo sets `CARGO_CFG_BPF_TARGET_ARCH` so we don't have to inspect
`CARGO_ENCODED_RUSTFLAGS`.
Tamir Duberstein 2 days ago
parent
commit
4b0ddfc2b0
1 changed files with 7 additions and 8 deletions
  1. 7 8
      aya-build/src/lib.rs

+ 7 - 8
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}\"");
     }