bazelbuild/bazel

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

Open

#25.383 geöffnet am 25. Feb. 2025

Auf GitHub ansehen
 (5 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Java (4.465 Forks)batch import
P2help wantedteam-ExternalDepstype: feature request

Repository-Metriken

Stars
 (25.384 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 22T 20h) (77 gemergte PRs in 30 T)

Beschreibung

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.

Contributor Guide