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

Build the libbpf library during the cmake configuration process #4166

Merged
merged 2 commits into from
Sep 28, 2023
Merged
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
24 changes: 11 additions & 13 deletions backends/ebpf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ if(NOT APPLE)
)
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
)
# Check if we have already built the libbpf library.
find_library(LIBBPF NAMES bpf HINTS "${CMAKE_CURRENT_SOURCE_DIR}/runtime/usr/lib64/")
if (NOT LIBBPF)
message("Building libbpf...")
execute_process(
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build_libbpf
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
endif()
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 @@ -120,9 +121,6 @@ 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
1 change: 1 addition & 0 deletions backends/ebpf/build_libbpf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def main() -> int:
mk_cmd += "BUILD_STATIC_ONLY=y "
mk_cmd += f"OBJDIR={libbpf_build_dir} "
mk_cmd += f"DESTDIR={libbpf_target_dir} "
mk_cmd += "EXTRA_CFLAGS=-fPIE"
result = testutils.exec_process(args=mk_cmd)
if result.returncode != testutils.SUCCESS:
testutils.log.error("Could not build libbpf")
Expand Down