Support `build_file` or `build_file_content` for `http_file`
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the feature request:
I would like to use `http_file` to download a single proto file.
```starlark
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.
Contributor guide
Research direction
Start by tracing the existing http_file and http_archive handling, especially build_file and build_file_content behavior, and compare the package-placement constraint described in the linked protobuf rule. Done means http_file supports either option so a downloaded proto can be consumed directly by proto_library without a dummy genrule or http_archive.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100