Bundle libbpf and switch to vendored build

Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>
This commit is contained in:
2025-09-21 00:12:32 +05:30
parent 761bf2d660
commit 6eca0716d8
7 changed files with 44 additions and 40 deletions

View File

@ -32,6 +32,7 @@ jobs:
sudo apt-get update sudo apt-get update
sudo apt-get install -y \ sudo apt-get install -y \
libbpf-dev \ libbpf-dev \
libelf-dev \
linux-headers-generic \ linux-headers-generic \
build-essential \ build-essential \
cmake \ cmake \

View File

@ -44,13 +44,6 @@ jobs:
with: with:
submodules: true submodules: true
# Set up QEMU for aarch64 emulation
- name: Set up QEMU
if: matrix.arch == 'aarch64'
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Build wheels - name: Build wheels
uses: pypa/cibuildwheel@v2.17 uses: pypa/cibuildwheel@v2.17
env: env:
@ -59,14 +52,13 @@ jobs:
CIBW_ARCHS_LINUX: ${{ matrix.arch }} CIBW_ARCHS_LINUX: ${{ matrix.arch }}
# Python versions to build for # Python versions to build for
CIBW_BUILD: "cp38-* cp39-* cp310-* cp311-* cp312-*" CIBW_BUILD: "cp38-* cp311-*"
CIBW_SKIP: "*-musllinux*" # Skip musl builds, focus on glibc CIBW_SKIP: "*-musllinux*" # Skip musl builds, focus on glibc
# Install system dependencies before building # Install minimal system dependencies before building
CIBW_BEFORE_ALL_LINUX: > CIBW_BEFORE_ALL_LINUX: >
yum install -y epel-release && yum install -y make gcc-c++ kernel-headers ||
yum install -y libbpf-devel kernel-headers || (apt-get update && apt-get install -y build-essential linux-headers-generic)
(apt-get update && apt-get install -y libbpf-dev linux-headers-generic)
# Test the built wheels # Test the built wheels
CIBW_TEST_COMMAND: "python -c 'import pylibbpf; print(f\"pylibbpf {pylibbpf.__version__} imported successfully\")'" CIBW_TEST_COMMAND: "python -c 'import pylibbpf; print(f\"pylibbpf {pylibbpf.__version__} imported successfully\")'"

3
.gitmodules vendored
View File

@ -2,3 +2,6 @@
path = pybind11 path = pybind11
url = https://github.com/pybind/pybind11.git url = https://github.com/pybind/pybind11.git
branch = master branch = master
[submodule "libbpf"]
path = libbpf
url = https://github.com/libbpf/libbpf.git

View File

@ -4,6 +4,40 @@ project(pylibbpf)
add_subdirectory(pybind11) add_subdirectory(pybind11)
pybind11_add_module(pylibbpf src/main.cpp) pybind11_add_module(pylibbpf src/main.cpp)
# Build vendored libbpf
include(ExternalProject)
ExternalProject_Add(
libbpf
PREFIX libbpf
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libbpf/src
CONFIGURE_COMMAND ""
BUILD_COMMAND
make BUILD_STATIC_ONLY=1 OBJDIR=${CMAKE_CURRENT_BINARY_DIR}/libbpf/libbpf
DESTDIR=${CMAKE_CURRENT_BINARY_DIR}/libbpf INCLUDEDIR= LIBDIR= UAPIDIR=
install install_uapi_headers
BUILD_IN_SOURCE TRUE
INSTALL_COMMAND ""
STEP_TARGETS build)
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
set(ARCH "x86")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
set(ARCH "arm")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
set(ARCH "arm64")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "ppc64le")
set(ARCH "powerpc")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips")
set(ARCH "mips")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "riscv64")
set(ARCH "riscv")
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "loongarch64")
set(ARCH "loongarch")
endif()
set(LIBBPF_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/libbpf)
set(LIBBPF_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/libbpf/libbpf.a)
# EXAMPLE_VERSION_INFO is defined by setup.py and passed into the C++ code as a # EXAMPLE_VERSION_INFO is defined by setup.py and passed into the C++ code as a
# define (VERSION_INFO) here. # define (VERSION_INFO) here.
target_compile_definitions(pylibbpf target_compile_definitions(pylibbpf

1
libbpf Submodule

Submodule libbpf added at 45e89348ec

View File

@ -16,12 +16,11 @@ authors = [
{ name = "varun-r-mallya", email = "varunrmallya@gmail.com" } { name = "varun-r-mallya", email = "varunrmallya@gmail.com" }
] ]
readme = "README.md" readme = "README.md"
license = { text = "Apache-2.0" } license = "Apache-2.0"
requires-python = ">=3.8" requires-python = ">=3.8"
classifiers = [ classifiers = [
"Development Status :: 3 - Alpha", "Development Status :: 3 - Alpha",
"Intended Audience :: Developers", "Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: POSIX :: Linux", "Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3", "Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.8",
@ -64,31 +63,6 @@ filterwarnings = [
] ]
testpaths = ["tests"] testpaths = ["tests"]
[tool.cibuildwheel]
build = ["cp38-*", "cp39-*", "cp310-*", "cp311-*", "cp312-*"]
skip = ["*-win32", "*-win_amd64", "*-macosx*", "pp*"]
# Build for both x86_64 and aarch64 on Linux
archs = ["x86_64", "aarch64"]
# Linux-specific settings
[tool.cibuildwheel.linux]
before-all = [
"yum install -y epel-release || apt-get update",
"yum install -y libbpf-devel kernel-headers || apt-get install -y libbpf-dev linux-headers-generic",
]
# Skip testing on emulated architectures (too slow)
test-skip = ["*_aarch64", "*_arm64"]
# Test command for supported architectures
test-command = "pytest {project}/tests"
test-extras = ["test"]
before-build = "rm -rf {project}/build"
environment = { CMAKE_BUILD_PARALLEL_LEVEL = "2" }
[tool.ruff] [tool.ruff]
target-version = "py38" target-version = "py38"
line-length = 88 line-length = 88

View File

@ -136,7 +136,6 @@ setup(
classifiers=[ classifiers=[
"Development Status :: 3 - Alpha", "Development Status :: 3 - Alpha",
"Intended Audience :: Developers", "Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: POSIX :: Linux", "Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3", "Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.8",