Bazel Target未在包装中声明
我的目录结构如下:
main
| WORKSPACE
| external
> | BUILD
我在外部
下有一个构建文件。我的工作空间文件拉动了AWS SDK:
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
rules_foreign_cc_dependencies()
_ALL_CONTENT = """\
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
"""
new_git_repository(
name = "aws_sdk",
remote = "https://github.com/aws/aws-sdk-cpp",
branch = "master",
build_file_content = _ALL_CONTENT,
init_submodules = True,
recursive_init_submodules = True,
)
并且我的构建文件构建它:
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
cmake(
name = "aws",
cache_entries = {
"CMAKE_BUILD_TYPE": "Release",
"BUILD_ONLY": "dynamodb",
"BUILD_SHARED_LIBS": "ON",
"ENABLE_TESTING": "OFF",
},
lib_source = "@aws_sdk//:all_srcs",
out_shared_libs = [
"libaws-cpp-sdk-core.so",
"libaws-cpp-sdk-dynamodb.so",
]
)
,当我尝试运行bazel build //外部//外部:aws -verbose_failures
时
ERROR: Skipping '//external:aws': no such target '//external:aws': target 'aws' not declared in package 'external' defined by /path/to/WORKSPACE
WARNING: Target pattern parsing failed.
但是 当然,为什么要出现此错误。我缺少什么吗?
编辑:我发现这是因为我将构建目录从library
更改为外部
。当我将其更改回library
时,它似乎可以构建。有什么方法可以让它使用新的目录名称构建?
My directory structure is as follows:
main
| WORKSPACE
| external
> | BUILD
I have a single BUILD file under external
. My workspace file pulls the AWS SDK:
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
rules_foreign_cc_dependencies()
_ALL_CONTENT = """\
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
"""
new_git_repository(
name = "aws_sdk",
remote = "https://github.com/aws/aws-sdk-cpp",
branch = "master",
build_file_content = _ALL_CONTENT,
init_submodules = True,
recursive_init_submodules = True,
)
and my BUILD file builds it:
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
cmake(
name = "aws",
cache_entries = {
"CMAKE_BUILD_TYPE": "Release",
"BUILD_ONLY": "dynamodb",
"BUILD_SHARED_LIBS": "ON",
"ENABLE_TESTING": "OFF",
},
lib_source = "@aws_sdk//:all_srcs",
out_shared_libs = [
"libaws-cpp-sdk-core.so",
"libaws-cpp-sdk-dynamodb.so",
]
)
However, when I try and run bazel build //external:aws --verbose_failures
, I get this error:
ERROR: Skipping '//external:aws': no such target '//external:aws': target 'aws' not declared in package 'external' defined by /path/to/WORKSPACE
WARNING: Target pattern parsing failed.
I'm really not sure why this error is coming up. Is there something I'm missing?
EDIT: I found that it is because I changed the BUILD directory from library
to external
. It seems to build when I change it back to library
; is there a way I can get it to build using a new directory name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
外部
是特殊软件包名称之一。选择几乎所有其他名称。我认为使用
//外部
不推荐使用,但仍专门用于向后兼容。文档并没有真正谈论它。I think
external
is one of the special package names. Pick pretty much any other name instead.I think using
//external
deprecated, but it's still handled specially for backwards compatibility. The docs don't really talk about it.I think Label.ABSOLUTE_PACKAGE_NAMES in the Bazel source is the full list of package names which are special like this. It's currently
conditions
,visibility
, andexternal
, and is unlikely to change because any change can break backwards compatibility in ways that are hard to fix. Those have all been around for a long time, nowadays Bazel has better ways to introduce new identifiers in ways that can't conflict with user code like this.Brian是正确的,
//外部
是一个特殊的软件包名称,但是如果您确实需要在外部
下存储目录,则有实验支持重新安排Bazel的内部实现,以允许在//外部
中使用子弹。首先,将
外部/构建
移动到外部/aws/build
。它与外部/构建
无法使用。然后,使用以下标志:
Brian is correct that
//external
is a special package name, but if you really need to store the directories underexternal
, there's experimental support that re-arranges Bazel's internal implementation to allow subpackages in//external
.First, move
external/BUILD
toexternal/aws/BUILD
. It wouldn't work withexternal/BUILD
.Then, use these flags: