Skip to content

Commit

Permalink
Update P4Runtime and use FetchContent instead of a submodule. (#4082)
Browse files Browse the repository at this point in the history
* 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 357898e.
  • Loading branch information
fruffy authored Jul 28, 2023
1 parent 6756816 commit 849cb77
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 19 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 7 additions & 6 deletions backends/dpdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,30 @@ 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
COMPILE_FLAGS "-Wno-unused-parameter -Wno-array-bounds")

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
Expand Down
2 changes: 1 addition & 1 deletion backends/dpdk/control-plane/bfruntime_arch_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License.
#include <unordered_map>
#include <vector>

#include "backends/dpdk/p4/config/p4info.pb.h"
#include "control-plane/bfruntime.h"
#include "control-plane/p4RuntimeArchHandler.h"
#include "control-plane/p4RuntimeArchStandard.h"
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion backends/dpdk/control-plane/bfruntime_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion bazel/p4c_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 23 additions & 2 deletions control-plane/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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")

Expand Down
1 change: 0 additions & 1 deletion control-plane/p4runtime
Submodule p4runtime deleted from 7a322f
2 changes: 1 addition & 1 deletion control-plane/typeSpecConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
2 changes: 1 addition & 1 deletion test/gtest/p4runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ limitations under the License.

#include <boost/algorithm/string/replace.hpp>

#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"
Expand Down

0 comments on commit 849cb77

Please sign in to comment.