Support `build_file` or `build_file_content` for `http_file`
#25,383 opened on Feb 25, 2025
Repository metrics
- Stars
- (25,384 stars)
- PR merge metrics
- (Avg merge 22d 20h) (77 merged PRs in 30d)
Description
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.