From 849cb779573848a442756de6847e3ec991d37764 Mon Sep 17 00:00:00 2001 From: Fabian Ruffy <5960321+fruffy@users.noreply.github.com> Date: Fri, 28 Jul 2023 10:36:07 -0400 Subject: [PATCH] Update P4Runtime and use FetchContent instead of a submodule. (#4082) * Update P4Runtime and use FetchContent instead of a submodule. * Clean up control-plane and DPDK directory and Protobuf paths. * Update Bazel P4Runtime dependency. * Revert control path changes. * Try to prefix Bazel build. * Revert "Try to prefix Bazel build." This reverts commit 357898e58a1676ef266d025e43cfb53576dbcf63. --- .gitmodules | 3 --- BUILD.bazel | 4 +-- backends/dpdk/CMakeLists.txt | 13 +++++----- .../control-plane/bfruntime_arch_handler.h | 2 +- backends/dpdk/control-plane/bfruntime_ext.h | 3 ++- bazel/p4c_deps.bzl | 2 +- control-plane/CMakeLists.txt | 25 +++++++++++++++++-- control-plane/p4runtime | 1 - control-plane/typeSpecConverter.h | 2 +- test/gtest/p4runtime.cpp | 2 +- 10 files changed, 38 insertions(+), 19 deletions(-) delete mode 160000 control-plane/p4runtime diff --git a/.gitmodules b/.gitmodules index ab809da1b00..36f09edf377 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,9 +2,6 @@ path = test/frameworks/gtest url = https://github.com/google/googletest.git ignored = untracked -[submodule "control-plane/p4runtime"] - path = control-plane/p4runtime - url = https://github.com/p4lang/p4runtime.git [submodule "backends/ebpf/runtime/contrib/libbpf"] path = backends/ebpf/runtime/contrib/libbpf url = https://github.com/libbpf/libbpf diff --git a/BUILD.bazel b/BUILD.bazel index 14266209bf7..869aa3bc3cb 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -280,14 +280,14 @@ cc_binary( genrule( name = "dest_dir_dpdk", srcs = ["backends/dpdk/control-plane/proto/p4info.proto"], - outs = ["p4/config/dpdk/p4info.proto"], + outs = ["backends/dpdk/p4/config/p4info.proto"], cmd = "mkdir -p p4/config/dpdk; cp $(SRCS) $(OUTS)", visibility = ["//visibility:private"], ) proto_library( name = "p4info_dpdk_proto", - srcs = ["p4/config/dpdk/p4info.proto"], + srcs = ["backends/dpdk/p4/config/p4info.proto"], deps = [ "@com_google_protobuf//:any_proto", "@com_google_protobuf//:descriptor_proto", diff --git a/backends/dpdk/CMakeLists.txt b/backends/dpdk/CMakeLists.txt index d922bf30db9..a05c97aca16 100644 --- a/backends/dpdk/CMakeLists.txt +++ b/backends/dpdk/CMakeLists.txt @@ -21,8 +21,8 @@ include_directories(${P4C_BINARY_DIR}/control-plane) ################ Proto set (DPDK_P4RUNTIME_DIR ${CMAKE_CURRENT_SOURCE_DIR}/control-plane/proto) set (DPDK_P4RUNTIME_INFO_PROTO ${DPDK_P4RUNTIME_DIR}/p4info.proto) -set (DPDK_P4RUNTIME_INFO_GEN_SRCS ${P4C_BINARY_DIR}/p4/config/dpdk/p4info.pb.cc) -set (DPDK_P4RUNTIME_INFO_GEN_HDRS ${P4C_BINARY_DIR}/p4/config/dpdk/p4info.pb.h) +set (DPDK_P4RUNTIME_INFO_GEN_SRCS ${CMAKE_CURRENT_BINARY_DIR}/p4/config/p4info.pb.cc) +set (DPDK_P4RUNTIME_INFO_GEN_HDRS ${CMAKE_CURRENT_BINARY_DIR}/p4/config/p4info.pb.h) # The generated code for protobuf has an excessive number of warnings # Silence -Warray-bounds as the root issue is out of our control: https://github.com/protocolbuffers/protobuf/issues/7140 set_source_files_properties(${DPDK_P4RUNTIME_INFO_GEN_SRCS} PROPERTIES @@ -30,20 +30,21 @@ set_source_files_properties(${DPDK_P4RUNTIME_INFO_GEN_SRCS} PROPERTIES add_custom_target (dpdk_runtime_dir ${CMAKE_COMMAND} -E make_directory - ${P4C_BINARY_DIR}/p4/config/dpdk) + ${CMAKE_CURRENT_BINARY_DIR}/p4/config) # Generate source code from .proto using protoc. The output is # placed in the build directory inside `control-plane` directory add_custom_command( OUTPUT ${DPDK_P4RUNTIME_INFO_GEN_SRCS} ${DPDK_P4RUNTIME_INFO_GEN_HDRS} COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --proto_path ${DPDK_P4RUNTIME_DIR} - --proto_path ${P4C_SOURCE_DIR}/control-plane/p4runtime/proto - --cpp_out ${P4C_BINARY_DIR}/p4/config/dpdk - --python_out ${P4C_BINARY_DIR}/p4/config/dpdk + --proto_path ${P4RUNTIME_STD_DIR} + --cpp_out ${CMAKE_CURRENT_BINARY_DIR}/p4/config + --python_out ${CMAKE_CURRENT_BINARY_DIR}/p4/config ${DPDK_P4RUNTIME_INFO_PROTO} DEPENDS ${DPDK_P4RUNTIME_INFO_PROTO} dpdk_runtime_dir COMMENT "Generating protobuf files for p4info on target DPDK." ) +add_dependencies(dpdk_runtime_dir controlplane) add_library(dpdk_runtime STATIC ${DPDK_P4RUNTIME_INFO_GEN_SRCS}) target_include_directories(dpdk_runtime diff --git a/backends/dpdk/control-plane/bfruntime_arch_handler.h b/backends/dpdk/control-plane/bfruntime_arch_handler.h index 9ecc3e2b748..42d67af0dde 100644 --- a/backends/dpdk/control-plane/bfruntime_arch_handler.h +++ b/backends/dpdk/control-plane/bfruntime_arch_handler.h @@ -21,6 +21,7 @@ limitations under the License. #include #include +#include "backends/dpdk/p4/config/p4info.pb.h" #include "control-plane/bfruntime.h" #include "control-plane/p4RuntimeArchHandler.h" #include "control-plane/p4RuntimeArchStandard.h" @@ -31,7 +32,6 @@ limitations under the License. #include "frontends/p4/methodInstance.h" #include "frontends/p4/typeMap.h" #include "midend/eliminateTypedefs.h" -#include "p4/config/dpdk/p4info.pb.h" using P4::ReferenceMap; using P4::TypeMap; diff --git a/backends/dpdk/control-plane/bfruntime_ext.h b/backends/dpdk/control-plane/bfruntime_ext.h index a0094c2d89e..ea29889a562 100644 --- a/backends/dpdk/control-plane/bfruntime_ext.h +++ b/backends/dpdk/control-plane/bfruntime_ext.h @@ -18,8 +18,9 @@ limitations under the License. #include "backends/dpdk/constants.h" #include "backends/dpdk/options.h" +#include "backends/dpdk/p4/config/p4info.pb.h" #include "control-plane/bfruntime.h" -#include "p4/config/dpdk/p4info.pb.h" + namespace P4 { namespace BFRT { diff --git a/bazel/p4c_deps.bzl b/bazel/p4c_deps.bzl index 9f5f16dd052..7617b282ccd 100644 --- a/bazel/p4c_deps.bzl +++ b/bazel/p4c_deps.bzl @@ -44,7 +44,7 @@ filegroup( name = "com_github_p4lang_p4runtime", remote = "https://github.com/p4lang/p4runtime", # Newest commit on main branch as of April 11, 2023. - commit = "90553b90a12ead5c19700e7fef21164dea5b6d22", + commit = "d76a3640a223f47a43dc34e5565b72e43796ba57", shallow_since = "1680213111 -0700", # strip_prefix is broken; we use patch_cmds as a workaround, # see https://github.com/bazelbuild/bazel/issues/10062. diff --git a/control-plane/CMakeLists.txt b/control-plane/CMakeLists.txt index e8ea27c9396..bd5c4bf84c4 100644 --- a/control-plane/CMakeLists.txt +++ b/control-plane/CMakeLists.txt @@ -12,9 +12,27 @@ # See the License for the specific language governing permissions and # limitations under the License. + +# Print download state while setting up P4Runtime. +set(FETCHCONTENT_QUIET_PREV ${FETCHCONTENT_QUIET}) +set(FETCHCONTENT_QUIET OFF) +# Fetch and declare the P4Runtime library. +FetchContent_Declare( + p4runtime + GIT_REPOSITORY https://github.com/p4lang/p4runtime.git + GIT_TAG d76a3640a223f47a43dc34e5565b72e43796ba57 + GIT_PROGRESS TRUE + GIT_SHALLOW TRUE +) +FetchContent_MakeAvailable(p4runtime) +set(FETCHCONTENT_QUIET ${FETCHCONTENT_QUIET_PREV}) +message("Done with setting up P4Runtime for P4C.") + # The standard P4Runtime protocol buffers message definitions live in the PI -# repo, which is included in this repo as a submodule. -set (P4RUNTIME_STD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/p4runtime/proto) +# repo, which is included in this repo as a git module. +set(P4RUNTIME_STD_DIR ${p4runtime_SOURCE_DIR}/proto CACHE INTERNAL + "Path to the P4Runtime directory." +) set (P4RUNTIME_INFO_PROTO ${P4RUNTIME_STD_DIR}/p4/config/v1/p4info.proto) set (P4RUNTIME_INFO_GEN_SRCS ${CMAKE_CURRENT_BINARY_DIR}/p4/config/v1/p4info.pb.cc) set (P4RUNTIME_INFO_GEN_HDRS ${CMAKE_CURRENT_BINARY_DIR}/p4/config/v1/p4info.pb.h) @@ -58,6 +76,7 @@ add_custom_command(OUTPUT ${P4RUNTIME_GEN_SRCS} ${P4RUNTIME_GEN_HDRS} -I ${P4RUNTIME_STD_DIR} -I${CMAKE_CURRENT_SOURCE_DIR} --cpp_out ${CMAKE_CURRENT_BINARY_DIR} --python_out ${CMAKE_CURRENT_BINARY_DIR} + --experimental_allow_proto3_optional ${P4RUNTIME_PROTO} DEPENDS ${P4RUNTIME_PROTO} COMMENT "Generating protobuf files" @@ -100,7 +119,9 @@ target_include_directories(controlplane-gen ) target_link_libraries (controlplane-gen PUBLIC ${PROTOBUF_LIBRARY}) +# Needed for the correct import of google/status.pb.cc include_directories (${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) + # Silence -Warray-bounds as the root issue is out of our control: https://github.com/protocolbuffers/protobuf/issues/7140 set_source_files_properties (${P4RUNTIME_GEN_SRCS} PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter -Wno-array-bounds") diff --git a/control-plane/p4runtime b/control-plane/p4runtime deleted file mode 160000 index 7a322f35f0c..00000000000 --- a/control-plane/p4runtime +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7a322f35f0c80bf20bc7fcc96f9d1ab77e5fd07a diff --git a/control-plane/typeSpecConverter.h b/control-plane/typeSpecConverter.h index 3a9be539b6e..fa86ab56db4 100644 --- a/control-plane/typeSpecConverter.h +++ b/control-plane/typeSpecConverter.h @@ -22,7 +22,7 @@ limitations under the License. #include "ir/ir.h" #include "ir/visitor.h" -#include "p4/config/v1/p4types.pb.h" +#include "p4/config/v1/p4info.pb.h" namespace p4 { diff --git a/test/gtest/p4runtime.cpp b/test/gtest/p4runtime.cpp index c0c86e4da47..1b4be9b9fcb 100644 --- a/test/gtest/p4runtime.cpp +++ b/test/gtest/p4runtime.cpp @@ -25,10 +25,10 @@ limitations under the License. #include -#include "control-plane/p4/config/v1/p4info.pb.h" #include "control-plane/p4/config/v1/p4types.pb.h" #include "control-plane/p4/v1/p4runtime.pb.h" #include "gtest/gtest.h" +#include "p4/config/v1/p4info.pb.h" #pragma GCC diagnostic pop #include "control-plane/p4RuntimeSerializer.h"