Skip to content

Commit 6eca071

Browse files
Bundle libbpf and switch to vendored build
Signed-off-by: varun-r-mallya <[email protected]>
1 parent 761bf2d commit 6eca071

File tree

7 files changed

+44
-40
lines changed

7 files changed

+44
-40
lines changed

.github/workflows/pip.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
sudo apt-get update
3333
sudo apt-get install -y \
3434
libbpf-dev \
35+
libelf-dev \
3536
linux-headers-generic \
3637
build-essential \
3738
cmake \

.github/workflows/wheels.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ jobs:
4444
with:
4545
submodules: true
4646

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-
5447
- name: Build wheels
5548
uses: pypa/[email protected]
5649
env:
@@ -59,14 +52,13 @@ jobs:
5952
CIBW_ARCHS_LINUX: ${{ matrix.arch }}
6053

6154
# Python versions to build for
62-
CIBW_BUILD: "cp38-* cp39-* cp310-* cp311-* cp312-*"
55+
CIBW_BUILD: "cp38-* cp311-*"
6356
CIBW_SKIP: "*-musllinux*" # Skip musl builds, focus on glibc
6457

65-
# Install system dependencies before building
58+
# Install minimal system dependencies before building
6659
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)
60+
yum install -y make gcc-c++ kernel-headers ||
61+
(apt-get update && apt-get install -y build-essential linux-headers-generic)
7062
7163
# Test the built wheels
7264
CIBW_TEST_COMMAND: "python -c 'import pylibbpf; print(f\"pylibbpf {pylibbpf.__version__} imported successfully\")'"

.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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,40 @@ 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 ${CMAKE_CURRENT_BINARY_DIR}/libbpf)
39+
set(LIBBPF_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/libbpf/libbpf.a)
40+
741
# EXAMPLE_VERSION_INFO is defined by setup.py and passed into the C++ code as a
842
# define (VERSION_INFO) here.
943
target_compile_definitions(pylibbpf

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 = "Apache-2.0"
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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ def build_extension(self, ext: CMakeExtension) -> None:
136136
classifiers=[
137137
"Development Status :: 3 - Alpha",
138138
"Intended Audience :: Developers",
139-
"License :: OSI Approved :: Apache Software License",
140139
"Operating System :: POSIX :: Linux",
141140
"Programming Language :: Python :: 3",
142141
"Programming Language :: Python :: 3.8",

0 commit comments

Comments
 (0)