workspace: include eBPF crates in default-members

Being able to compile the eBPF crates for the host architecture is
useful because it allows `cargo build` and `cargo test` to "just work".

To achieve that, we feature-gate `no_std` and `no_main` on the bpf
target architecture.
reviewable/pr1229/r14
Thomas Eizinger 3 weeks ago
parent 08ea655b10
commit 239acac2c5
No known key found for this signature in database
GPG Key ID: 05633CD77196CAF3

@ -42,9 +42,10 @@ default-members = [
"aya-ebpf-macros",
"aya-log-ebpf-macros",
# ebpf crates are omitted; they must be built with:
# --target bpfe{b,l}-unknown-none
# CARGO_CFG_BPF_TARGET_ARCH={x86_64,aarch64,arm,riscv64,powerpc64,s390x,mips}
"ebpf/aya-ebpf",
"ebpf/aya-ebpf-bindings",
"ebpf/aya-log-ebpf",
"test/integration-ebpf",
]
[workspace.package]

@ -133,6 +133,16 @@ pub fn check_bounds_signed(value: i64, lower: i64, upper: i64) -> bool {
}
}
#[macro_export]
macro_rules! main_stub {
() => {
#[cfg(not(target_arch = "bpf"))]
fn main() {
panic!(r#"eBPF kernels are not designed to be executed in user-space. This main function is only a placeholder to allow the code to compile on the host system (i.e. on any system that is not `target_arch = "bpf"`). This works in tandem with the `no_main` attribute which is only applied when compiling for `target_arch = "bpf"`."#)
}
};
}
#[macro_export]
macro_rules! panic_handler {
() => {

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use aya_ebpf::{
helpers::{bpf_probe_read_kernel_str_bytes, bpf_probe_read_user_str_bytes},

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use core::net::{IpAddr, Ipv4Addr, Ipv6Addr};

@ -1,8 +1,9 @@
// Socket Filter program for testing with an arbitrary program with maps.
// This is mainly used in tests with consideration for old kernels.
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use aya_ebpf::{
macros::{map, socket_filter},

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use core::mem;

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use aya_ebpf::{bindings::xdp_action, macros::xdp, programs::XdpContext};

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use aya_ebpf::{bindings::xdp_action, macros::xdp, programs::XdpContext};

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use aya_ebpf::{
macros::{map, raw_tracepoint},

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use aya_ebpf::{
bindings::xdp_action,

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use core::hint;

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use aya_ebpf::{
macros::{map, uprobe},

@ -1,8 +1,9 @@
// Socket Filter program for testing with an arbitrary program.
// This is mainly used in tests with consideration for old kernels.
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use aya_ebpf::{macros::socket_filter, programs::SkBuffContext};

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use aya_ebpf::{
cty::c_long,

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use aya_ebpf::{bindings::tcx_action_base::TCX_NEXT, macros::classifier, programs::TcContext};

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use aya_ebpf::{
bindings::{bpf_ret_code, xdp_action},

@ -1,7 +1,8 @@
// Two programs in the same ELF section
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use aya_ebpf::{macros::tracepoint, programs::TracePointContext};

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use aya_ebpf::{
EbpfContext as _, helpers,

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![cfg_attr(target_arch = "bpf", no_std)]
#![cfg_attr(target_arch = "bpf", no_main)]
aya_ebpf::main_stub!();
use aya_ebpf::{bindings::xdp_action::XDP_PASS, macros::xdp, programs::XdpContext};

@ -2728,6 +2728,7 @@ pub fn aya_ebpf::programs::xdp::XdpContext::borrow_mut(&mut self) -> &mut T
impl<T> core::convert::From<T> for aya_ebpf::programs::xdp::XdpContext
pub fn aya_ebpf::programs::xdp::XdpContext::from(t: T) -> T
pub macro aya_ebpf::bpf_printk!
pub macro aya_ebpf::main_stub!
pub macro aya_ebpf::panic_handler!
pub struct aya_ebpf::PtRegs
impl aya_ebpf::PtRegs

Loading…
Cancel
Save