From 509eba589df52d3c9ac1adc1ecd1028419b14647 Mon Sep 17 00:00:00 2001 From: Sergey Kacheev Date: Tue, 21 Apr 2026 19:59:33 +0300 Subject: [PATCH] fix: use static build for pdump_cp --- .github/workflows/Dockerfile.base | 2 +- .github/workflows/Dockerfile.base.dev | 1 + .github/workflows/build.yml | 2 +- .github/workflows/fuzz-test.yml | 2 +- .gitmodules | 3 ++ modules/pdump/api/meson.build | 75 ++++++++++++++++++++------- modules/pdump/controlplane/ffi.go | 3 +- subprojects/libpcap | 1 + 8 files changed, 66 insertions(+), 23 deletions(-) create mode 160000 subprojects/libpcap diff --git a/.github/workflows/Dockerfile.base b/.github/workflows/Dockerfile.base index 1ab3c26e1..7d0309912 100644 --- a/.github/workflows/Dockerfile.base +++ b/.github/workflows/Dockerfile.base @@ -3,5 +3,5 @@ FROM ubuntu:24.04 ENV DEBIAN_FRONTEND noninteractive RUN apt update -y -RUN apt install -y meson clang +RUN apt install -y meson clang cmake RUN apt install -y python3-pyelftools libnuma-dev libpcap-dev git diff --git a/.github/workflows/Dockerfile.base.dev b/.github/workflows/Dockerfile.base.dev index 286d1f252..56c2b0b06 100644 --- a/.github/workflows/Dockerfile.base.dev +++ b/.github/workflows/Dockerfile.base.dev @@ -15,6 +15,7 @@ ARG PROTOC_GEN_GO_GRPC_VERSION=latest RUN apt-get update -y && apt-get install -y \ meson \ + cmake \ clang \ clang-format-19 \ clang-tidy-19 \ diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eb24f5920..60a464a92 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -73,7 +73,7 @@ jobs: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}- - uses: awalsh128/cache-apt-pkgs-action@latest with: - packages: meson clang python3-pyelftools libnuma-dev libpcap-dev git protobuf-compiler jq clang-tidy-19 + packages: meson clang cmake python3-pyelftools libnuma-dev libpcap-dev git protobuf-compiler jq clang-tidy-19 version: 1.1 - name: Install LLVM 19 toolchain diff --git a/.github/workflows/fuzz-test.yml b/.github/workflows/fuzz-test.yml index cc840fecb..9bcd133fc 100644 --- a/.github/workflows/fuzz-test.yml +++ b/.github/workflows/fuzz-test.yml @@ -24,7 +24,7 @@ jobs: - uses: awalsh128/cache-apt-pkgs-action@latest with: - packages: meson clang python3-pyelftools libnuma-dev libpcap-dev git protobuf-compiler jq + packages: meson clang cmake python3-pyelftools libnuma-dev libpcap-dev git protobuf-compiler jq version: 1.1 - uses: actions/checkout@v4 diff --git a/.gitmodules b/.gitmodules index 525d2aef5..1060e1047 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "subprojects/dpdk"] path = subprojects/dpdk url = https://github.com/yanet-platform/dpdk +[submodule "subprojects/libpcap"] + path = subprojects/libpcap + url = https://github.com/the-tcpdump-group/libpcap.git diff --git a/modules/pdump/api/meson.build b/modules/pdump/api/meson.build index 014e3656c..febbad903 100644 --- a/modules/pdump/api/meson.build +++ b/modules/pdump/api/meson.build @@ -1,38 +1,75 @@ -cp_dependencies = [ - lib_common_dep, - lib_config_cp_dep, -] +pdump_dataplane_inc = include_directories('../dataplane') -ext_deps = ['rte_bpf'] +# libpcap: git submodule at subprojects/libpcap, built with CMake into this +# module's build dir (Meson's cmake.subproject hits a dependency cycle in upstream libpcap). +fs = import('fs') +cmake = find_program('cmake', required: true, version: '>=3.5') +pcap_src_root = meson.project_source_root() / 'subprojects' / 'libpcap' +if not fs.exists(pcap_src_root / 'CMakeLists.txt') + error( + 'pdump: missing libpcap sources at subprojects/libpcap. Initialize git submodules: git submodule update --init --recursive', + ) +endif -foreach e:ext_deps - cp_dependencies += libdpdk.get_variable('static_' + e) -endforeach +pcap_cmake_build = meson.current_build_dir() / 'external' / 'libpcap-cmake' +pcap_prefix = meson.current_build_dir() / 'external' / 'libpcap-install' +libpcap_a = pcap_prefix / 'lib' / 'libpcap.a' -pdump_cp_link_deps = [] -foreach l:libdpdk.get_variable('dpdk_static_libraries') - if l.name() in ext_deps - pdump_cp_link_deps += l - endif -endforeach +pcap_cmake_args = [ + '-S', pcap_src_root, + '-B', pcap_cmake_build, + '-G', 'Ninja', + '-DCMAKE_INSTALL_PREFIX=' + pcap_prefix, + '-DCMAKE_BUILD_TYPE=' + (get_option('buildtype') == 'debug' ? 'Debug' : 'RelWithDebInfo'), + '-DBUILD_SHARED_LIBS=OFF', + '-DDISABLE_BLUETOOTH=ON', + '-DDISABLE_NETMAP=ON', + '-DDISABLE_DPDK=ON', + '-DDISABLE_DBUS=ON', + '-DDISABLE_RDMA=ON', + '-DDISABLE_DAG=ON', + '-DDISABLE_SEPTEL=ON', + '-DDISABLE_SNF=ON', + '-DDISABLE_TC=ON', + '-DCMAKE_C_FLAGS=' + ' '.join(yanet_c_args), + '-DCMAKE_EXE_LINKER_FLAGS=' + ' '.join(yanet_link_args), + '-DCMAKE_SHARED_LINKER_FLAGS=' + ' '.join(yanet_link_args), + '-DCMAKE_MODULE_LINKER_FLAGS=' + ' '.join(yanet_link_args), +] +if host_machine.system() == 'linux' + pcap_cmake_args += ['-DBUILD_WITH_LIBNL=OFF', '-DDISABLE_LINUX_USBMON=ON'] +endif -pdump_dataplane_inc = include_directories('../dataplane') +if not fs.exists(libpcap_a) + message('[pdump] Configuring libpcap with CMake in ' + pcap_cmake_build) + run_command(cmake, pcap_cmake_args, check: true) + message('[pdump] Building and installing libpcap to ' + pcap_prefix) + run_command(cmake, '--build', pcap_cmake_build, '--target', 'install', check: true) +else + message('[pdump] Reusing built libpcap: ' + libpcap_a) +endif -api_sources = files( - 'controlplane.c', +pcap_libdir = pcap_prefix / 'lib' +pcap_incdir = pcap_prefix / 'include' +message('[pdump] Linking pdump_cp with static libpcap from ' + pcap_libdir) +libpcap_dep = declare_dependency( + compile_args: ['-I' + pcap_incdir], + dependencies: cc.find_library('pcap', dirs: pcap_libdir, static: true), ) +cp_dependencies = [lib_common_dep, lib_config_cp_dep, libdpdk_dep, libpcap_dep] +api_sources = files('controlplane.c') + lib_pdump_cp = static_library( 'pdump_cp', api_sources, c_args: yanet_c_args, link_args: yanet_link_args, - link_whole: pdump_cp_link_deps, dependencies: cp_dependencies, include_directories: [yanet_rootdir, pdump_dataplane_inc], install: false, ) - lib_pdump_cp_dep = declare_dependency( link_with: lib_pdump_cp, + dependencies: cp_dependencies, ) diff --git a/modules/pdump/controlplane/ffi.go b/modules/pdump/controlplane/ffi.go index 4ef7f64c3..0480da153 100644 --- a/modules/pdump/controlplane/ffi.go +++ b/modules/pdump/controlplane/ffi.go @@ -1,8 +1,9 @@ package pdump //#cgo CFLAGS: -I../../../ -I../dataplane +//#cgo CFLAGS: -I../../../build/modules/pdump/api/external/libpcap-install/include //#cgo LDFLAGS: -L../../../build/modules/pdump/api -lpdump_cp -//#cgo LDFLAGS: -lpcap +//#cgo LDFLAGS: -L../../../build/modules/pdump/api/external/libpcap-install/lib -Wl,-Bstatic -lpcap -Wl,-Bdynamic // //#include //#include "modules/pdump/api/controlplane.h" diff --git a/subprojects/libpcap b/subprojects/libpcap new file mode 160000 index 000000000..bbcbc9174 --- /dev/null +++ b/subprojects/libpcap @@ -0,0 +1 @@ +Subproject commit bbcbc9174df3298a854daee2b3e666a4b6e5383a