Hi,
I am building my plugin with bazel, a few protos needs to be included for the plugin (as mentioned here) and I just can’t seem to get them to compile properly with bazel.
I keep running into a protoc version mismatch error:
bazel-out/aarch64-fastbuild/bin/cc/tensorflow/plugin/protos/graph.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
12 | #error This file was generated by a newer version of protoc which is
| ^~~~~
bazel-out/aarch64-fastbuild/bin/cc/tensorflow/plugin/protos/graph.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
13 | #error incompatible with your Protocol Buffer headers. Please update
| ^~~~~
bazel-out/aarch64-fastbuild/bin/cc/tensorflow/plugin/protos/graph.pb.h:14:2: error: #error your headers.
14 | #error your headers.
| ^~~~~
I checked the protoc version installed on my system, there is only one (after sudo find / -name protoc -type f
).
So I am wondering why and how there can be a mismatch.
This is my workspace:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# ################################################################################
# # Proto for primeclient
# http_archive(
# name = "rules_proto",
# sha256 = "66bfdf8782796239d3875d37e7de19b1d94301e8972b3cbd2446b332429b4df1",
# strip_prefix = "rules_proto-4.0.0",
# urls = [
# "https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0.tar.gz",
# "https://github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0.tar.gz",
# ],
# )
# load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
# rules_proto_dependencies()
# rules_proto_toolchains()
#
# ################################################################################
# ##### gRPC Rules for Bazel
# ##### See https://github.com/grpc/grpc/blob/master/src/cpp/README.md#make
# http_archive(
# name = "com_github_grpc_grpc",
# urls = [
# "https://github.com/grpc/grpc/archive/refs/tags/v1.44.0.tar.gz",
# ],
# sha256 = "8c05641b9f91cbc92f51cc4a5b3a226788d7a63f20af4ca7aaca50d92cc94a0d",
# strip_prefix = "grpc-1.44.0",
# )
# load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
# grpc_deps()
# load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
# grpc_extra_deps()
http_archive(
name = "rules_proto_grpc",
sha256 = "bbe4db93499f5c9414926e46f9e35016999a4e9f6e3522482d3760dc61011070",
strip_prefix = "rules_proto_grpc-4.2.0",
urls = ["https://github.com/rules-proto-grpc/rules_proto_grpc/archive/4.2.0.tar.gz"],
)
load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_toolchains", "rules_proto_grpc_repos")
rules_proto_grpc_toolchains()
rules_proto_grpc_repos()
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
rules_proto_dependencies()
rules_proto_toolchains()
load("@rules_proto_grpc//cpp:repositories.bzl", rules_proto_grpc_cpp_repos = "cpp_repos")
rules_proto_grpc_cpp_repos()
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
grpc_deps()
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
grpc_extra_deps()
################################################################################
# Tensorflow
new_local_repository(
name = "tensorflow_docker_arm64",
path = "/home/tfprime/python3-venv/lib/python3.8/site-packages/tensorflow",
build_file_content = """
package(
default_visibility = [
"//visibility:public",
],
)
cc_library(
name = "headers",
hdrs = glob(["include/**/*"]),
strip_include_prefix = "include",
)
cc_import(
name = "lib",
shared_library = "python/_pywrap_tensorflow_internal.so",
)
""",
)
the protos package BUILD file:
load("@rules_proto_grpc//cpp:defs.bzl", "cpp_proto_library")
cpp_proto_library(
name="protos_all",
protos=[
# ":protolibs_all"
":api_def",
":attr_value",
":cost_graph",
":device_properties",
":full_type",
":function",
":graph",
":node_def",
":op_def",
":op_performance_data",
":resource_handle",
":tensor",
":tensor_shape",
":types",
":versions",
],
linkshared=True,
# output_mode = "NO_PREFIX",
visibility = ["//cc/tensorflow:__subpackages__"],
)
proto_library(
name="api_def",
srcs=["api_def.proto"],
deps = [":attr_value"]
)
proto_library(
name="attr_value",
srcs=["attr_value.proto"],
deps=[
":tensor",
":tensor_shape",
":types",
]
)
proto_library(
name="cost_graph",
srcs=["cost_graph.proto"],
deps=[
":tensor_shape",
":types"
]
)
proto_library(
name="device_properties",
srcs=["device_properties.proto"],
)
proto_library(
name="full_type",
srcs=["full_type.proto"],
)
proto_library(
name="function",
srcs=["function.proto"],
deps=[
":attr_value",
":node_def",
":op_def",
]
)
proto_library(
name="graph",
srcs=["graph.proto"],
deps=[
":function",
":node_def",
":versions",
]
)
proto_library(
name="node_def",
srcs=["node_def.proto"],
deps = [
":attr_value",
":full_type",
]
)
proto_library(
name="op_def",
srcs=["op_def.proto"],
deps = [
":attr_value",
":full_type",
":resource_handle",
":types",
]
)
proto_library(
name="op_performance_data",
srcs=["op_performance_data.proto"],
deps=[
":attr_value",
":device_properties",
":tensor",
":tensor_shape",
":types",
]
)
proto_library(
name="resource_handle",
srcs=["resource_handle.proto"],
deps = [
":tensor_shape",
":types",
]
)
proto_library(
name="tensor",
srcs=["tensor.proto"],
deps=[
":resource_handle",
":tensor_shape",
":types",
]
)
proto_library(
name="tensor_shape",
srcs=["tensor_shape.proto"],
)
proto_library(
name="types",
srcs=["types.proto"],
)
proto_library(
name="versions",
srcs=["versions.proto"],
)
The BUILD that depends on it:
package(default_visibility = ["//visibility:public"])
cc_binary(
name = "ppu_pluggable_device_prime",
linkshared=True,
srcs = glob(["**/*.cc"]) + glob(["**/*.inc"]) + glob(["**/*.h"]),
deps = [
"//cc/tensorflow:docker",
"//cc/tensorflow/plugin_primeclient:plugin_primeclient",
"//cc/primeclient:prime_client.so",
":interface",
],
defines = ["USE_PRIME_CLIENT"],
copts = ["-std=c++17", "-fPIC", "-O2"],
)
cc_library(
name = "interface",
hdrs = glob(["interface/**/*.h", "interface/**/*_impl.inc"]),
includes = ["interface"],
strip_include_prefix = "interface",
deps = [
"//cc/tensorflow/plugin/interface/protos:protos_all",
],
visibility = ["//cc/tensorflow:__subpackages__"],
)
The BUILD that fails:
package(default_visibility = ["//visibility:public"])
cc_library(
name = "plugin_primeclient",
srcs = glob(["**/*.cc", "**/*.inc"]),
alwayslink = True,
linkstatic = True,
deps = [
"//cc/tensorflow:docker",
"//cc/tensorflow/plugin:interface",
"//cc/primeclient:headers",
],
copts = ["-std=c++17", "-fPIC", "-O2"],
visibility = ["//cc/tensorflow/plugin:__pkg__"],
)
I have been trying both rules_proto and rules_proto_grpc and got the same issue.
I have been asking questions related to the same problem on both stackoverflow and github but none of these requests have been successful.
I feel like this issue might be at a better place here as the context is to build a plugin and the issue could eventually be some conflicting headers from the tensorflow repos with mines.
The issue has been blocking me for weeks already so I will be extremly thankful to the kind person that would want to help me with it.