Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gen: run automatically #1168

Merged
merged 6 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ jobs:
- uses: peter-evans/create-pull-request@v7
if: github.event_name != 'pull_request' && github.repository_owner == 'aya-rs'
with:
commit-message: "public-api: regenerate"
branch: create-pull-request/public-api
commit-message: 'public-api: regenerate'
title: 'public-api: regenerate'
body: |
**Automated changes**

- name: Run miri
run: |
Expand Down
65 changes: 21 additions & 44 deletions .github/workflows/gen.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
name: codegen

on: workflow_dispatch
on:
push:
branches:
- main

schedule:
- cron: 00 4 * * *

workflow_dispatch:

jobs:
codegen:
Expand All @@ -11,64 +19,33 @@ jobs:
with:
submodules: recursive

- name: update libbpf
working-directory: xtask/libbpf
run: |
set -e
git fetch origin
git checkout origin/HEAD
echo "LIBBPF_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV

- uses: dtolnay/rust-toolchain@master
- uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
components: rustfmt, clippy

- uses: Swatinem/rust-cache@v2

- name: Install headers
run: |
set -euxo pipefail
sudo apt -y update
sudo apt -y install libelf-dev libc6-dev libc6-dev-{arm64,armel,riscv64,ppc64el,s390x,mips}-cross

- name: Run codegen
run: |
cargo xtask codegen

- name: Check for changes
run: |
git diff --quiet || echo "COMMIT_CHANGES=1" >> $GITHUB_ENV
- run: cargo xtask codegen
- run: cargo xtask public-api --bless

- name: Bless public API changes
if: env.COMMIT_CHANGES == 1
run: |
cargo xtask public-api --bless
- run: echo "LIBBPF_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
working-directory: xtask/libbpf

- name: Commit Changes
id: commit
if: env.COMMIT_CHANGES == 1
uses: devops-infra/action-commit-push@master
- uses: peter-evans/create-pull-request@v7
with:
github_token: "${{ secrets.CRABBY_GITHUB_TOKEN }}"
commit_message: |
chore(aya-obj, aya-ebpf-bindings): Regenerate bindings
branch: create-pull-request/codegen
commit-message: |
aya-obj, aya-ebpf-bindings: regenerate

libbpf commit: ${{ env.LIBBPF_SHA }}

target_branch: codegen
force: true

- name: Create pull request
if: steps.commit.outputs.files_changed != ''
uses: devops-infra/action-pull-request@master
with:
github_token: ${{ secrets.CRABBY_GITHUB_TOKEN }}
title: 'aya-obj, aya-ebpf-bindings: regenerate'
body: |
**Automated pull request**
**Automated changes**

libbpf commit: ${{ env.LIBBPF_SHA }}

title: "chore(aya-obj, aya-ebpf-bindings): Regenerate bindings"
source_branch: codegen
target_branch: main
get_diff: true
7 changes: 1 addition & 6 deletions aya-obj/include/linux_wrapper.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <asm-generic/socket.h>
#include <linux/bpf.h>
#include <linux/btf.h>
#include <linux/if_link.h>
Expand All @@ -7,8 +6,4 @@
#include <linux/pkt_cls.h>
#include <linux/pkt_sched.h>
#include <linux/rtnetlink.h>

/* workaround the fact that bindgen can't parse the IOC macros */
int AYA_PERF_EVENT_IOC_ENABLE = PERF_EVENT_IOC_ENABLE;
int AYA_PERF_EVENT_IOC_DISABLE = PERF_EVENT_IOC_DISABLE;
int AYA_PERF_EVENT_IOC_SET_BPF = PERF_EVENT_IOC_SET_BPF;
#include <sys/socket.h>
2 changes: 1 addition & 1 deletion aya-tool/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn generate<T: AsRef<str>>(
let dir = tempdir().unwrap();
let file_path = dir.path().join(name);
let mut file = File::create(&file_path).unwrap();
let _ = file.write(c_header.as_bytes()).unwrap();
let () = file.write_all(c_header.as_bytes()).unwrap();

let flags = combine_flags(&bindgen.command_line_flags(), &additional_flags);

Expand Down
6 changes: 0 additions & 6 deletions aya/src/bpf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{
borrow::Cow,
collections::{HashMap, HashSet},
ffi::c_int,
fs, io,
os::fd::{AsFd as _, AsRawFd as _},
path::{Path, PathBuf},
Expand All @@ -12,7 +11,6 @@ use aya_obj::{
btf::{Btf, BtfError, BtfFeatures, BtfRelocationError},
generated::{
bpf_map_type::{self, *},
AYA_PERF_EVENT_IOC_DISABLE, AYA_PERF_EVENT_IOC_ENABLE, AYA_PERF_EVENT_IOC_SET_BPF,
BPF_F_SLEEPABLE, BPF_F_XDP_HAS_FRAGS,
},
relocation::EbpfRelocationError,
Expand Down Expand Up @@ -40,10 +38,6 @@ use crate::{
util::{bytes_of, bytes_of_slice, nr_cpus, page_size},
};

pub(crate) const PERF_EVENT_IOC_ENABLE: c_int = AYA_PERF_EVENT_IOC_ENABLE;
pub(crate) const PERF_EVENT_IOC_DISABLE: c_int = AYA_PERF_EVENT_IOC_DISABLE;
pub(crate) const PERF_EVENT_IOC_SET_BPF: c_int = AYA_PERF_EVENT_IOC_SET_BPF;

/// Marker trait for types that can safely be converted to and from byte slices.
pub unsafe trait Pod: Copy + 'static {}

Expand Down
6 changes: 2 additions & 4 deletions aya/src/maps/perf/perf_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ use std::{
use aya_obj::generated::{
perf_event_header, perf_event_mmap_page,
perf_event_type::{PERF_RECORD_LOST, PERF_RECORD_SAMPLE},
PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE,
};
use bytes::BytesMut;
use libc::{munmap, MAP_FAILED, MAP_SHARED, PROT_READ, PROT_WRITE};
use thiserror::Error;

use crate::{
sys::{mmap, perf_event_ioctl, perf_event_open_bpf, SysResult},
PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE,
};
use crate::sys::{mmap, perf_event_ioctl, perf_event_open_bpf, SysResult};

/// Perf buffer error.
#[derive(Error, Debug)]
Expand Down
7 changes: 5 additions & 2 deletions aya/src/programs/perf_attach.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Perf attach links.
use std::os::fd::{AsFd as _, AsRawFd as _, BorrowedFd, RawFd};

use aya_obj::generated::bpf_attach_type::BPF_PERF_EVENT;
use aya_obj::generated::{
bpf_attach_type::BPF_PERF_EVENT, PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE,
PERF_EVENT_IOC_SET_BPF,
};

use crate::{
programs::{
Expand All @@ -13,7 +16,7 @@ use crate::{
bpf_link_create, is_bpf_cookie_supported, perf_event_ioctl, BpfLinkCreateArgs, LinkTarget,
SysResult, SyscallError,
},
FEATURES, PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE, PERF_EVENT_IOC_SET_BPF,
FEATURES,
};

#[derive(Debug, Hash, Eq, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion aya/src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(crate) enum Syscall<'a> {
},
PerfEventIoctl {
fd: BorrowedFd<'a>,
request: c_int,
request: u32,
arg: c_int,
},
}
Expand Down
6 changes: 1 addition & 5 deletions aya/src/sys/perf_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ pub(crate) fn perf_event_open_trace_point(
perf_event_sys(attr, pid, cpu, PERF_FLAG_FD_CLOEXEC)
}

pub(crate) fn perf_event_ioctl(
fd: BorrowedFd<'_>,
request: c_int,
arg: c_int,
) -> SysResult<c_long> {
pub(crate) fn perf_event_ioctl(fd: BorrowedFd<'_>, request: u32, arg: c_int) -> SysResult<c_long> {
let call = Syscall::PerfEventIoctl { fd, request, arg };
#[cfg(not(test))]
return syscall(call);
Expand Down
7 changes: 4 additions & 3 deletions ebpf/aya-ebpf-bindings/include/bindings.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <linux/types.h>
// __wsum is missing from types.h, see
// https://elixir.bootlin.com/linux/v5.13/source/include/uapi/linux/types.h
// __wsum is missing from types.h, compare:
// https://github.com/torvalds/linux/blob/v5.13/include/uapi/linux/types.h
// https://github.com/libbpf/libbpf/blob/v1.5.0/include/linux/types.h
typedef __u32 __bitwise __wsum;

#include "bpf_helpers.h"
#include <bpf/bpf_helpers.h>
#include <linux/bpf.h>
// needed for TC_ACT_*
#include <linux/pkt_cls.h>
Expand Down
Loading
Loading