Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libxdp added #26503

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions recipes/libbpf/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"1.5.0":
url: "https://github.com/libbpf/libbpf/archive/v1.5.0.tar.gz"
sha256: "53492aff6dd47e4da04ef5e672d753b9743848bdb38e9d90eafbe190b7983c44"
"1.3.0":
url: "https://github.com/libbpf/libbpf/archive/v1.3.0.tar.gz"
sha256: "11db86acd627e468bc48b7258c1130aba41a12c4d364f78e184fd2f5a913d861"
Expand Down
9 changes: 9 additions & 0 deletions recipes/libbpf/all/test_package/example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "bpf/libbpf.h"

int main(int argc, char** argv)
{
const char buffer[1] = { '\0' };
struct bpf_object* obj = bpf_object__open_mem(buffer, 1, NULL);
bpf_object__close(obj);
return 0;
}
5 changes: 5 additions & 0 deletions recipes/libxdp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sources:
"1.5.1":
url: "https://github.com/xdp-project/xdp-tools/archive/v1.5.1.tar.gz"
sha256: "aa1119a296412dbf19b50d4250a855ca7a7c56fcfbe0a6c02cd10ab1798f5b75"

101 changes: 101 additions & 0 deletions recipes/libxdp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.env import Environment
from conan.tools.files import copy, get, rm, rmdir, chdir
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps, PkgConfigDeps
from conan.tools.layout import basic_layout
import os
import shutil

required_conan_version = ">=1.54.0"

class LibbpfConan(ConanFile):
name = "libxdp"
description = "XDP tools"
license = "BSD-2-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/xdp-project/xdp-tools"
topics = ("berkeley-packet-filter", "bpf", "ebpf", "xdp", "network", "tracing")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"customXskProg": ["ANY"],
}
default_options = {
"shared": False,
"fPIC": True,
"customXskProg": "",
}

exports_sources = "config.mk"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
self.requires("libbpf/1.5.0", transitive_headers=True, transitive_libs=True)

def validate(self):
if self.settings.os != "Linux":
raise ConanInvalidConfiguration(f"{self.ref} is only available on Linux")

def build_requirements(self):
self.tool_requires("make/4.3")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
copy(self, "config.mk", self.export_sources_folder, self.source_folder)

def generate(self):
tc = AutotoolsToolchain(self)
tc.make_args.extend([
"PREFIX={}".format(""),
"DESTDIR={}".format(self.package_folder),
"LIBSUBDIR={}".format("lib"),
])
tc.generate()

pkgdeps = PkgConfigDeps(self)
pkgdeps.generate()

autotoolsdeps = AutotoolsDeps(self)
autotoolsdeps.generate()

def build(self):
if self.options.customXskProg != "":
dest = os.path.join(self.source_folder, "lib/libxdp/xsk_def_xdp_prog.c")
shutil.copyfile(str(self.options.customXskProg), dest)
self.output.info(f"custom prog: {self.options.customXskProg} -> {dest}")
env = Environment()
env.define("BPF_CFLAGS", f'-g -I{self.dependencies["libbpf"].package_folder}/include')
envvars = env.vars(self, scope="build")
with envvars.apply():
autotools = Autotools(self)
with chdir(self, os.path.join(self.source_folder, "lib")):
autotools.make(target="libxdp")

def package(self):
with chdir(self, os.path.join(self.source_folder, "lib")):
autotools = Autotools(self)
autotools.install(target="libxdp_install")
if self.options.shared:
rm(self, "libxdp.a", os.path.join(self.package_folder, "lib"))
else:
rm(self, "libxdp.so*", os.path.join(self.package_folder, "lib"))

def package_info(self):
self.cpp_info.libs = ["xdp"]

66 changes: 66 additions & 0 deletions recipes/libxdp/all/config.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Generated config
# user can control verbosity similar to kernel builds (e.g., V=1)
ifeq ("$(origin V)", "command line")
VERBOSE = $(V)
endif
ifndef VERBOSE
VERBOSE = 0
endif
ifeq ($(VERBOSE),1)
Q =
else
Q = @
endif
ifeq ($(VERBOSE),0)
MAKEFLAGS += --no-print-directory
endif


ifeq ($(VERBOSE), 0)
QUIET_CC = @echo ' CC '$@;
QUIET_CLANG = @echo ' CLANG '$@;
QUIET_LLC = @echo ' LLC '$@;
QUIET_LINK = @echo ' LINK '$@;
QUIET_INSTALL = @echo ' INSTALL '$@;
QUIET_M4 = @echo ' M4 '$@;
QUIET_GEN = @echo ' GEN '$@;
endif
PRODUCTION:=0
DYNAMIC_LIBXDP:=0
MAX_DISPATCHER_ACTIONS:=10
BPF_TARGET:=bpf
PKG_CONFIG:=pkg-config
CC:=gcc
OBJCOPY:=objcopy
CLANG:=clang
LLC:=llc
M4:=m4
EMACS:=emacs
ARCH_INCLUDES:=
READELF:=readelf
BPFTOOL:=bpftool
HAVE_FEATURES+=LIBBPF_PERF_BUFFER__CONSUME
HAVE_FEATURES+=LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID
HAVE_FEATURES+=LIBBPF_BTF__TYPE_CNT
HAVE_FEATURES+=LIBBPF_BPF_OBJECT__NEXT_MAP
HAVE_FEATURES+=LIBBPF_BPF_OBJECT__NEXT_PROGRAM
HAVE_FEATURES+=LIBBPF_BPF_PROGRAM__INSN_CNT
HAVE_FEATURES+=LIBBPF_BPF_PROGRAM__TYPE
HAVE_FEATURES+=LIBBPF_BPF_PROGRAM__FLAGS
HAVE_FEATURES+=LIBBPF_BPF_PROGRAM__EXPECTED_ATTACH_TYPE
HAVE_FEATURES+=LIBBPF_BPF_MAP_CREATE
HAVE_FEATURES+=LIBBPF_PERF_BUFFER__NEW_RAW
HAVE_FEATURES+=LIBBPF_BPF_XDP_ATTACH
HAVE_FEATURES+=LIBBPF_BPF_MAP__SET_AUTOCREATE
HAVE_FEATURES+=LIBBPF_BPF_PROG_TEST_RUN_OPTS
HAVE_FEATURES+=LIBBPF_BPF_XDP_QUERY
HAVE_FEATURES += SECURE_GETENV
SYSTEM_LIBBPF:=n
LIBBPF_VERSION=1.5.0
OBJECT_LIBBPF =
HAVE_ZLIB:=y
CFLAGS += -DHAVE_ZLIB
LDLIBS += -lz
HAVE_ELF:=y
CFLAGS += -DHAVE_ELF
LDLIBS += -lelf
7 changes: 7 additions & 0 deletions recipes/libxdp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

find_package(libxdp REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} libxdp::libxdp)
9 changes: 9 additions & 0 deletions recipes/libxdp/all/test_package/CMakeUserPresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 4,
"vendor": {
"conan": {}
},
"include": [
"build/gcc-13-x86_64-gnu17-release/generators/CMakePresets.json"
]
}
26 changes: 26 additions & 0 deletions recipes/libxdp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
7 changes: 7 additions & 0 deletions recipes/libxdp/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <cstdlib>
#include <iostream>
#include <xdp/xsk.h>

int main() {
return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/libxdp/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.5.1":
folder: all