嵌套的 Bazel 项目
Nested Bazel Projects
我正在尝试构建一个使用 TensorFlow Serving 的项目,所以我用 WORKSPACE 文件创建了一个目录 my_dir,将服务存储库克隆到其中,将我的自定义文件放入目录 my_project,在 tensorflow_serving 内配置了 tensorflow,从 my_dir/serving 和
构建了 tensorflow 服务
bazel build //tensorflow_serving/...
那里的一切都很好,然后我尝试构建一个模仿 mnist_export 的 python 文件并将其放入 my_dir 并制作一个构建文件
py_binary(
name = "export_cnn",
srcs = [
"export_cnn.py",
],
deps = [
"@tf//tensorflow:tensorflow_py",
"@tf_serving//tensorflow_serving/session_bundle:exporter",
],
)
然而,当我 运行
bazel build //my_project:export_cnn
我收到以下错误:
ERROR:
.../bazel/_bazel_me/3ef3308a843af155635e839105e8da5c/external/tf/tensorflow/core/BUILD:92:1: null failed: protoc failed: error executing command bazel-out/host/bin/external/tf/google/protobuf/protoc '--cpp_out=bazel-out/local_linux-fastbuild/genfiles/external/tf' -Iexternal/tf -Iexternal/tf/google/protobuf/src ... (remaining 1 argument(s) skipped).
tensorflow/core/framework/step_stats.proto: File not found.
tensorflow/core/framework/device_attributes.proto: File not found.
tensorflow/core/framework/graph.proto: File not found.
tensorflow/core/framework/tensor.proto: File not found.
tensorflow/core/protobuf/config.proto: File not found.
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/framework/step_stats.proto" was not found or had errors.
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/framework/device_attributes.proto" was not found or had errors.
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/framework/graph.proto" was not found or had errors.
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/framework/tensor.proto" was not found or had errors.
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/protobuf/config.proto" was not found or had errors.
tensorflow/core/protobuf/worker.proto:41:12: "DeviceAttributes" is not defined.
tensorflow/core/protobuf/worker.proto:64:3: "GraphDef" is not defined.
tensorflow/core/protobuf/worker.proto:72:3: "GraphOptions" is not defined.
tensorflow/core/protobuf/worker.proto:141:3: "TensorProto" is not defined.
tensorflow/core/protobuf/worker.proto:180:3: "StepStats" is not defined.
tensorflow/core/protobuf/worker.proto:225:3: "BusAdjacency" is not defined.
tensorflow/core/protobuf/worker.proto:227:3: "BusAdjacency" is not defined.
tensorflow/core/protobuf/worker.proto:232:3: "TensorProto" is not defined.
tensorflow/core/protobuf/worker.proto:272:3: "StepStats" is not defined.
在我的 WORKSPACE 文件中,我有以下内容:
local_repository(
name = "tf",
path = __workspace_dir__ + "/serving/tensorflow",
)
local_repository(
name = "tf_serving",
path = __workspace_dir__ + "/serving",
)
load('//serving/tensorflow/tensorflow:workspace.bzl', 'tf_workspace')
tf_workspace("serving/tensorflow/", "@tf")
我的假设是,因为 tensorflow 是一个子子项目,所以它不会将其生成的文件放在祖父项目 bazel-out 中。然而,我已经尝试了很多东西,但一直无法让它发挥作用。
我在一个文件夹中提供 tensorflow,在另一个文件夹中提供我的项目。这是我的 WORKSPACE 文件:
workspace(name = "my_project")
local_repository(
name = "org_tensorflow",
path = __workspace_dir__ + "/tf-serving/tensorflow/",
)
local_repository(
name = "tf_serving",
path = __workspace_dir__ + "/tf-serving/",
)
load('//tf-serving/tensorflow/tensorflow:workspace.bzl', 'tf_workspace')
tf_workspace("tf-serving/tensorflow/", "@org_tensorflow")
# ===== gRPC dependencies =====
bind(
name = "libssl",
actual = "@boringssl_git//:ssl",
)
bind(
name = "zlib",
actual = "@zlib_archive//:zlib",
)
我还将 zlib.BUILD 从 tensorflow 服务复制到我拥有 WORKSPACE 文件的同一位置。
我项目中的 BUILD 文件有这个规则(和你的类似):
py_binary(
name = "export_model",
srcs = [
"export_model.py",
],
deps = [
"@org_tensorflow//tensorflow:tensorflow_py",
"@tf_serving//tensorflow_serving/session_bundle:exporter",
],
)
我的代码和你的代码之间的区别在于我将依赖项包含在我的根 WORKSPACE 中。这段代码在一台机器上对我来说编译和工作正常我在其他机器上编译它有一些问题(ubuntu 14.04)因为一个依赖。希望对你有用。
我还必须添加
--genrule_strategy=standalone --spawn_strategy=standalone
到构建命令以修复依赖关系,当从 tf-serving 工作区 运行 时它编译得很好,但是一旦我将 tf-serving 作为子模块链接并且 运行 它来自我的工作区 我在编译 grpc 时遇到缺少头文件 (nanopb/pb.h) 的错误。
我正在尝试构建一个使用 TensorFlow Serving 的项目,所以我用 WORKSPACE 文件创建了一个目录 my_dir,将服务存储库克隆到其中,将我的自定义文件放入目录 my_project,在 tensorflow_serving 内配置了 tensorflow,从 my_dir/serving 和
构建了 tensorflow 服务bazel build //tensorflow_serving/...
那里的一切都很好,然后我尝试构建一个模仿 mnist_export 的 python 文件并将其放入 my_dir 并制作一个构建文件
py_binary(
name = "export_cnn",
srcs = [
"export_cnn.py",
],
deps = [
"@tf//tensorflow:tensorflow_py",
"@tf_serving//tensorflow_serving/session_bundle:exporter",
],
)
然而,当我 运行
bazel build //my_project:export_cnn
我收到以下错误:
ERROR:
.../bazel/_bazel_me/3ef3308a843af155635e839105e8da5c/external/tf/tensorflow/core/BUILD:92:1: null failed: protoc failed: error executing command bazel-out/host/bin/external/tf/google/protobuf/protoc '--cpp_out=bazel-out/local_linux-fastbuild/genfiles/external/tf' -Iexternal/tf -Iexternal/tf/google/protobuf/src ... (remaining 1 argument(s) skipped).
tensorflow/core/framework/step_stats.proto: File not found.
tensorflow/core/framework/device_attributes.proto: File not found.
tensorflow/core/framework/graph.proto: File not found.
tensorflow/core/framework/tensor.proto: File not found.
tensorflow/core/protobuf/config.proto: File not found.
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/framework/step_stats.proto" was not found or had errors.
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/framework/device_attributes.proto" was not found or had errors.
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/framework/graph.proto" was not found or had errors.
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/framework/tensor.proto" was not found or had errors.
tensorflow/core/protobuf/worker.proto: Import "tensorflow/core/protobuf/config.proto" was not found or had errors.
tensorflow/core/protobuf/worker.proto:41:12: "DeviceAttributes" is not defined.
tensorflow/core/protobuf/worker.proto:64:3: "GraphDef" is not defined.
tensorflow/core/protobuf/worker.proto:72:3: "GraphOptions" is not defined.
tensorflow/core/protobuf/worker.proto:141:3: "TensorProto" is not defined.
tensorflow/core/protobuf/worker.proto:180:3: "StepStats" is not defined.
tensorflow/core/protobuf/worker.proto:225:3: "BusAdjacency" is not defined.
tensorflow/core/protobuf/worker.proto:227:3: "BusAdjacency" is not defined.
tensorflow/core/protobuf/worker.proto:232:3: "TensorProto" is not defined.
tensorflow/core/protobuf/worker.proto:272:3: "StepStats" is not defined.
在我的 WORKSPACE 文件中,我有以下内容:
local_repository(
name = "tf",
path = __workspace_dir__ + "/serving/tensorflow",
)
local_repository(
name = "tf_serving",
path = __workspace_dir__ + "/serving",
)
load('//serving/tensorflow/tensorflow:workspace.bzl', 'tf_workspace')
tf_workspace("serving/tensorflow/", "@tf")
我的假设是,因为 tensorflow 是一个子子项目,所以它不会将其生成的文件放在祖父项目 bazel-out 中。然而,我已经尝试了很多东西,但一直无法让它发挥作用。
我在一个文件夹中提供 tensorflow,在另一个文件夹中提供我的项目。这是我的 WORKSPACE 文件:
workspace(name = "my_project")
local_repository(
name = "org_tensorflow",
path = __workspace_dir__ + "/tf-serving/tensorflow/",
)
local_repository(
name = "tf_serving",
path = __workspace_dir__ + "/tf-serving/",
)
load('//tf-serving/tensorflow/tensorflow:workspace.bzl', 'tf_workspace')
tf_workspace("tf-serving/tensorflow/", "@org_tensorflow")
# ===== gRPC dependencies =====
bind(
name = "libssl",
actual = "@boringssl_git//:ssl",
)
bind(
name = "zlib",
actual = "@zlib_archive//:zlib",
)
我还将 zlib.BUILD 从 tensorflow 服务复制到我拥有 WORKSPACE 文件的同一位置。
我项目中的 BUILD 文件有这个规则(和你的类似):
py_binary(
name = "export_model",
srcs = [
"export_model.py",
],
deps = [
"@org_tensorflow//tensorflow:tensorflow_py",
"@tf_serving//tensorflow_serving/session_bundle:exporter",
],
)
我的代码和你的代码之间的区别在于我将依赖项包含在我的根 WORKSPACE 中。这段代码在一台机器上对我来说编译和工作正常我在其他机器上编译它有一些问题(ubuntu 14.04)因为一个依赖。希望对你有用。
我还必须添加
--genrule_strategy=standalone --spawn_strategy=standalone
到构建命令以修复依赖关系,当从 tf-serving 工作区 运行 时它编译得很好,但是一旦我将 tf-serving 作为子模块链接并且 运行 它来自我的工作区 我在编译 grpc 时遇到缺少头文件 (nanopb/pb.h) 的错误。