Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default visibility to public for proto files #238

Open
CristianNeamtu-47684 opened this issue Aug 20, 2024 · 2 comments
Open

Set default visibility to public for proto files #238

CristianNeamtu-47684 opened this issue Aug 20, 2024 · 2 comments
Assignees
Labels
Feature New feature or request

Comments

@CristianNeamtu-47684
Copy link

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)
@CristianNeamtu-47684 CristianNeamtu-47684 added the Feature New feature or request label Aug 20, 2024
@CristianNeamtu-47684
Copy link
Author

CristianNeamtu-47684 commented Aug 20, 2024

Upon a closer inspection proto/protovalidate/buf/validate/validate.proto imports buf/validate/priv/private.proto.

Is there another way we can enable others to generate code (without buf) while also providing/managing dependencies?
For example: C#, Ruby

@CristianNeamtu-47684
Copy link
Author

CristianNeamtu-47684 commented Sep 2, 2024

Hi,
Could you please let me know if there are any options to export the proto files as third_party/ dependencies?

This is useful for people that use @grpc/proto-loader or protoc directly, where proto files need to be explicitly added to path.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants