1

There is a protobuf that my project needs. The protobuf itself is in another repo altogether owned by a completely different team. However they do publish their artifacts on my company's internal Artifactory.

How can I use that (non Bazel) protobuf in my Bazel project?

This is the direction I was trying to go before I hit a deadend.

WORKSPACE file:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")

http_archive(
    name = "rules_proto",
    sha256 = "80d3a4ec17354cccc898bfe32118edd934f851b03029d63ef3fc7c8663a7415c",
    strip_prefix = "rules_proto-5.3.0-21.5",
    urls = [
        "https://github.com/bazelbuild/rules_proto/archive/refs/tags/5.3.0-21.5.tar.gz",
    ],
)
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
rules_proto_dependencies()
rules_proto_toolchains()

http_file(
    name = "some-service-protobuf",
    url = "https://artifactory.xyz.com/artifactory/x/y/some-service-protobuf.dbgrel.zip",
)

BUILD file:

load("@rules_proto//proto:defs.bzl", "proto_library")
proto_library(
    name = "SomeService.proto",
)

The resources I'm trying to use:

  1. https://bazel.build/reference/be/java#java_proto_library
  2. https://github.com/bazelbuild/rules_proto

Is fetching proto files from remote URL possible? How show I do it after copying those files in my repo.

halfer
  • 19,824
  • 17
  • 99
  • 186
90abyss
  • 7,037
  • 19
  • 63
  • 94
  • The advice [on your latest post](https://stackoverflow.com/questions/74588845/getting-a-using-type-x-from-an-indirect-dependency-in-java-test-suite-even-whe) applies here too. Stack Overflow is not a chatroom. Use a spell-checker, and use the Markdown editor to apply formatting for readability. Bear in mind that questions are kept for posterity, and are intended to be useful for future engineers. – halfer Nov 27 '22 at 13:10

1 Answers1

1

You might try using http_archive instead:

https://bazel.build/rules/lib/repo/http#http_archive

And then use the build_file or build_file_content attributes to add the build file with the proto_library definition to the external workspace created from the zip file:

http_archive(
    name = "some-service-protobuf",
    url = "https://artifactory.xyz.com/artifactory/x/y/some-service-protobuf.dbgrel.zip",
    build_file = "BUILD.some_service",
)

BUILD.some_service:

load("@rules_proto//proto:defs.bzl", "proto_library")
proto_library(
    name = "some_service_proto",
    srcs = ["SomeService.proto"],
)

Then in another build file you can do something like:

java_proto_library(
  name = "some_service_java_protobuf",
  deps = ["@some-service-protobuf//:some_service_proto"],
)
ahumesky
  • 4,203
  • 8
  • 12
  • that worked! thanks a lot! one follow up question: if i wanted to add a dependency to this proto_library, how do i do it? i tried with "deps = ["//src/main/proto:timestamp_java_proto"]" but it didnt work – 90abyss Nov 30 '22 at 01:01