diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml index cdb491f..7aaed3f 100644 --- a/.github/workflows/pip.yml +++ b/.github/workflows/pip.yml @@ -32,6 +32,7 @@ jobs: sudo apt-get update sudo apt-get install -y \ libbpf-dev \ + libelf-dev \ linux-headers-generic \ build-essential \ cmake \ diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 26a99e9..10b4148 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -44,13 +44,6 @@ jobs: with: 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 uses: pypa/cibuildwheel@v2.17 env: @@ -59,14 +52,13 @@ jobs: CIBW_ARCHS_LINUX: ${{ matrix.arch }} # 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 - # Install system dependencies before building + # Install minimal system dependencies before building CIBW_BEFORE_ALL_LINUX: > - yum install -y epel-release && - yum install -y libbpf-devel kernel-headers || - (apt-get update && apt-get install -y libbpf-dev linux-headers-generic) + yum install -y make gcc-c++ kernel-headers || + (apt-get update && apt-get install -y build-essential linux-headers-generic) # Test the built wheels CIBW_TEST_COMMAND: "python -c 'import pylibbpf; print(f\"pylibbpf {pylibbpf.__version__} imported successfully\")'" diff --git a/.gitmodules b/.gitmodules index ced1d11..1589533 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,6 @@ path = pybind11 url = https://github.com/pybind/pybind11.git branch = master +[submodule "libbpf"] + path = libbpf + url = https://github.com/libbpf/libbpf.git diff --git a/CMakeLists.txt b/CMakeLists.txt index c9b7c8b..8e1f679 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,40 @@ project(pylibbpf) add_subdirectory(pybind11) 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 # define (VERSION_INFO) here. target_compile_definitions(pylibbpf diff --git a/libbpf b/libbpf new file mode 160000 index 0000000..45e8934 --- /dev/null +++ b/libbpf @@ -0,0 +1 @@ +Subproject commit 45e89348ec74617c11cd5241ccd0ffc91dfd03c4 diff --git a/pyproject.toml b/pyproject.toml index 6bf40dc..602875f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,12 +16,11 @@ authors = [ { name = "varun-r-mallya", email = "varunrmallya@gmail.com" } ] readme = "README.md" -license = { text = "Apache-2.0" } +license = "Apache-2.0" requires-python = ">=3.8" classifiers = [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.8", @@ -64,31 +63,6 @@ filterwarnings = [ ] 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] target-version = "py38" line-length = 88 diff --git a/setup.py b/setup.py index 6e995a7..37e5302 100644 --- a/setup.py +++ b/setup.py @@ -136,7 +136,6 @@ setup( classifiers=[ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.8",