Skip to content

Commit bc4af4d

Browse files
Merge branch 'master' into dependabot/github_actions/actions-e3feb9629e
2 parents ba7f6c1 + 5273b61 commit bc4af4d

File tree

10 files changed

+90
-126
lines changed

10 files changed

+90
-126
lines changed

.github/workflows/pip.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,36 @@ jobs:
1515
matrix:
1616
platform: [ubuntu-latest]
1717
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
18-
18+
1919
runs-on: ${{ matrix.platform }}
20-
20+
2121
steps:
2222
- uses: actions/checkout@v5
2323
with:
2424
submodules: true
25-
2625
- uses: actions/setup-python@v6
2726
with:
2827
python-version: ${{ matrix.python-version }}
29-
28+
3029
- name: Install system dependencies
3130
run: |
3231
sudo apt-get update
3332
sudo apt-get install -y \
3433
libbpf-dev \
34+
libelf-dev \
3535
linux-headers-generic \
3636
build-essential \
3737
cmake \
3838
ninja-build
39-
39+
4040
- name: Add requirements
4141
run: python -m pip install --upgrade pip wheel setuptools
42-
42+
4343
- name: Build and install
4444
run: pip install --verbose .[test]
45-
45+
4646
- name: Test import
4747
run: python -c "import pylibbpf; print('Import successful')"
48-
48+
4949
- name: Test
5050
run: python -m pytest -v
51-

.github/workflows/wheels.yml

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ jobs:
1818
- uses: actions/checkout@v5
1919
with:
2020
submodules: true
21-
21+
2222
- name: Build SDist
2323
run: pipx run build --sdist
24-
24+
2525
- name: Check metadata
2626
run: pipx run twine check dist/*
27-
27+
2828
- uses: actions/upload-artifact@v4
2929
with:
3030
name: cibw-sdist
@@ -36,48 +36,32 @@ jobs:
3636
strategy:
3737
fail-fast: false
3838
matrix:
39-
# Build for both x86_64 and aarch64
40-
arch: [x86_64, aarch64]
41-
39+
arch: [x86_64]
40+
4241
steps:
4342
- uses: actions/checkout@v5
4443
with:
4544
submodules: true
46-
47-
# Set up QEMU for aarch64 emulation
48-
- name: Set up QEMU
49-
if: matrix.arch == 'aarch64'
50-
uses: docker/setup-qemu-action@v3
51-
with:
52-
platforms: arm64
53-
45+
5446
- name: Build wheels
5547
uses: pypa/[email protected]
5648
env:
57-
# Only build for Linux
5849
CIBW_PLATFORM: linux
5950
CIBW_ARCHS_LINUX: ${{ matrix.arch }}
60-
61-
# Python versions to build for
62-
CIBW_BUILD: "cp38-* cp39-* cp310-* cp311-* cp312-*"
63-
CIBW_SKIP: "*-musllinux*" # Skip musl builds, focus on glibc
64-
65-
# Install system dependencies before building
66-
CIBW_BEFORE_ALL_LINUX: >
67-
yum install -y epel-release &&
68-
yum install -y libbpf-devel kernel-headers ||
69-
(apt-get update && apt-get install -y libbpf-dev linux-headers-generic)
70-
71-
# Test the built wheels
51+
CIBW_BUILD: "cp38-* cp311-*"
52+
CIBW_SKIP: "*-musllinux*"
7253
CIBW_TEST_COMMAND: "python -c 'import pylibbpf; print(f\"pylibbpf {pylibbpf.__version__} imported successfully\")'"
73-
74-
# Skip testing on emulated architectures (too slow)
7554
CIBW_TEST_SKIP: "*-linux_aarch64"
76-
55+
56+
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
57+
58+
CIBW_BEFORE_ALL_LINUX: |
59+
dnf install -y elfutils-libelf-devel zlib-devel
60+
7761
- name: Verify clean directory
7862
run: git diff --exit-code
7963
shell: bash
80-
64+
8165
- name: Upload wheels
8266
uses: actions/upload-artifact@v4
8367
with:
@@ -90,20 +74,18 @@ jobs:
9074
runs-on: ubuntu-latest
9175
if: github.event_name == 'release' && github.event.action == 'published'
9276
permissions:
93-
# IMPORTANT: this permission is mandatory for trusted publishing
9477
id-token: write
9578
environment:
9679
name: pypi
97-
# url: https://pypi.org/project/pylibbpf/${{ github.event.release.name }}
98-
80+
9981
steps:
10082
- name: Download all artifacts
10183
uses: actions/download-artifact@v5
10284
with:
10385
pattern: cibw-*
10486
path: dist
10587
merge-multiple: true
106-
88+
10789
- name: Publish to PyPI
10890
uses: pypa/gh-action-pypi-publish@release/v1
10991
with:

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
path = pybind11
33
url = https://github.com/pybind/pybind11.git
44
branch = master
5+
[submodule "libbpf"]
6+
path = libbpf
7+
url = https://github.com/libbpf/libbpf.git

CMakeLists.txt

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,51 @@ project(pylibbpf)
44
add_subdirectory(pybind11)
55
pybind11_add_module(pylibbpf src/main.cpp)
66

7+
# Build vendored libbpf
8+
include(ExternalProject)
9+
ExternalProject_Add(
10+
libbpf
11+
PREFIX libbpf
12+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libbpf/src
13+
CONFIGURE_COMMAND ""
14+
BUILD_COMMAND
15+
make BUILD_STATIC_ONLY=1 OBJDIR=${CMAKE_CURRENT_BINARY_DIR}/libbpf/libbpf
16+
DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/libbpf INCLUDEDIR= LIBDIR= UAPIDIR=
17+
install install_uapi_headers
18+
BUILD_IN_SOURCE TRUE
19+
INSTALL_COMMAND ""
20+
STEP_TARGETS build)
21+
22+
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
23+
set(ARCH "x86")
24+
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
25+
set(ARCH "arm")
26+
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
27+
set(ARCH "arm64")
28+
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "ppc64le")
29+
set(ARCH "powerpc")
30+
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips")
31+
set(ARCH "mips")
32+
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "riscv64")
33+
set(ARCH "riscv")
34+
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "loongarch64")
35+
set(ARCH "loongarch")
36+
endif()
37+
38+
set(LIBBPF_INCLUDE_DIRS
39+
${CMAKE_CURRENT_BINARY_DIR}/libbpf
40+
${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include
41+
${CMAKE_CURRENT_BINARY_DIR}/libbpf/usr/include)
42+
set(LIBBPF_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/libbpf/libbpf.a)
43+
744
# EXAMPLE_VERSION_INFO is defined by setup.py and passed into the C++ code as a
845
# define (VERSION_INFO) here.
946
target_compile_definitions(pylibbpf
10-
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO})
47+
PRIVATE VERSION_INFO=${PYLIBBPF_VERSION_INFO})
48+
49+
# ensure build order
50+
add_dependencies(pylibbpf libbpf)
51+
52+
# headers + linking
53+
target_include_directories(pylibbpf PRIVATE ${LIBBPF_INCLUDE_DIRS})
54+
target_link_libraries(pylibbpf PRIVATE ${LIBBPF_LIBRARIES})

README.md

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
1-
# cmake_example for pybind11
2-
3-
An example [pybind11](https://github.com/pybind/pybind11) module built with a
4-
CMake-based build system. This is useful for C++ codebases that have an
5-
existing CMake project structure. This is being replaced by
6-
[`scikit_build_example`](https://github.com/pybind/scikit_build_example), which uses
7-
[scikit-build-core][], which is designed to allow Python
8-
packages to be driven from CMake without depending on setuptools. The approach here has
9-
some trade-offs not present in a pure setuptools build (see
10-
[`python_example`](https://github.com/pybind/python_example)) or scikit-build-core. Python 3.7+ required;
11-
see the commit history for older versions of Python.
12-
13-
Problems vs. scikit-build-core based example:
14-
15-
- You have to manually copy fixes/additions when they get added to this example (like when Apple Silicon support was added)
16-
- Modern editable installs are not supported (scikit-build-core doesn't support them either yet, but probably will soon)
17-
- You are depending on setuptools, which can and will change
18-
- You are stuck with an all-or-nothing approach to adding cmake/ninja via wheels (scikit-build-core adds these only as needed, so it can be used on BSD, Cygwin, Pyodide, Android, etc)
19-
- You are stuck with whatever CMake ships with (scikit-build-core backports FindPython for you)
1+
# Py-libbpf
2+
This library provides Python bindings for libbpf on Linux to make loading of eBPF object files easier. This is meant to
3+
be used along with `pythonbpf`, the eBPF Python DSL compiler. This library makes it possible to attach these programs to
4+
events in the kernel right from inside Python.
205

6+
# Warning
7+
IN DEVELOPMENT. DO NOT USE.
218

229
## Prerequisites
2310

@@ -32,40 +19,12 @@ Just clone this repository and pip install. Note the `--recursive` option which
3219
needed for the pybind11 submodule:
3320

3421
```bash
35-
git clone --recursive https://github.com/pybind/cmake_example.git
36-
pip install ./cmake_example
22+
git clone --recursive https://github.com/varun-r-mallya/pylibbpf.git
23+
pip install .
3724
```
3825

3926
With the `setup.py` file included in this example, the `pip install` command will
4027
invoke CMake and build the pybind11 module as specified in `CMakeLists.txt`.
4128

42-
43-
4429
## Building the documentation
45-
46-
Documentation for the example project is generated using Sphinx. Sphinx has the
47-
ability to automatically inspect the signatures and documentation strings in
48-
the extension module to generate beautiful documentation in a variety formats.
49-
The following command generates HTML-based reference documentation; for other
50-
formats please refer to the Sphinx manual:
51-
52-
- `cd cmake_example/docs`
53-
- `make html`
54-
55-
56-
## License
57-
58-
Pybind11 is provided under a BSD-style license that can be found in the LICENSE
59-
file. By using, distributing, or contributing to this project, you agree to the
60-
terms and conditions of this license.
61-
62-
63-
## Test call
64-
65-
```python
66-
import cmake_example
67-
cmake_example.add(1, 2)
68-
```
69-
70-
[`cibuildwheel`]: https://cibuildwheel.readthedocs.io
71-
[scikit-build-core]: https://github.com/scikit-build/scikit-build-core
30+
The documentation here is still boilerplate.

libbpf

Submodule libbpf added at 45e8934

pyproject.toml

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ authors = [
1616
{ name = "varun-r-mallya", email = "[email protected]" }
1717
]
1818
readme = "README.md"
19-
license = { text = "Apache-2.0" }
19+
license = { file = "LICENSE" }
2020
requires-python = ">=3.8"
2121
classifiers = [
2222
"Development Status :: 3 - Alpha",
2323
"Intended Audience :: Developers",
24-
"License :: OSI Approved :: Apache Software License",
2524
"Operating System :: POSIX :: Linux",
2625
"Programming Language :: Python :: 3",
2726
"Programming Language :: Python :: 3.8",
@@ -64,31 +63,6 @@ filterwarnings = [
6463
]
6564
testpaths = ["tests"]
6665

67-
[tool.cibuildwheel]
68-
build = ["cp38-*", "cp39-*", "cp310-*", "cp311-*", "cp312-*"]
69-
skip = ["*-win32", "*-win_amd64", "*-macosx*", "pp*"]
70-
71-
# Build for both x86_64 and aarch64 on Linux
72-
archs = ["x86_64", "aarch64"]
73-
74-
# Linux-specific settings
75-
[tool.cibuildwheel.linux]
76-
before-all = [
77-
"yum install -y epel-release || apt-get update",
78-
"yum install -y libbpf-devel kernel-headers || apt-get install -y libbpf-dev linux-headers-generic",
79-
]
80-
81-
# Skip testing on emulated architectures (too slow)
82-
test-skip = ["*_aarch64", "*_arm64"]
83-
84-
# Test command for supported architectures
85-
test-command = "pytest {project}/tests"
86-
test-extras = ["test"]
87-
88-
before-build = "rm -rf {project}/build"
89-
90-
environment = { CMAKE_BUILD_PARALLEL_LEVEL = "2" }
91-
9266
[tool.ruff]
9367
target-version = "py38"
9468
line-length = 88

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import re
32
import subprocess
43
import sys
54
from pathlib import Path
@@ -50,7 +49,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
5049
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
5150
]
5251
build_args = []
53-
52+
5453
# Adding CMake arguments set as environment variable
5554
# (needed e.g. to build for ARM OSx on conda-forge)
5655
if "CMAKE_ARGS" in os.environ:
@@ -137,7 +136,6 @@ def build_extension(self, ext: CMakeExtension) -> None:
137136
classifiers=[
138137
"Development Status :: 3 - Alpha",
139138
"Intended Audience :: Developers",
140-
"License :: OSI Approved :: Apache Software License",
141139
"Operating System :: POSIX :: Linux",
142140
"Programming Language :: Python :: 3",
143141
"Programming Language :: Python :: 3.8",

src/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#include <pybind11/pybind11.h>
2-
32
#define STRINGIFY(x) #x
43
#define MACRO_STRINGIFY(x) STRINGIFY(x)
54

5+
extern "C" {
6+
#include "bpf/libbpf.h"
7+
}
8+
69
int add(int i, int j) {
710
return i + j;
811
}

tests/test_basic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pylibbpf as m
22

3+
34
def test_main():
45
assert m.__version__ == "0.0.1"
56
assert m.add(1, 2) == 3

0 commit comments

Comments
 (0)