如何添加非 bazel 项目作为当前 bazel 项目的构建目标?
背景: 我有一个 C++ 头文件库,例如:mpack mpack 使用 cmake 构建系统。但是,我想在我的项目(my_project)中使用它的一些功能,该项目使用 bazel 构建系统。
我正在按照以下步骤进行操作 https://docs.bazel.build/versions/ 1.2.0/external.html#non-bazel-projects
目标: 尝试在 sni_filter.cc 中包含 mpack.hpp
我的更改:
a) 在 WORKSPACE 文件中添加了以下代码段
new_local_repository(
name = "mpack-c",
path = "mpack-c",
build_file = "BUILD.mpack-c",
)
b) 添加了 BUILD.mpack-c
cc_library(
name = "mpack-lib",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
c) 在 sni_filter 的 BUILD 文件中添加了 mpack-lib 目标
envoy_cc_library(
name = "sni_filter_lib",
srcs = ["sni_filter.cc"],
hdrs = ["sni_filter.h"],
deps = [
"@mpack-c//:mpack-lib",
],
)
当我尝试运行bazel 构建,它抛出一个错误:
ERROR: Error fetching repository: /xoxo/xyz/abc/repo/src/engine/WORKSPACE:28:21: In new_local_repository rule //external:mpack-c the 'build_file' attribute does not specify an existing file (/xoxo/xyz/abc/repo/src/engine/BUILD.mpack-c does not exist)
ERROR: /xoxo/xyz/abc/repo/src/engine/my_proj/sni_filter/BUILD:11:17: //my_proj/sni_filter:sni_filter_lib depends on @mpack-c//:mpack-lib in repository @mpack-c which failed to fetch. no such package '@mpack-c//': In new_local_repository rule //external:mpack-c the 'build_file' attribute does not specify an existing file (/xoxo/xyz/abc/repo/src/engine/BUILD.mpack-c does not exist)
Background:
I have a C++ header-only library eg : mpack
mpack uses cmake build system. However, I want to use some of its functions in my project (my_project) which uses bazel build system.
I was following the steps from
https://docs.bazel.build/versions/1.2.0/external.html#non-bazel-projects
Goal:
Trying to include mpack.hpp in sni_filter.cc
My changes:
a) Added the following snippet in WORKSPACE file
new_local_repository(
name = "mpack-c",
path = "mpack-c",
build_file = "BUILD.mpack-c",
)
b) Added BUILD.mpack-c
cc_library(
name = "mpack-lib",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
c) Added the mpack-lib target in BUILD file of sni_filter
envoy_cc_library(
name = "sni_filter_lib",
srcs = ["sni_filter.cc"],
hdrs = ["sni_filter.h"],
deps = [
"@mpack-c//:mpack-lib",
],
)
When I am trying to run a bazel build, its throwing an error :
ERROR: Error fetching repository: /xoxo/xyz/abc/repo/src/engine/WORKSPACE:28:21: In new_local_repository rule //external:mpack-c the 'build_file' attribute does not specify an existing file (/xoxo/xyz/abc/repo/src/engine/BUILD.mpack-c does not exist)
ERROR: /xoxo/xyz/abc/repo/src/engine/my_proj/sni_filter/BUILD:11:17: //my_proj/sni_filter:sni_filter_lib depends on @mpack-c//:mpack-lib in repository @mpack-c which failed to fetch. no such package '@mpack-c//': In new_local_repository rule //external:mpack-c the 'build_file' attribute does not specify an existing file (/xoxo/xyz/abc/repo/src/engine/BUILD.mpack-c does not exist)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
new_local_repository
属性中的路径必须是绝对路径,或者相对于WORKSPACE
文件所在目录的相对路径。此外,build_file
中的标签> 属性需要相对于工作空间根指定。因此,在您的 WORKSPACE 文件中将: 替换
为:
作为参考,请参阅 文档。
The path in the
new_local_repository
attribute needs to either be absolute or relative to the directory theWORKSPACE
file is located in. Also, the label in thebuild_file
attribute needs to specified relative to the workspace root.So, in your
WORKSPACE
file replace:with:
For reference, see the documentation.