Skip to content

Set default visibility to public for proto files #238

@CristianNeamtu-47684

Description

@CristianNeamtu-47684

Feature description:
Set default package visibility to public for proto files since they can be seen as an api specification

Problem it solves or use case:
A user of protovalidate may decide to provide their own protobuf definitions for others to use and to generate code based on them. With bazel this is more difficult because they are not publicly exported with the github.com/bufbuild/protovalidate-go.

This can be worked around by either copying them in the 3rd party protos or copying them via a git_repository. With either option it's easy to be out of sync with the go dependency as time passes.

This is useful when working with other individuals or teams that have not transitioned to buf

Proposed implementation or solution:
Define default package visibility as public

package(default_visibility = ["//visibility:public"])

Contribution:
If approved and I can raise a pull-request with the abode change added to the BUILD.bazel

Examples or references:
The deprecated protoc-gen-validate BUILD.bzazel
Google APIs BUILD.bazel

These references allow shipping proto dependenices together with the user's proto definitions.

Additional context:
Bazel query

:> bazel query '@buf_deps//buf/validate:*'
@buf_deps//buf/validate:BUILD.bazel
@buf_deps//buf/validate:expression.proto |
@buf_deps//buf/validate:validate.proto   | <-- desired files
@buf_deps//buf/validate:validate_proto

Our usecase

:> cat proto/BUILD.bazel

load("@rules_pkg//:pkg.bzl", "pkg_zip")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")

pkg_files(
    name = "protovalidate",
    srcs = [
        "@buf_deps//buf/validate:expression.proto",
        "@buf_deps//buf/validate:validate.proto",
    ]
)

# (...)

pkg_zip(
    name = "pkg_proto",
    srcs = [
      # (...)
      "//proto/ours/api.proto",
      # (...)
      ":protovalidate",
    ],
    package_file_name = "proto.zip",
    visibility = ["//visibility:public"],
)
:> bazel build :protovalidate

ERROR: /users/foo/projects/my-project/proto/BUILD.bazel:4:10: in pkg_files rule //proto:protovalidate: target '@buf_deps//buf/validate:expression.proto' is not visible from target '//proto:protovalidate'. Check the visibility declaration of the former target if you think the dependency is legitimate. To set the visibility of that source file target, use the exports_files() function
ERROR: /users/foo/projects/my-project/proto/BUILD.bazel:4:10: in pkg_files rule //proto:protovalidate: target '@buf_deps//buf/validate:validate.proto' is not visible from target '//proto:protovalidate'. Check the visibility declaration of the former target if you think the dependency is legitimate. To set the visibility of that source file target, use the exports_files() function
ERROR: /users/foo/projects/my-project/proto/BUILD.bazel:4:10: Analysis of target '//proto:protovalidate' failed
ERROR: Analysis of target '//proto:protovalidate' failed; build aborted:
INFO: Elapsed time: 0.620s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 2 targets configured)

Metadata

Metadata

Assignees

Labels

FeatureNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions