Compare commits

..

No commits in common. '17573e0e47fd53c24097a1f92b3e0ecf66a298d4' and '03fea9e3042009cc43a76f2d15769ded69532be3' have entirely different histories.

@ -178,8 +178,9 @@ jobs:
for target in bpfeb-unknown-none bpfel-unknown-none; do for target in bpfeb-unknown-none bpfel-unknown-none; do
echo "::group::Build and test for $arch / $target" echo "::group::Build and test for $arch / $target"
if ! ( if ! (
export CARGO_CFG_BPF_TARGET_ARCH="$arch"
RUSTFLAGS="--cfg bpf_target_arch=\"$arch\"" cargo +nightly hack build \ cargo +nightly hack build \
--target "$target" \ --target "$target" \
-Z build-std=core \ -Z build-std=core \
--package aya-ebpf \ --package aya-ebpf \

@ -11,19 +11,21 @@ use std::{
use anyhow::{Context as _, Result, anyhow}; use anyhow::{Context as _, Result, anyhow};
use cargo_metadata::{Artifact, CompilerMessage, Message, Target}; use cargo_metadata::{Artifact, CompilerMessage, Message, Target};
#[derive(Default)]
pub struct Package<'a> { pub struct Package<'a> {
pub name: &'a str, pub name: &'a str,
pub root_dir: &'a str, pub root_dir: &'a str,
pub no_default_features: bool,
pub features: &'a [&'a str],
} }
fn target_arch_fixup(target_arch: Cow<'_, str>) -> Cow<'_, str> { fn target_arch() -> Cow<'static, str> {
const TARGET_ARCH: &str = "CARGO_CFG_TARGET_ARCH";
let target_arch = env::var_os(TARGET_ARCH).unwrap_or_else(|| panic!("{TARGET_ARCH} not set"));
let target_arch = target_arch.into_encoded_bytes();
let target_arch = String::from_utf8(target_arch)
.unwrap_or_else(|err| panic!("String::from_utf8({TARGET_ARCH}): {err:?}"));
if target_arch.starts_with("riscv64") { if target_arch.starts_with("riscv64") {
"riscv64".into() "riscv64".into()
} else { } else {
target_arch target_arch.into()
} }
} }
@ -56,22 +58,10 @@ pub fn build_ebpf<'a>(
return Err(anyhow!("unsupported endian={endian:?}")); return Err(anyhow!("unsupported endian={endian:?}"));
}; };
const TARGET_ARCH: &str = "CARGO_CFG_TARGET_ARCH"; let arch = target_arch();
let bpf_target_arch =
env::var_os(TARGET_ARCH).unwrap_or_else(|| panic!("{TARGET_ARCH} not set"));
let bpf_target_arch = bpf_target_arch
.into_string()
.unwrap_or_else(|err| panic!("OsString::into_string({TARGET_ARCH}): {err:?}"));
let bpf_target_arch = target_arch_fixup(bpf_target_arch.into());
let target = format!("{target}-unknown-none"); let target = format!("{target}-unknown-none");
for Package { for Package { name, root_dir } in packages {
name,
root_dir,
no_default_features,
features,
} in packages
{
// We have a build-dependency on `name`, so cargo will automatically rebuild us if `name`'s // We have a build-dependency on `name`, so cargo will automatically rebuild us if `name`'s
// *library* target or any of its dependencies change. Since we depend on `name`'s *binary* // *library* target or any of its dependencies change. Since we depend on `name`'s *binary*
// targets, that only gets us half of the way. This stanza ensures cargo will rebuild us on // targets, that only gets us half of the way. This stanza ensures cargo will rebuild us on
@ -94,10 +84,6 @@ pub fn build_ebpf<'a>(
"--target", "--target",
&target, &target,
]); ]);
if no_default_features {
cmd.arg("--no-default-features");
}
cmd.args(["--features", &features.join(",")]);
{ {
const SEPARATOR: &str = "\x1f"; const SEPARATOR: &str = "\x1f";
@ -106,7 +92,7 @@ pub fn build_ebpf<'a>(
for s in [ for s in [
"--cfg=bpf_target_arch=\"", "--cfg=bpf_target_arch=\"",
&bpf_target_arch, &arch,
"\"", "\"",
SEPARATOR, SEPARATOR,
"-Cdebuginfo=2", "-Cdebuginfo=2",
@ -216,45 +202,16 @@ impl<'a> Toolchain<'a> {
/// Emit cfg flags that describe the desired BPF target architecture. /// Emit cfg flags that describe the desired BPF target architecture.
pub fn emit_bpf_target_arch_cfg() { pub fn emit_bpf_target_arch_cfg() {
// The presence of this environment variable indicates that `--cfg const RUSTFLAGS: &str = "CARGO_ENCODED_RUSTFLAGS";
// 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 println!("cargo:rerun-if-env-changed={RUSTFLAGS}");
// is set by cargo. let rustc_cfgs = std::env::var_os(RUSTFLAGS).unwrap_or_else(|| panic!("{RUSTFLAGS} not set"));
const BPF_TARGET_ARCH: &str = "CARGO_CFG_BPF_TARGET_ARCH"; let rustc_cfgs = rustc_cfgs
println!("cargo:rerun-if-env-changed={BPF_TARGET_ARCH}"); .to_str()
.unwrap_or_else(|| panic!("{RUSTFLAGS}={rustc_cfgs:?} not unicode"));
// Users may directly set this environment variable in situations where if !rustc_cfgs.contains("bpf_target_arch") {
// using RUSTFLAGS to set `--cfg bpf_target_arch="..."` is not possible or let arch = target_arch();
// not ergonomic. In contrast to RUSTFLAGS this mechanism reuses the target println!("cargo:rustc-cfg=bpf_target_arch=\"{arch}\"");
// cache for all values, producing many more invalidations.
const AYA_BPF_TARGET_ARCH: &str = "AYA_BPF_TARGET_ARCH";
println!("cargo:rerun-if-env-changed={AYA_BPF_TARGET_ARCH}");
const HOST: &str = "HOST";
println!("cargo:rerun-if-env-changed={HOST}");
if std::env::var_os(BPF_TARGET_ARCH).is_none() {
let host = std::env::var_os(HOST).unwrap_or_else(|| panic!("{HOST} not set"));
let host = host
.into_string()
.unwrap_or_else(|err| panic!("OsString::into_string({HOST}): {err:?}"));
let host = host.as_str();
let bpf_target_arch = if let Some(bpf_target_arch) = std::env::var_os(AYA_BPF_TARGET_ARCH) {
bpf_target_arch
.into_string()
.unwrap_or_else(|err| {
panic!("OsString::into_string({AYA_BPF_TARGET_ARCH}): {err:?}")
})
.into()
} else {
target_arch_fixup(
host.split_once('-')
.map_or(host, |(arch, _rest)| arch)
.into(),
)
};
println!("cargo:rustc-cfg=bpf_target_arch=\"{bpf_target_arch}\"");
} }
print!("cargo::rustc-check-cfg=cfg(bpf_target_arch, values("); print!("cargo::rustc-check-cfg=cfg(bpf_target_arch, values(");

@ -293,13 +293,8 @@ impl<'a> EbpfLoader<'a> {
/// Override the value of a global variable. /// Override the value of a global variable.
#[deprecated(since = "0.13.2", note = "please use `override_global` instead")] #[deprecated(since = "0.13.2", note = "please use `override_global` instead")]
pub fn set_global<T: Into<GlobalData<'a>>>( pub fn set_global<T: Into<GlobalData<'a>>>(&mut self, name: &'a str, value: T) -> &mut Self {
&mut self, self.override_global(name, value, false)
name: &'a str,
value: T,
must_exist: bool,
) -> &mut Self {
self.override_global(name, value, must_exist)
} }
/// Set the max_entries for specified map. /// Set the max_entries for specified map.

@ -219,7 +219,6 @@ fn main() -> Result<()> {
.parent() .parent()
.ok_or_else(|| anyhow!("no parent for {manifest_path}"))? .ok_or_else(|| anyhow!("no parent for {manifest_path}"))?
.as_str(), .as_str(),
..Default::default()
}; };
aya_build::build_ebpf([integration_ebpf_package], aya_build::Toolchain::default())?; aya_build::build_ebpf([integration_ebpf_package], aya_build::Toolchain::default())?;
} else { } else {

@ -27,12 +27,8 @@ pub fn aya_build::Toolchain<'a>::borrow_mut(&mut self) -> &mut T
impl<T> core::convert::From<T> for aya_build::Toolchain<'a> impl<T> core::convert::From<T> for aya_build::Toolchain<'a>
pub fn aya_build::Toolchain<'a>::from(t: T) -> T pub fn aya_build::Toolchain<'a>::from(t: T) -> T
pub struct aya_build::Package<'a> pub struct aya_build::Package<'a>
pub aya_build::Package::features: &'a [&'a str]
pub aya_build::Package::name: &'a str pub aya_build::Package::name: &'a str
pub aya_build::Package::no_default_features: bool
pub aya_build::Package::root_dir: &'a str pub aya_build::Package::root_dir: &'a str
impl<'a> core::default::Default for aya_build::Package<'a>
pub fn aya_build::Package<'a>::default() -> aya_build::Package<'a>
impl<'a> core::marker::Freeze for aya_build::Package<'a> impl<'a> core::marker::Freeze for aya_build::Package<'a>
impl<'a> core::marker::Send for aya_build::Package<'a> impl<'a> core::marker::Send for aya_build::Package<'a>
impl<'a> core::marker::Sync for aya_build::Package<'a> impl<'a> core::marker::Sync for aya_build::Package<'a>

@ -10750,7 +10750,7 @@ pub fn aya::EbpfLoader<'a>::map_max_entries(&mut self, name: &'a str, size: u32)
pub fn aya::EbpfLoader<'a>::map_pin_path<P: core::convert::Into<alloc::borrow::Cow<'a, std::path::Path>>>(&mut self, name: &'a str, path: P) -> &mut Self pub fn aya::EbpfLoader<'a>::map_pin_path<P: core::convert::Into<alloc::borrow::Cow<'a, std::path::Path>>>(&mut self, name: &'a str, path: P) -> &mut Self
pub fn aya::EbpfLoader<'a>::new() -> Self pub fn aya::EbpfLoader<'a>::new() -> Self
pub fn aya::EbpfLoader<'a>::override_global<T: core::convert::Into<aya::GlobalData<'a>>>(&mut self, name: &'a str, value: T, must_exist: bool) -> &mut Self pub fn aya::EbpfLoader<'a>::override_global<T: core::convert::Into<aya::GlobalData<'a>>>(&mut self, name: &'a str, value: T, must_exist: bool) -> &mut Self
pub fn aya::EbpfLoader<'a>::set_global<T: core::convert::Into<aya::GlobalData<'a>>>(&mut self, name: &'a str, value: T, must_exist: bool) -> &mut Self pub fn aya::EbpfLoader<'a>::set_global<T: core::convert::Into<aya::GlobalData<'a>>>(&mut self, name: &'a str, value: T) -> &mut Self
pub fn aya::EbpfLoader<'a>::set_max_entries(&mut self, name: &'a str, size: u32) -> &mut Self pub fn aya::EbpfLoader<'a>::set_max_entries(&mut self, name: &'a str, size: u32) -> &mut Self
pub fn aya::EbpfLoader<'a>::verifier_log_level(&mut self, level: aya::VerifierLogLevel) -> &mut Self pub fn aya::EbpfLoader<'a>::verifier_log_level(&mut self, level: aya::VerifierLogLevel) -> &mut Self
impl core::default::Default for aya::EbpfLoader<'_> impl core::default::Default for aya::EbpfLoader<'_>

Loading…
Cancel
Save