bazelbuild/bazel

Support `build_file` or `build_file_content` for `http_file`

Open

#25,383 创建于 2025年2月25日

在 GitHub 查看
 (5 评论) (0 反应) (0 负责人)Java (4,465 fork)batch import
P2help wantedteam-ExternalDepstype: feature request

仓库指标

Star
 (25,384 star)
PR 合并指标
 (平均合并 22天 20小时) (30 天内合并 77 个 PR)

描述

Description of the feature request:

I would like to use http_file to download a single proto file.

http_file(
    name = "fake_proto",
    sha256 = "abc1234",
    url = "https://raw.githubusercontent.com/myorg/myrepo/src/path/probo/fake.proto
    downloaded_file_path = "fake.proto",
)

I cannot use this natively in a proto_library due to the following via https://github.com/protocolbuffers/protobuf/blob/2d6ab3ce45f85af6bffd694659148062ba9aecde/bazel/private/bazel_proto_library_rule.bzl#L24C5-L24C24

Error in fail: Proto source with label '@@_main~_repo_rules~fake_proto//file:fake.proto' must be in same package as consuming rule.

You can get around this in two ways:

A dummy genrule to copy it to local package

genrule(
    name = "fake_proto_file",
    srcs = ["@fake_proto//file:fake.proto"],
    outs = ["fake.proto"],
    cmd = """
        cp $< $@
    """,
)

http_archive with custom build_file The custom build_file_content can create the proto_library and therefore be in the same package.

Both of these feels unnecessary; pulling in protobuf files should be a straightforward UX in Bazel.

贡献者指南