Skip to content

Commit

Permalink
Pull the libbpf library with FetchContent instead of submodules and a…
Browse files Browse the repository at this point in the history
… script. (#3970)
  • Loading branch information
fruffy authored Aug 11, 2023
1 parent 9499498 commit 6a144da
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 20 deletions.
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
[submodule "backends/ebpf/runtime/contrib/libbpf"]
path = backends/ebpf/runtime/contrib/libbpf
url = https://github.com/libbpf/libbpf
ignore = dirty
36 changes: 32 additions & 4 deletions backends/ebpf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,34 @@
# limitations under the License.

# CMakefile for the EBPF P4-16 back-end.
# To be included in the main P4C compiler CMakefile

message(STATUS "Start configuring eBPF back end")
message(STATUS "Start configuring the eBPF back end")

if(NOT APPLE)
# Fetch and declare the libbpf library. Print out download state while setting up libbpf.
set(FETCHCONTENT_QUIET_PREV ${FETCHCONTENT_QUIET})
set(FETCHCONTENT_QUIET OFF)
fetchcontent_declare(
bpfrepo
URL https://github.com/libbpf/libbpf/archive/refs/tags/v1.2.2.tar.gz
URL_HASH SHA256=32b0c41eabfbbe8e0c8aea784d7495387ff9171b5a338480a8fbaceb9da8d5e5
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/runtime/contrib/libbpf
USES_TERMINAL_DOWNLOAD TRUE
GIT_PROGRESS TRUE
)
fetchcontent_makeavailable(bpfrepo)
set(FETCHCONTENT_QUIET ${FETCHCONTENT_QUIET_PREV})
# Build libbpf as necessary.
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/runtime/usr/lib64/libbpf.a
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build_libbpf
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Building libbpf..."
)
add_custom_target(genlibbpf ALL
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/runtime/usr/lib64/libbpf.a
)
message("Done with setting up libbpf for P4C.")
endif()

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.h.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/version.h" @ONLY)
Expand Down Expand Up @@ -95,6 +120,9 @@ set (P4C_EBPF_DIST_HEADERS p4include/ebpf_model.p4)
add_executable(p4c-ebpf ${P4C_EBPF_SRCS})
target_link_libraries (p4c-ebpf ${P4C_LIBRARIES} ${P4C_LIB_DEPS})
add_dependencies(p4c-ebpf ir-generated frontend)
if (NOT APPLE)
add_dependencies(p4c-ebpf genlibbpf)
endif()

install (TARGETS p4c-ebpf
RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY})
Expand Down Expand Up @@ -193,7 +221,7 @@ endif()
# check for the libbpf library
find_library(LIBBPF NAMES bpf HINTS "${CMAKE_CURRENT_SOURCE_DIR}/runtime/usr/lib64/")
if (LIBBPF)
message(STATUS "Found libbpf library")
message(STATUS "Found libbpf library at ${LIBBPF}")
else()
message(WARNING "Missing the libbpf dependency, disabling kernel tests."
" You can install libbpf by running './build_libbpf' in the "
Expand Down
6 changes: 0 additions & 6 deletions backends/ebpf/build_libbpf
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ def main() -> int:
libbpf_src_dir = libbpf_dir.joinpath("src")
libbpf_build_dir = libbpf_src_dir.joinpath("build")
libbpf_target_dir = FILE_DIR.joinpath("runtime")
# Download submodule if it has not been initialized yet
git_cmd = f"cd {FILE_DIR} && git submodule update --init {libbpf_dir}"
# We ignore the error that is thrown here
result = testutils.exec_process(args=git_cmd, timeout=20, shell=True)
if result.returncode != testutils.SUCCESS:
testutils.log.error("Could not initialize libbpf submodule")
# Create the libbpf build directory
testutils.check_and_create_dir(libbpf_build_dir)
# Build libbpf
Expand Down
1 change: 1 addition & 0 deletions backends/ebpf/runtime/contrib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libbpf
1 change: 0 additions & 1 deletion backends/ebpf/runtime/contrib/libbpf
Submodule libbpf deleted from 051a40
1 change: 1 addition & 0 deletions cmake/Linters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ file(
tools/*.py
)
list(FILTER P4C_PYTHON_LINT_LIST EXCLUDE REGEX "backends/p4tools/submodules")
list(FILTER P4C_PYTHON_LINT_LIST EXCLUDE REGEX "backends/ebpf/runtime/contrib/libbpf")
list(FILTER P4C_PYTHON_LINT_LIST EXCLUDE REGEX "tools/cpplint.py")

add_black_files(${P4C_SOURCE_DIR} "${P4C_PYTHON_LINT_LIST}")
Expand Down
5 changes: 0 additions & 5 deletions tools/ci-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ if [[ "${DISTRIB_RELEASE}" == "22.04" ]] ; then
sudo pip3 install --upgrade grpcio==1.51.1
fi

# Build libbpf for eBPF tests.
pushd ${P4C_DIR}
backends/ebpf/build_libbpf
popd

# ! ------ BEGIN PTF_EBPF -----------------------------------------------
function install_ptf_ebpf_test_deps() (
P4C_PTF_PACKAGES="gcc-multilib \
Expand Down

0 comments on commit 6a144da

Please sign in to comment.