{"id":28534925,"url":"https://github.com/pubref/rules_protobuf","last_synced_at":"2025-07-07T22:30:44.421Z","repository":{"id":44205192,"uuid":"64622101","full_name":"pubref/rules_protobuf","owner":"pubref","description":"Bazel rules for building protocol buffers and gRPC services (java, c++, go, ...)","archived":false,"fork":false,"pushed_at":"2023-07-28T17:49:54.000Z","size":968,"stargazers_count":232,"open_issues_count":5,"forks_count":156,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-06-09T17:14:48.758Z","etag":null,"topics":["bazel","bazel-rules","grpc","grpc-gateway","protobuf","protoc","protocol-buffers"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pubref.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-01T00:02:53.000Z","updated_at":"2025-05-29T14:57:02.000Z","dependencies_parsed_at":"2024-06-18T20:04:38.810Z","dependency_job_id":"0a4a99f7-248f-4812-857b-3b42a7a334c6","html_url":"https://github.com/pubref/rules_protobuf","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/pubref/rules_protobuf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubref%2Frules_protobuf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubref%2Frules_protobuf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubref%2Frules_protobuf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubref%2Frules_protobuf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pubref","download_url":"https://codeload.github.com/pubref/rules_protobuf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubref%2Frules_protobuf/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264154766,"owners_count":23565229,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bazel","bazel-rules","grpc","grpc-gateway","protobuf","protoc","protocol-buffers"],"created_at":"2025-06-09T17:13:24.421Z","updated_at":"2025-07-07T22:30:44.415Z","avatar_url":"https://github.com/pubref.png","language":"Python","readme":"# NOTICE\n\nrules_protobuf was initially written when the bazel protobuf ecosystem was\nfairly immature.  Now 2 years later, this repository is showing its age.  Rather\nthan retrofit this set of rules, it's been re-written from the ground-up to work\ncorrectly with the `native.proto_library` rule and is available at\nhttps://github.com/stackb/rules_proto.  Consequently, these rules are effectively\nno longer being maintained.\n\nPlease upgrade to the newer rules when appropriate and file issues if there are\nfeature gaps that need to be filled.\n\nCheers, @pcj (Oct 25 2018)\n\nhttps://github.com/stackb/rules_proto\n\n---\n\n\n# `rules_protobuf` [![Build Status](https://travis-ci.org/pubref/rules_protobuf.svg?branch=master)](https://travis-ci.org/pubref/rules_protobuf)\n\nBazel skylark rules for building [protocol buffers][protobuf-home]\nwith +/- gRPC support on (osx, linux) :sparkles:.\n\n\u003ctable border=\"0\"\u003e\u003ctr\u003e\n\u003ctd\u003e\u003cimg src=\"https://bazel.build/images/bazel-icon.svg\" height=\"180\"/\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cimg src=\"https://github.com/pubref/rules_protobuf/blob/master/images/wtfcat.png\" height=\"180\"/\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/7802525?v=4\u0026s=400\" height=\"180\"/\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd\u003eBazel\u003c/td\u003e\n\u003ctd\u003erules_protobuf\u003c/td\u003e\n\u003ctd\u003egRPC\u003c/td\u003e\n\u003c/tr\u003e\u003c/table\u003e\n\n### How is this related to the proto\\_library rules within Bazel itself?\n\nThese rules sprung out of a need to have protobuf support when there\nwas limited exposed and documented proto generation capabilities in\nthe main bazel repository.  This is a moving target.  The main goals\nof this project are to:\n\n1. Provide `protoc`, the protocol buffer compiler\n   ([v3.5.1](https://github.com/google/protobuf/commit/1f8b9b202e9a4e467ff0b0f25facb1642727cdf5e69092038f15b37c75b99e45)).\n\n2. Provide the language-specific plugins.\n\n3. Provide the necessary libraries and dependencies for gRPC support,\n   when possible.\n\n4. Provide an extensible `proto_language` abstraction (used in\n   conjunction with the `proto_compile` rule) to generate outputs for\n   current and future custom protoc plugins not explicitly provided\n   here.\n\n\n### Rules\n\n| Language                     | Compile \u003csup\u003e1\u003c/sup\u003e  | Build \u003csup\u003e2\u003c/sup\u003e | gRPC \u003csup\u003e3\u003c/sup\u003e |\n| ---------------------------: | -----------: | --------: | -------- |\n| [C++](cpp)                   | [cc_proto_compile](cpp#cc_proto_compile) | [cc_proto_library](cpp#cc_proto_library) [v3.5.1](https://github.com/google/protobuf/releases/tag/v3.5.1) | [v1.10.1](https://github.com/grpc/grpc/releases/tag/v1.10.1) |\n| [C#](csharp)                 | [csharp_proto_compile](csharp#csharp_proto_compile) | [csharp_proto_library](csharp#csharp_proto_library) | [1.0.0](https://www.nuget.org/packages/Grpc/) |\n| [Closure](closure)           | [closure_proto_compile](closure#closure_proto_compile) | [closure_proto_library](closure#closure_proto_library)          |  |\n| [Go](go)                     | [go_proto_compile](go#go_proto_compile) | [go_proto_library](go#go_proto_library) | [v1.6.0](https://github.com/grpc/grpc-go/releases/tag/v1.6.0) |\n| [Go (gogo)](gogo)            | [gogo_proto_compile](gogo#gogo_proto_compile) | [gogo_proto_library](gogo#gogo_proto_library) | [Nov 2017](https://github.com/gogo/protobuf/commit/616a82ed12d78d24d4839363e8f3c5d3f20627cf) |\n| [gRPC gateway](grpc_gateway) | [grpc_gateway_proto_compile](grpc_gateway#grpc_gateway_proto_compile)\u003cbr/\u003e[grpc_gateway_swagger_compile](grpc_gateway#grpc_gateway_swagger_compile)   | [grpc_gateway_proto_library](grpc_gateway#grpc_gateway_proto_library)\u003cbr/\u003e[grpc_gateway_binary](grpc_gateway#grpc_gateway_binary) | [v1.2.2+ (f2862b)](https://github.com/grpc-ecosystem/grpc-gateway/commit/f2862b476edcef83412c7af8687c9cd8e4097c0f) |\n| [Java](java)                 | [java_proto_compile](java#java_proto_compile) | [java_proto_library](java#java_proto_library) | [v1.9.0](https://github.com/grpc/grpc-java/releases/tag/v1.9.0) |\n| [Node](node)                 | [node_proto_compile](node#node_proto_compile) | [node_proto_library](node#node_proto_library)          | [1.10.1](https://www.npmjs.com/package/grpc) |\n| [Objective-C](objc) | [objc_proto_compile](objc#objc_proto_compile) | [objc_proto_library](objc#objc_proto_library) \u003csup\u003e4\u003c/sup\u003e | [v1.10.1](https://github.com/grpc/grpc/releases/v1.10.1) |\n| [Python](python)             | [py_proto_compile](python#py_proto_compile)         | [py_proto_library](python#py_proto_library)          | [v1.6.1](https://github.com/grpc/grpc/commit/f5600e99be0fdcada4b3039c0f656a305264884a) |\n| [Ruby](ruby)                 | [ruby_proto_compile](ruby#ruby_proto_compile)          |           | [v1.6.1](https://github.com/grpc/grpc/commit/f5600e99be0fdcada4b3039c0f656a305264884a) |\n| Custom [proto_language](protobuf#proto_language) | [proto_compile](protobuf#proto_compile) | |  |\n\n\u003e Refer to [`DEPENDENCIES.md`](DEPENDENCIES.md) for a more detailed\n\u003e summary of workspace dependencies / versions.\n\n1. Support for generation of protoc outputs via `proto_compile()`\n   rule.\n\n2. Support for generation + compilation of outputs with protobuf\n   dependencies.\n\n3. gRPC support.\n\n4. Highly experimental (probably not functional yet). A\n   work-in-progress for those interested in contributing further work.\n\n\n# Usage\n\n## 1. Install Bazel\n\nIf you have not already installed `bazel` on your workstation, follow\nthe [bazel instructions][bazel-install].\n\n\u003e NOTE: Bazel 0.8.0 or above is required for go support. \n\n## 2. Add rules_protobuf your WORKSPACE\n\nSpecify the language(s) you'd like use by loading the\nlanguage-specific `*_proto_repositories` rule(s):\n\n```python\ngit_repository(\n  name = \"org_pubref_rules_protobuf\",\n  remote = \"https://github.com/pubref/rules_protobuf\",\n  tag = \"v0.8.2\",\n  #commit = \"...\" # alternatively, use latest commit on master\n)\n\nload(\"@org_pubref_rules_protobuf//java:rules.bzl\", \"java_proto_repositories\")\njava_proto_repositories()\n\nload(\"@org_pubref_rules_protobuf//cpp:rules.bzl\", \"cpp_proto_repositories\")\ncpp_proto_repositories()\n\nload(\"@org_pubref_rules_protobuf//go:rules.bzl\", \"go_proto_repositories\")\ngo_proto_repositories()\n```\n\nSeveral languages have other `rules_*` dependencies that you'll need\nto load before the `*_proto_repositories()` function is invoked:\n\n| Language | Requires |\n| ---:     | :---     |\n| closure_proto_repositories | [rules_closure](https://github.com/bazelbuild/rules_closure) |\n| csharp_proto_repositories | [rules_dotnet](https://github.com/bazelbuild/rules_dotnet) |\n| go_proto_repositories | [rules_go](https://github.com/bazelbuild/rules_go) |\n| gogo_proto_repositories | [rules_go](https://github.com/bazelbuild/rules_go) |\n| grpc_gateway_proto_repositories | [rules_go](https://github.com/bazelbuild/rules_go) |\n| node_proto_repositories | [rules_node](https://github.com/pubref/rules_node) |\n| py_proto_repositories \u003csup\u003e1\u003c/sup\u003e | [rules_python](https://github.com/bazelbuild/rules_python) |\n\n\u003e \u003csup\u003e1\u003c/sup\u003e Only needed for python grpc support.\n\n## 3. Add \\*\\_proto\\_\\* rules to your BUILD files\n\nTo build a java-based gRPC library:\n\n```python\nload(\"@org_pubref_rules_protobuf//java:rules.bzl\", \"java_proto_library\")\n\njava_proto_library(\n  name = \"protolib\",\n  protos = [\n    \"my.proto\"\n  ],\n  with_grpc = True,\n  verbose = 1, # 0=no output, 1=show protoc command, 2+ more...\n)\n```\n\n## Examples\n\nTo run the examples \u0026 tests in this repository, clone it to your\nworkstation.\n\n```sh\n# Clone this repo\n$ git clone https://github.com/pubref/rules_protobuf\n\n# Go to examples/helloworld directory\n$ cd rules_protobuf/examples/helloworld\n\n# Run all tests\n$ bazel test examples/...\n\n# Build a server\n$ bazel build cpp/server\n\n# Run a server from the command-line\n$ $(bazel info bazel-bin)/examples/helloworld/cpp/server\n\n# Run a client\n$ bazel run go/client\n$ bazel run cpp/client\n$ bazel run java/org/pubref/rules_protobuf/examples/helloworld/client:netty\n```\n\n# Overriding or excluding WORKSPACE dependencies\n\nTo load alternate versions of dependencies, pass in a\n[dict][skylark-dict] having the same overall structure of a\n[deps.bzl](protobuf/deps.bzl) file.  Entries having a matching key will\noverride those found in the file.  For example, to load a different\nversion of https://github.com/golang/protobuf, provide a different\ncommit ID:\n\n```python\nload(\"@org_pubref_rules_protobuf//go:rules.bzl\", \"go_proto_repositories\")\ngo_proto_repositories(\n  overrides = {\n    \"com_github_golang_protobuf\": {\n      # Override golang with a different commit\n      \"commit\": \"2c1988e8c18d14b142c0b472624f71647cf39adb\",\n    }\n  },\n)\n```\n\nYou may already have some external dependencies already present in\nyour workspace that rules_protobuf will attempt to load, causing a\ncollision.  To prevent rules_protobuf from loading specific external\nworkspaces, name them in the `excludes` list:\n\n```python\ngo_proto_repositories(\n  excludes = [\n    \"com_github_golang_glog\",\n  ]\n)\n```\n\nTo completely replace the set of dependencies that will attempt to be\nloaded, you can pass in a full `dict` object to the `lang_deps`\nattribute.\n\n```python\ngo_proto_repositories(\n  lang_deps = {\n    \"com_github_golang_glog\": {\n      ...\n    },\n  },\n)\n```\n\nThere are several language --\u003e language dependencies as well. For\nexample, `python_proto_repositories` and `ruby_proto_repositories`\n(and more) internally call the `cpp_proto_repositories` rule to\nprovide the grpc plugins.  To suppress this (and have better control\nin your workspace), you can use the `omit_cpp_repositories=True`\noption.\n\n# Proto B --\u003e Proto A dependencies\n\nUse the `proto_deps` attribute to name proto rule dependencies. Use of\n`proto_deps` implies you're using imports, so read on...\n\n## Imports\n\nIn all cases, these rules will include a `--proto_path=.` (`-I.`)\nargument.  This is functionally equivalent to `--proto_path=$(bazel\ninfo execution_root)`.  Therefore, when the protoc tool is invoked, it\nwill 'see' whatever directory structure exists at the bazel execution\nroot for your workspace.  To better learn what this looks like, `cd\n$(bazel info execution_root)` and look around.  In general, it\ncontains all your sourcefiles as they appear in your workspace with an\nadditional `external/WORKSPACE_NAME` directory for all dependencies\nused.\n\nThis has implications for import statements in your protobuf\nsourcefiles, if you use them.  The two cases to consider are imports\n*within* your workspace (referred to here as *'internal' imports*),\nand imports of other protobuf files in an external workspace\n(*external imports*).\n\n### Internal Imports\n\nInternal imports should require no additional parameters if your\nimport statements follow the same directory structure of your\nworkspace.  For example, the\n`examples/helloworld/proto/helloworld.proto` file imports the\n`examples/proto/common.proto` file.  Since this matches the workspace\ndirectory structure, `protoc` can find it, and no additional arguments\nto a `cc_proto_library` are required for protoc code generation step.\n\nObviously, importing a file does not mean that code will be generated\nfor it.  Therefore, *use of the imports attribute implies that the\ngenerated files for the imported message or service already exist\nsomewhere that can be used as a dependency some other library rule*\n(such as `srcs` for `java_library`).\n\nRather than using `imports`, it often make more sense to declare a\ndependency on another proto_library rule via the `proto_deps`\nattribute.  This makes the import available to the calling rule and\nperforms the code generation step.  For example, the\n`cc_proto_library` rule in `examples/helloworld/proto:cpp` names the\n`//examples/proto:cpp`'s `cc_proto_library` rule in its `proto_deps`\nattribute to accomplish both code generation and compilation of object\nfiles for the proto chain.\n\n### External Imports\n\nThe same logic applies to external imports.  The two questions to ask\nyourself when setting up your rules are:\n\n[Question 1]: *Can protoc \"see\" the imported file?* In order to satisfy this\nrequirement, pass in the full path of the required file(s) relative to\nthe execution root where protoc will be run.  For example, the\nwell-known `descriptor.proto` could be made visible to protoc via:\n\n```python\njava_proto_library(\n  name = 'fooprotos',\n  protos = 'foo.proto`,\n  imports = [\n      \"external/com_google_protobuf/src/\",\n    ],\n    inputs = [\n      \"@com_google_protobuf//:well_known_protos\",\n    ],\n)\n```\n\nThis would be imported as `import \"google/protobuf/descriptor.proto\"`\ngiven that the file\n`@com_google_protobuf/src/google/protobuf/descriptor.proto` is\nin the package `google.protobuf`.\n\n[Question 2]: *Can the `cc_proto_library` rule \"see\" the generated protobuf files*?\n(in this case `descriptor.pb.{h,cc}`.  Just because the file was\nimported does not imply that protoc will generate outputs for it, so\nsomewhere in the `cc_library` rule dependency chain these files must\nbe present.  This could be via another `cc_proto_library` rule defined\nelswhere, or a some other filegroup or label list.  If the source is\nanother `cc_proto_library` rule, specify that in the `proto_deps`\nattribute to the calling `cc_proto_library` rule.  Otherwise, pass a\nlabel that includes the (pregenerated) protobuf files to the `deps`\nattribute, just as you would any typical `cc_library` rule.\n\n**Important note about sandboxing**: simply stating the path where\n  protoc should look for imports (via the `imports` attribute) is not\n  enough to work with the bazel sandbox.  Bazel is very particular\n  about needing to know *exactly* which inputs are required for a\n  rule, and *exactly* what output files it generates.  If an input is\n  not declared, it will not be exposed in the sandbox.  Therefore, we\n  have to provide both the import path *and* a label-generating rule\n  in the `inputs` attribute that names the files we want available in\n  the sandbox (given here by `:well_known_protos`).\n\nIf you are having problems, put `verbose={1,2,3}` in your build rule\nand/or disable sandboxing with `--spawn_strategy=standalone`.\n\n# Contributing\n\nContributions welcome; please create Issues or GitHub pull requests.\n\n# Credits\n\n* Much thanks to all\n  [contributors](https://github.com/pubref/rules_protobuf/graphs/contributors)\n  and the members of the bazel, protobuf, and gRPC teams.\n\n[protobuf-home]: https://developers.google.com/protocol-buffers/ \"Protocol Buffers Developer Documentation\"\n[bazel-home]: http://bazel.io \"Bazel Homepage\"\n[bazel-install]: http://bazel.io/docs/install.html \"Bazel Installation\"\n[rules_closure]: http://github.com/bazelbuild/rules_closure \"Rules Closure\"\n[rules_go]: http://github.com/bazelbuild/rules_go \"Rules Go\"\n[grpc-gateway-home]:https://github.com/grpc-ecosystem/grpc-gateway\n\n[skylark-dict]: https://www.bazel.io/docs/skylark/lib/dict.html \"Skylark Documentation for dict\"\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpubref%2Frules_protobuf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpubref%2Frules_protobuf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpubref%2Frules_protobuf/lists"}