Bazel Target未在包装中声明

发布于 2025-02-09 01:45:17 字数 1513 浏览 2 评论 0原文

我的目录结构如下:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

默嘫て 2025-02-16 01:45:17

外部是特殊软件包名称之一。选择几乎所有其他名称。

我认为使用//外部不推荐使用,但仍专门用于向后兼容。文档并没有真正谈论它。

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, and external, 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.

追风人 2025-02-16 01:45:17

Brian是正确的,//外部是一个特殊的软件包名称,但是如果您确实需要外部下存储目录,则有实验支持重新安排Bazel的内部实现,以允许在//外部中使用子弹。

首先,将外部/构建移动到外部/aws/build。它与外部/构建无法使用。

然后,使用以下标志:

$ bazel build //external/aws:aws --experimental_sibling_repository_layout --experimental_disable_external_package
Starting local Bazel server and connecting to it...
Analyzing: target //external/aws:aws (41 packages loaded, 199 targets configured)
    Fetching @local_config_cc; Running xcode-locator
    Fetching @aws_sdk; Cloning origin/master of https://github.com/aws/aws-sdk-cpp
    Fetching @cmake-3.22.2-macos-universal; fetching
    Fetching ...versal; Extracting /private/var/tmp/_bazel_jingwen/91b505447ea4b3a0df1e091fb8e7029a/external/cmake-3.22.2-macos-univ\
ersal/temp12961087259543774657/cmake-3.22.2-macos-universal.tar.gz

Brian is correct that //external is a special package name, but if you really need to store the directories under external, there's experimental support that re-arranges Bazel's internal implementation to allow subpackages in //external.

First, move external/BUILD to external/aws/BUILD. It wouldn't work with external/BUILD.

Then, use these flags:

$ bazel build //external/aws:aws --experimental_sibling_repository_layout --experimental_disable_external_package
Starting local Bazel server and connecting to it...
Analyzing: target //external/aws:aws (41 packages loaded, 199 targets configured)
    Fetching @local_config_cc; Running xcode-locator
    Fetching @aws_sdk; Cloning origin/master of https://github.com/aws/aws-sdk-cpp
    Fetching @cmake-3.22.2-macos-universal; fetching
    Fetching ...versal; Extracting /private/var/tmp/_bazel_jingwen/91b505447ea4b3a0df1e091fb8e7029a/external/cmake-3.22.2-macos-univ\
ersal/temp12961087259543774657/cmake-3.22.2-macos-universal.tar.gz
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文