Skip to content

Commit

Permalink
Make sure we ignore warnings in the Protobuf dependency source code. (#…
Browse files Browse the repository at this point in the history
…4086)

* Make sure we ignore warnings in the Protobuf dependency source code.

* Wrap Protobuf includes.

* Declare P4Runtime before the extensions.

* Clarifying comments.
  • Loading branch information
fruffy-bfn authored Aug 2, 2023
1 parent 849cb77 commit 281a09e
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 32 deletions.
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,31 @@ set(EXTENSION_IR_SOURCES)
# extensions can provide specific conversions (e.g., for externs)
set(EXTENSION_P4_14_CONV_SOURCES)

########################################## P4Runtime Begin #########################################
# TODO: Ideally, this code should be part of the control-plane CMakelists.txt file. However, because
# extensions which may depend on P4Runtime variables are instantiated before the control-plane we
# need to keep the P4Runtime installation in the top-level CMakelists file.
# 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 git module.
set(P4RUNTIME_STD_DIR ${p4runtime_SOURCE_DIR}/proto CACHE INTERNAL
"Path to the P4Runtime directory."
)
########################################## P4Runtime End ##########################################

file (GLOB p4c_extensions RELATIVE ${P4C_SOURCE_DIR}/extensions ${P4C_SOURCE_DIR}/extensions/*)
MESSAGE ("-- Available extensions ${p4c_extensions}")
foreach (ext ${p4c_extensions})
Expand Down
7 changes: 3 additions & 4 deletions backends/dpdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ 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 ${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
Expand All @@ -51,6 +47,9 @@ target_include_directories(dpdk_runtime
SYSTEM BEFORE PUBLIC ${Protobuf_INCLUDE_DIR}
)

# Silence various warnings as the root issue is out of our control, example https://github.com/protocolbuffers/protobuf/issues/7140
set_source_files_properties(${DPDK_P4RUNTIME_INFO_GEN_SRCS} {$DPDK_P4RUNTIME_INFO_GEN_HDRS} PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter -Wno-array-bounds -Wno-error")

set(P4C_DPDK_SOURCES
../bmv2/common/lower.cpp
backend.cpp
Expand Down
5 changes: 5 additions & 0 deletions backends/dpdk/control-plane/bfruntime_arch_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ limitations under the License.
#include <unordered_map>
#include <vector>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wpedantic"
#include "backends/dpdk/p4/config/p4info.pb.h"
#pragma GCC diagnostic pop

#include "control-plane/bfruntime.h"
#include "control-plane/p4RuntimeArchHandler.h"
#include "control-plane/p4RuntimeArchStandard.h"
Expand Down
3 changes: 3 additions & 0 deletions cmake/Protobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ macro(p4c_obtain_protobuf)
)
set(Protobuf_INCLUDE_DIR ${protobuf_SOURCE_DIR}/src/ CACHE STRING "Protobuf include directory.")
set(PROTOBUF_LIBRARY libprotobuf)
# Protobuf source code may trigger warnings which we need to ignore.
set_target_properties(libprotobuf PROPERTIES COMPILE_FLAGS "-Wno-error")

message("Done with setting up Protobuf for P4C.")
endif()
endmacro(p4c_obtain_protobuf)
27 changes: 3 additions & 24 deletions control-plane/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,6 @@
# 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 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 @@ -80,7 +59,7 @@ add_custom_command(OUTPUT ${P4RUNTIME_GEN_SRCS} ${P4RUNTIME_GEN_HDRS}
${P4RUNTIME_PROTO}
DEPENDS ${P4RUNTIME_PROTO}
COMMENT "Generating protobuf files"
)
)

# These macros are much nicer than the custom command, but do not work for generating
# files in a different directory (e.g. p4/config). If we are ok with just generating
Expand Down Expand Up @@ -122,8 +101,8 @@ 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")
# Silence various warnings as the root issue is out of our control, example https://github.com/protocolbuffers/protobuf/issues/7140
set_source_files_properties (${P4RUNTIME_GEN_SRCS} {$P4RUNTIME_GEN_HDRS} PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter -Wno-array-bounds -Wno-error")

add_library (controlplane STATIC ${CONTROLPLANE_SRCS} )
target_link_libraries (controlplane ${CMAKE_THREAD_LIBS_INIT} controlplane-gen)
Expand Down
4 changes: 4 additions & 0 deletions control-plane/bfruntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ limitations under the License.
#include "lib/json.h"
#include "lib/log.h"
#include "lib/null.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wpedantic"
#include "p4/config/v1/p4info.pb.h"
#pragma GCC diagnostic pop

namespace p4configv1 = ::p4::config::v1;

Expand Down
1 change: 1 addition & 0 deletions control-plane/p4RuntimeArchHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ limitations under the License.

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wpedantic"
#include "p4/config/v1/p4info.pb.h"
#pragma GCC diagnostic pop

Expand Down
9 changes: 6 additions & 3 deletions control-plane/p4RuntimeSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ limitations under the License.
*/
#include "p4RuntimeSerializer.h"

#include <google/protobuf/text_format.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wpedantic"
#include <google/protobuf/text_format.h>
#include <google/protobuf/util/json_util.h>
#pragma GCC diagnostic pop

#include <algorithm>
#include <iostream>
Expand All @@ -30,8 +32,9 @@ limitations under the License.
#include <utility>
#include <vector>

#include "p4/config/v1/p4info.pb.h"
#include "p4/config/v1/p4types.pb.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wpedantic"
#include "p4/v1/p4runtime.pb.h"
#pragma GCC diagnostic pop

Expand Down
1 change: 0 additions & 1 deletion control-plane/typeSpecConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ limitations under the License.
#include "lib/error.h"
#include "lib/exceptions.h"
#include "lib/null.h"
#include "p4/config/v1/p4types.pb.h"
#include "p4RuntimeArchHandler.h"

namespace p4configv1 = ::p4::config::v1;
Expand Down
4 changes: 4 additions & 0 deletions control-plane/typeSpecConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ limitations under the License.

#include "ir/ir.h"
#include "ir/visitor.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wpedantic"
#include "p4/config/v1/p4info.pb.h"
#pragma GCC diagnostic pop

namespace p4 {

Expand Down

0 comments on commit 281a09e

Please sign in to comment.