Add validation rules for go. Closes #16
This commit is contained in:
parent
db4e1485f2
commit
4e0c63304c
|
@ -853,6 +853,28 @@ tasks:
|
|||
build_targets:
|
||||
- "//..."
|
||||
working_directory: example/go/go_grpc_compile
|
||||
go_go_validate_compile_ubuntu1804:
|
||||
name: 'go: go_validate_compile'
|
||||
platform: ubuntu1804
|
||||
build_flags:
|
||||
build_targets:
|
||||
- "//..."
|
||||
working_directory: example/go/go_validate_compile
|
||||
go_go_validate_compile_windows:
|
||||
name: 'go: go_validate_compile'
|
||||
platform: windows
|
||||
build_flags:
|
||||
build_targets:
|
||||
- "//..."
|
||||
working_directory: example/go/go_validate_compile
|
||||
go_go_validate_compile_macos:
|
||||
name: 'go: go_validate_compile'
|
||||
platform: macos
|
||||
build_flags:
|
||||
- "--copt=-DGRPC_BAZEL_BUILD"
|
||||
build_targets:
|
||||
- "//..."
|
||||
working_directory: example/go/go_validate_compile
|
||||
go_go_proto_library_ubuntu1804:
|
||||
name: 'go: go_proto_library'
|
||||
platform: ubuntu1804
|
||||
|
@ -897,6 +919,28 @@ tasks:
|
|||
build_targets:
|
||||
- "//..."
|
||||
working_directory: example/go/go_grpc_library
|
||||
go_go_validate_library_ubuntu1804:
|
||||
name: 'go: go_validate_library'
|
||||
platform: ubuntu1804
|
||||
build_flags:
|
||||
build_targets:
|
||||
- "//..."
|
||||
working_directory: example/go/go_validate_library
|
||||
go_go_validate_library_windows:
|
||||
name: 'go: go_validate_library'
|
||||
platform: windows
|
||||
build_flags:
|
||||
build_targets:
|
||||
- "//..."
|
||||
working_directory: example/go/go_validate_library
|
||||
go_go_validate_library_macos:
|
||||
name: 'go: go_validate_library'
|
||||
platform: macos
|
||||
build_flags:
|
||||
- "--copt=-DGRPC_BAZEL_BUILD"
|
||||
build_targets:
|
||||
- "//..."
|
||||
working_directory: example/go/go_validate_library
|
||||
grpc-gateway_gateway_grpc_compile_ubuntu1804:
|
||||
name: 'grpc-gateway: gateway_grpc_compile'
|
||||
platform: ubuntu1804
|
||||
|
|
|
@ -74,8 +74,10 @@ Full documentation for the current and previous versions [can be found here](htt
|
|||
| [F#](https://rules-proto-grpc.com/en/latest/lang/fsharp.html) | [fsharp_grpc_library](https://rules-proto-grpc.com/en/latest/lang/fsharp.html#fsharp-grpc-library) | Generates a F# protobuf and gRPC library using ``fsharp_library`` from ``rules_dotnet``. Note that the library name must end in ``.dll`` ([example](/example/fsharp/fsharp_grpc_library)) |
|
||||
| [Go](https://rules-proto-grpc.com/en/latest/lang/go.html) | [go_proto_compile](https://rules-proto-grpc.com/en/latest/lang/go.html#go-proto-compile) | Generates Go protobuf ``.go`` files ([example](/example/go/go_proto_compile)) |
|
||||
| [Go](https://rules-proto-grpc.com/en/latest/lang/go.html) | [go_grpc_compile](https://rules-proto-grpc.com/en/latest/lang/go.html#go-grpc-compile) | Generates Go protobuf and gRPC ``.go`` files ([example](/example/go/go_grpc_compile)) |
|
||||
| [Go](https://rules-proto-grpc.com/en/latest/lang/go.html) | [go_validate_compile](https://rules-proto-grpc.com/en/latest/lang/go.html#go-validate-compile) | Generates Go protobuf and gRPC validation ``.go`` files ([example](/example/go/go_validate_compile)) |
|
||||
| [Go](https://rules-proto-grpc.com/en/latest/lang/go.html) | [go_proto_library](https://rules-proto-grpc.com/en/latest/lang/go.html#go-proto-library) | Generates a Go protobuf library using ``go_library`` from ``rules_go`` ([example](/example/go/go_proto_library)) |
|
||||
| [Go](https://rules-proto-grpc.com/en/latest/lang/go.html) | [go_grpc_library](https://rules-proto-grpc.com/en/latest/lang/go.html#go-grpc-library) | Generates a Go protobuf and gRPC library using ``go_library`` from ``rules_go`` ([example](/example/go/go_grpc_library)) |
|
||||
| [Go](https://rules-proto-grpc.com/en/latest/lang/go.html) | [go_validate_library](https://rules-proto-grpc.com/en/latest/lang/go.html#go-validate-library) | Generates a Go protobuf and gRPC validation library using ``go_library`` from ``rules_go`` ([example](/example/go/go_validate_library)) |
|
||||
| [grpc-gateway](https://rules-proto-grpc.com/en/latest/lang/grpc-gateway.html) | [gateway_grpc_compile](https://rules-proto-grpc.com/en/latest/lang/grpc-gateway.html#gateway-grpc-compile) | Generates grpc-gateway ``.go`` files ([example](/example/grpc-gateway/gateway_grpc_compile)) |
|
||||
| [grpc-gateway](https://rules-proto-grpc.com/en/latest/lang/grpc-gateway.html) | [gateway_openapiv2_compile](https://rules-proto-grpc.com/en/latest/lang/grpc-gateway.html#gateway-openapiv2-compile) | Generates grpc-gateway OpenAPI v2 ``.json`` files ([example](/example/grpc-gateway/gateway_openapiv2_compile)) |
|
||||
| [grpc-gateway](https://rules-proto-grpc.com/en/latest/lang/grpc-gateway.html) | [gateway_grpc_library](https://rules-proto-grpc.com/en/latest/lang/grpc-gateway.html#gateway-grpc-library) | Generates grpc-gateway library files ([example](/example/grpc-gateway/gateway_grpc_library)) |
|
||||
|
|
|
@ -28,7 +28,7 @@ Only Linux and Darwin (MacOS) is currently supported by Buf.
|
|||
buf_proto_breaking_test
|
||||
-----------------------
|
||||
|
||||
.. warning:: This rule is experimental. It may not work correctly!
|
||||
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
|
||||
|
||||
Checks .proto files for breaking changes
|
||||
|
||||
|
@ -112,7 +112,7 @@ Plugins
|
|||
buf_proto_lint_test
|
||||
-------------------
|
||||
|
||||
.. warning:: This rule is experimental. It may not work correctly!
|
||||
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
|
||||
|
||||
Lints .proto files
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ Rules for generating C protobuf ``.c`` & ``.h`` files and libraries using `upb <
|
|||
c_proto_compile
|
||||
---------------
|
||||
|
||||
.. warning:: This rule is experimental. It may not work correctly!
|
||||
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
|
||||
|
||||
Generates C protobuf ``.h`` & ``.c`` files
|
||||
|
||||
|
@ -116,7 +116,7 @@ Plugins
|
|||
c_proto_library
|
||||
---------------
|
||||
|
||||
.. warning:: This rule is experimental. It may not work correctly!
|
||||
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
|
||||
|
||||
Generates a C protobuf library using ``cc_library``, with dependencies linked
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ Rules for generating protobuf Markdown, JSON, HTML or DocBook documentation with
|
|||
doc_docbook_compile
|
||||
-------------------
|
||||
|
||||
.. warning:: This rule is experimental. It may not work correctly!
|
||||
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
|
||||
|
||||
Generates DocBook ``.xml`` documentation file
|
||||
|
||||
|
@ -116,7 +116,7 @@ Plugins
|
|||
doc_html_compile
|
||||
----------------
|
||||
|
||||
.. warning:: This rule is experimental. It may not work correctly!
|
||||
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
|
||||
|
||||
Generates ``.html`` documentation file
|
||||
|
||||
|
@ -204,7 +204,7 @@ Plugins
|
|||
doc_json_compile
|
||||
----------------
|
||||
|
||||
.. warning:: This rule is experimental. It may not work correctly!
|
||||
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
|
||||
|
||||
Generates ``.json`` documentation file
|
||||
|
||||
|
@ -292,7 +292,7 @@ Plugins
|
|||
doc_markdown_compile
|
||||
--------------------
|
||||
|
||||
.. warning:: This rule is experimental. It may not work correctly!
|
||||
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
|
||||
|
||||
Generates Markdown ``.md`` documentation file
|
||||
|
||||
|
|
212
docs/lang/go.rst
212
docs/lang/go.rst
|
@ -18,10 +18,14 @@ Rules for generating Go protobuf and gRPC ``.go`` files and libraries using `gol
|
|||
- Generates Go protobuf ``.go`` files
|
||||
* - `go_grpc_compile`_
|
||||
- Generates Go protobuf and gRPC ``.go`` files
|
||||
* - `go_validate_compile`_
|
||||
- Generates Go protobuf and gRPC validation ``.go`` files
|
||||
* - `go_proto_library`_
|
||||
- Generates a Go protobuf library using ``go_library`` from ``rules_go``
|
||||
* - `go_grpc_library`_
|
||||
- Generates a Go protobuf and gRPC library using ``go_library`` from ``rules_go``
|
||||
* - `go_validate_library`_
|
||||
- Generates a Go protobuf and gRPC validation library using ``go_library`` from ``rules_go``
|
||||
|
||||
.. _go_proto_compile:
|
||||
|
||||
|
@ -227,6 +231,109 @@ Plugins
|
|||
- `@rules_proto_grpc//go:go_plugin <https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/go/BUILD.bazel>`__
|
||||
- `@rules_proto_grpc//go:grpc_go_plugin <https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/go/BUILD.bazel>`__
|
||||
|
||||
.. _go_validate_compile:
|
||||
|
||||
go_validate_compile
|
||||
-------------------
|
||||
|
||||
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
|
||||
|
||||
Generates Go protobuf and gRPC validation ``.go`` files
|
||||
|
||||
Example
|
||||
*******
|
||||
|
||||
Full example project can be found `here <https://github.com/rules-proto-grpc/rules_proto_grpc/tree/master/example/go/go_validate_compile>`__
|
||||
|
||||
``WORKSPACE``
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
load("@rules_proto_grpc//:repositories.bzl", "bazel_gazelle", "io_bazel_rules_go") # buildifier: disable=same-origin-load
|
||||
|
||||
io_bazel_rules_go()
|
||||
|
||||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
|
||||
|
||||
go_rules_dependencies()
|
||||
|
||||
go_register_toolchains(
|
||||
version = "1.17.1",
|
||||
)
|
||||
|
||||
bazel_gazelle()
|
||||
|
||||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
|
||||
|
||||
gazelle_dependencies()
|
||||
|
||||
load("@rules_proto_grpc//go:repositories.bzl", rules_proto_grpc_go_repos = "go_repos")
|
||||
|
||||
rules_proto_grpc_go_repos()
|
||||
|
||||
``BUILD.bazel``
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
load("@rules_proto_grpc//go:defs.bzl", "go_validate_compile")
|
||||
|
||||
go_validate_compile(
|
||||
name = "thing_go_validate",
|
||||
protos = ["@rules_proto_grpc//example/proto:thing_proto"],
|
||||
)
|
||||
|
||||
go_validate_compile(
|
||||
name = "greeter_go_validate",
|
||||
protos = ["@rules_proto_grpc//example/proto:greeter_grpc"],
|
||||
)
|
||||
|
||||
Attributes
|
||||
**********
|
||||
|
||||
.. list-table:: Attributes for go_validate_compile
|
||||
:widths: 1 1 1 1 4
|
||||
:header-rows: 1
|
||||
|
||||
* - Name
|
||||
- Type
|
||||
- Mandatory
|
||||
- Default
|
||||
- Description
|
||||
* - ``protos``
|
||||
- ``label_list``
|
||||
- true
|
||||
-
|
||||
- List of labels that provide the ``ProtoInfo`` provider (such as ``proto_library`` from ``rules_proto``)
|
||||
* - ``options``
|
||||
- ``string_list_dict``
|
||||
- false
|
||||
- ``[]``
|
||||
- Extra options to pass to plugins, as a dict of plugin label -> list of strings. The key * can be used exclusively to apply to all plugins
|
||||
* - ``verbose``
|
||||
- ``int``
|
||||
- false
|
||||
- ``0``
|
||||
- The verbosity level. Supported values and results are 1: *show command*, 2: *show command and sandbox after running protoc*, 3: *show command and sandbox before and after running protoc*, 4. *show env, command, expected outputs and sandbox before and after running protoc*
|
||||
* - ``prefix_path``
|
||||
- ``string``
|
||||
- false
|
||||
- ``""``
|
||||
- Path to prefix to the generated files in the output directory
|
||||
* - ``extra_protoc_args``
|
||||
- ``string_list``
|
||||
- false
|
||||
- ``[]``
|
||||
- A list of extra args to pass directly to protoc, not as plugin options
|
||||
|
||||
Plugins
|
||||
*******
|
||||
|
||||
- `@rules_proto_grpc//go:go_plugin <https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/go/BUILD.bazel>`__
|
||||
- `@rules_proto_grpc//go:grpc_go_plugin <https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/go/BUILD.bazel>`__
|
||||
- `@rules_proto_grpc//go:validate_go_plugin <https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/go/BUILD.bazel>`__
|
||||
|
||||
.. _go_proto_library:
|
||||
|
||||
go_proto_library
|
||||
|
@ -433,3 +540,108 @@ Attributes
|
|||
- false
|
||||
- ``None``
|
||||
- Importpath for the generated files
|
||||
|
||||
.. _go_validate_library:
|
||||
|
||||
go_validate_library
|
||||
-------------------
|
||||
|
||||
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
|
||||
|
||||
Generates a Go protobuf and gRPC validation library using ``go_library`` from ``rules_go``
|
||||
|
||||
Example
|
||||
*******
|
||||
|
||||
Full example project can be found `here <https://github.com/rules-proto-grpc/rules_proto_grpc/tree/master/example/go/go_validate_library>`__
|
||||
|
||||
``WORKSPACE``
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
load("@rules_proto_grpc//:repositories.bzl", "bazel_gazelle", "io_bazel_rules_go") # buildifier: disable=same-origin-load
|
||||
|
||||
io_bazel_rules_go()
|
||||
|
||||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
|
||||
|
||||
go_rules_dependencies()
|
||||
|
||||
go_register_toolchains(
|
||||
version = "1.17.1",
|
||||
)
|
||||
|
||||
bazel_gazelle()
|
||||
|
||||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
|
||||
|
||||
gazelle_dependencies()
|
||||
|
||||
load("@rules_proto_grpc//go:repositories.bzl", rules_proto_grpc_go_repos = "go_repos")
|
||||
|
||||
rules_proto_grpc_go_repos()
|
||||
|
||||
``BUILD.bazel``
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
load("@rules_proto_grpc//go:defs.bzl", "go_validate_library")
|
||||
|
||||
go_validate_library(
|
||||
name = "greeter_go_validate",
|
||||
importpath = "github.com/rules-proto-grpc/rules_proto_grpc/example/proto",
|
||||
protos = [
|
||||
"@rules_proto_grpc//example/proto:greeter_grpc",
|
||||
"@rules_proto_grpc//example/proto:thing_proto",
|
||||
],
|
||||
)
|
||||
|
||||
Attributes
|
||||
**********
|
||||
|
||||
.. list-table:: Attributes for go_validate_library
|
||||
:widths: 1 1 1 1 4
|
||||
:header-rows: 1
|
||||
|
||||
* - Name
|
||||
- Type
|
||||
- Mandatory
|
||||
- Default
|
||||
- Description
|
||||
* - ``protos``
|
||||
- ``label_list``
|
||||
- true
|
||||
-
|
||||
- List of labels that provide the ``ProtoInfo`` provider (such as ``proto_library`` from ``rules_proto``)
|
||||
* - ``options``
|
||||
- ``string_list_dict``
|
||||
- false
|
||||
- ``[]``
|
||||
- Extra options to pass to plugins, as a dict of plugin label -> list of strings. The key * can be used exclusively to apply to all plugins
|
||||
* - ``verbose``
|
||||
- ``int``
|
||||
- false
|
||||
- ``0``
|
||||
- The verbosity level. Supported values and results are 1: *show command*, 2: *show command and sandbox after running protoc*, 3: *show command and sandbox before and after running protoc*, 4. *show env, command, expected outputs and sandbox before and after running protoc*
|
||||
* - ``prefix_path``
|
||||
- ``string``
|
||||
- false
|
||||
- ``""``
|
||||
- Path to prefix to the generated files in the output directory
|
||||
* - ``extra_protoc_args``
|
||||
- ``string_list``
|
||||
- false
|
||||
- ``[]``
|
||||
- A list of extra args to pass directly to protoc, not as plugin options
|
||||
* - ``deps``
|
||||
- ``label_list``
|
||||
- false
|
||||
- ``[]``
|
||||
- List of labels to pass as deps attr to underlying lang_library rule
|
||||
* - ``importpath``
|
||||
- ``string``
|
||||
- false
|
||||
- ``None``
|
||||
- Importpath for the generated files
|
||||
|
|
|
@ -333,7 +333,7 @@ Attributes
|
|||
objc_grpc_library
|
||||
-----------------
|
||||
|
||||
.. warning:: This rule is experimental. It may not work correctly!
|
||||
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
|
||||
|
||||
Generates an Objective-C protobuf and gRPC library using ``objc_library``
|
||||
|
||||
|
|
|
@ -162,6 +162,11 @@ go_go_grpc_compile_example:
|
|||
cd example/go/go_grpc_compile; \
|
||||
bazel --batch build --verbose_failures --disk_cache=../../bazel-disk-cache //...
|
||||
|
||||
.PHONY: go_go_validate_compile_example
|
||||
go_go_validate_compile_example:
|
||||
cd example/go/go_validate_compile; \
|
||||
bazel --batch build --verbose_failures --disk_cache=../../bazel-disk-cache //...
|
||||
|
||||
.PHONY: go_go_proto_library_example
|
||||
go_go_proto_library_example:
|
||||
cd example/go/go_proto_library; \
|
||||
|
@ -172,8 +177,13 @@ go_go_grpc_library_example:
|
|||
cd example/go/go_grpc_library; \
|
||||
bazel --batch build --verbose_failures --disk_cache=../../bazel-disk-cache //...
|
||||
|
||||
.PHONY: go_go_validate_library_example
|
||||
go_go_validate_library_example:
|
||||
cd example/go/go_validate_library; \
|
||||
bazel --batch build --verbose_failures --disk_cache=../../bazel-disk-cache //...
|
||||
|
||||
.PHONY: go_examples
|
||||
go_examples: go_go_proto_compile_example go_go_grpc_compile_example go_go_proto_library_example go_go_grpc_library_example
|
||||
go_examples: go_go_proto_compile_example go_go_grpc_compile_example go_go_validate_compile_example go_go_proto_library_example go_go_grpc_library_example go_go_validate_library_example
|
||||
|
||||
.PHONY: grpc-gateway_gateway_grpc_compile_example
|
||||
grpc-gateway_gateway_grpc_compile_example:
|
||||
|
@ -411,4 +421,4 @@ swift_swift_grpc_library_example:
|
|||
swift_examples: swift_swift_proto_compile_example swift_swift_grpc_compile_example swift_swift_proto_library_example swift_swift_grpc_library_example
|
||||
|
||||
.PHONY: all_examples
|
||||
all_examples: android_android_proto_compile_example android_android_grpc_compile_example android_android_proto_library_example android_android_grpc_library_example buf_buf_proto_breaking_test_example buf_buf_proto_lint_test_example c_c_proto_compile_example c_c_proto_library_example cpp_cpp_proto_compile_example cpp_cpp_grpc_compile_example cpp_cpp_proto_library_example cpp_cpp_grpc_library_example csharp_csharp_proto_compile_example csharp_csharp_grpc_compile_example csharp_csharp_proto_library_example csharp_csharp_grpc_library_example fsharp_fsharp_proto_compile_example fsharp_fsharp_grpc_compile_example fsharp_fsharp_proto_library_example fsharp_fsharp_grpc_library_example d_d_proto_compile_example d_d_proto_library_example doc_doc_docbook_compile_example doc_doc_html_compile_example doc_doc_json_compile_example doc_doc_markdown_compile_example go_go_proto_compile_example go_go_grpc_compile_example go_go_proto_library_example go_go_grpc_library_example grpc-gateway_gateway_grpc_compile_example grpc-gateway_gateway_openapiv2_compile_example grpc-gateway_gateway_grpc_library_example java_java_proto_compile_example java_java_grpc_compile_example java_java_proto_library_example java_java_grpc_library_example js_js_proto_compile_example js_js_grpc_node_compile_example js_js_grpc_web_compile_example js_js_proto_library_example js_js_grpc_node_library_example js_js_grpc_web_library_example objc_objc_proto_compile_example objc_objc_grpc_compile_example objc_objc_proto_library_example objc_objc_grpc_library_example php_php_proto_compile_example php_php_grpc_compile_example python_python_proto_compile_example python_python_grpc_compile_example python_python_grpclib_compile_example python_python_proto_library_example python_python_grpc_library_example python_python_grpclib_library_example ruby_ruby_proto_compile_example ruby_ruby_grpc_compile_example ruby_ruby_proto_library_example ruby_ruby_grpc_library_example rust_rust_proto_compile_example rust_rust_grpc_compile_example rust_rust_proto_library_example rust_rust_grpc_library_example scala_scala_proto_compile_example scala_scala_grpc_compile_example scala_scala_proto_library_example scala_scala_grpc_library_example swift_swift_proto_compile_example swift_swift_grpc_compile_example swift_swift_proto_library_example swift_swift_grpc_library_example
|
||||
all_examples: android_android_proto_compile_example android_android_grpc_compile_example android_android_proto_library_example android_android_grpc_library_example buf_buf_proto_breaking_test_example buf_buf_proto_lint_test_example c_c_proto_compile_example c_c_proto_library_example cpp_cpp_proto_compile_example cpp_cpp_grpc_compile_example cpp_cpp_proto_library_example cpp_cpp_grpc_library_example csharp_csharp_proto_compile_example csharp_csharp_grpc_compile_example csharp_csharp_proto_library_example csharp_csharp_grpc_library_example d_d_proto_compile_example d_d_proto_library_example doc_doc_docbook_compile_example doc_doc_html_compile_example doc_doc_json_compile_example doc_doc_markdown_compile_example fsharp_fsharp_proto_compile_example fsharp_fsharp_grpc_compile_example fsharp_fsharp_proto_library_example fsharp_fsharp_grpc_library_example go_go_proto_compile_example go_go_grpc_compile_example go_go_validate_compile_example go_go_proto_library_example go_go_grpc_library_example go_go_validate_library_example grpc-gateway_gateway_grpc_compile_example grpc-gateway_gateway_openapiv2_compile_example grpc-gateway_gateway_grpc_library_example java_java_proto_compile_example java_java_grpc_compile_example java_java_proto_library_example java_java_grpc_library_example js_js_proto_compile_example js_js_grpc_node_compile_example js_js_grpc_web_compile_example js_js_proto_library_example js_js_grpc_node_library_example js_js_grpc_web_library_example objc_objc_proto_compile_example objc_objc_grpc_compile_example objc_objc_proto_library_example objc_objc_grpc_library_example php_php_proto_compile_example php_php_grpc_compile_example python_python_proto_compile_example python_python_grpc_compile_example python_python_grpclib_compile_example python_python_proto_library_example python_python_grpc_library_example python_python_grpclib_library_example ruby_ruby_proto_compile_example ruby_ruby_grpc_compile_example ruby_ruby_proto_library_example ruby_ruby_grpc_library_example rust_rust_proto_compile_example rust_rust_grpc_compile_example rust_rust_proto_library_example rust_rust_grpc_library_example scala_scala_proto_compile_example scala_scala_grpc_compile_example scala_scala_proto_library_example scala_scala_grpc_library_example swift_swift_proto_compile_example swift_swift_grpc_compile_example swift_swift_proto_library_example swift_swift_grpc_library_example
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
load("@rules_proto_grpc//go:defs.bzl", "go_validate_compile")
|
||||
|
||||
go_validate_compile(
|
||||
name = "thing_go_validate",
|
||||
protos = ["@rules_proto_grpc//example/proto:thing_proto"],
|
||||
)
|
||||
|
||||
go_validate_compile(
|
||||
name = "greeter_go_validate",
|
||||
protos = ["@rules_proto_grpc//example/proto:greeter_grpc"],
|
||||
)
|
|
@ -0,0 +1,38 @@
|
|||
local_repository(
|
||||
name = "rules_proto_grpc",
|
||||
path = "../../../",
|
||||
)
|
||||
|
||||
load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_repos", "rules_proto_grpc_toolchains")
|
||||
|
||||
rules_proto_grpc_toolchains()
|
||||
|
||||
rules_proto_grpc_repos()
|
||||
|
||||
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
|
||||
|
||||
rules_proto_dependencies()
|
||||
|
||||
rules_proto_toolchains()
|
||||
|
||||
load("@rules_proto_grpc//:repositories.bzl", "bazel_gazelle", "io_bazel_rules_go") # buildifier: disable=same-origin-load
|
||||
|
||||
io_bazel_rules_go()
|
||||
|
||||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
|
||||
|
||||
go_rules_dependencies()
|
||||
|
||||
go_register_toolchains(
|
||||
version = "1.17.1",
|
||||
)
|
||||
|
||||
bazel_gazelle()
|
||||
|
||||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
|
||||
|
||||
gazelle_dependencies()
|
||||
|
||||
load("@rules_proto_grpc//go:repositories.bzl", rules_proto_grpc_go_repos = "go_repos")
|
||||
|
||||
rules_proto_grpc_go_repos()
|
|
@ -0,0 +1,10 @@
|
|||
load("@rules_proto_grpc//go:defs.bzl", "go_validate_library")
|
||||
|
||||
go_validate_library(
|
||||
name = "greeter_go_validate",
|
||||
importpath = "github.com/rules-proto-grpc/rules_proto_grpc/example/proto",
|
||||
protos = [
|
||||
"@rules_proto_grpc//example/proto:greeter_grpc",
|
||||
"@rules_proto_grpc//example/proto:thing_proto",
|
||||
],
|
||||
)
|
|
@ -0,0 +1,38 @@
|
|||
local_repository(
|
||||
name = "rules_proto_grpc",
|
||||
path = "../../../",
|
||||
)
|
||||
|
||||
load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_repos", "rules_proto_grpc_toolchains")
|
||||
|
||||
rules_proto_grpc_toolchains()
|
||||
|
||||
rules_proto_grpc_repos()
|
||||
|
||||
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
|
||||
|
||||
rules_proto_dependencies()
|
||||
|
||||
rules_proto_toolchains()
|
||||
|
||||
load("@rules_proto_grpc//:repositories.bzl", "bazel_gazelle", "io_bazel_rules_go") # buildifier: disable=same-origin-load
|
||||
|
||||
io_bazel_rules_go()
|
||||
|
||||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
|
||||
|
||||
go_rules_dependencies()
|
||||
|
||||
go_register_toolchains(
|
||||
version = "1.17.1",
|
||||
)
|
||||
|
||||
bazel_gazelle()
|
||||
|
||||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
|
||||
|
||||
gazelle_dependencies()
|
||||
|
||||
load("@rules_proto_grpc//go:repositories.bzl", rules_proto_grpc_go_repos = "go_repos")
|
||||
|
||||
rules_proto_grpc_go_repos()
|
|
@ -24,3 +24,20 @@ proto_plugin(
|
|||
tool = "@org_golang_google_grpc_cmd_protoc_gen_go_grpc//:protoc-gen-go-grpc",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
proto_plugin(
|
||||
name = "validate_go_plugin",
|
||||
exclusions = [
|
||||
"google/protobuf",
|
||||
"validate",
|
||||
],
|
||||
options = [
|
||||
"lang=go",
|
||||
"paths=source_relative",
|
||||
],
|
||||
outputs = [
|
||||
"{protopath}.pb.validate.go",
|
||||
],
|
||||
tool = "@com_github_envoyproxy_protoc_gen_validate//:protoc-gen-validate",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
|
@ -2,11 +2,15 @@
|
|||
|
||||
load(":go_proto_compile.bzl", _go_proto_compile = "go_proto_compile")
|
||||
load(":go_grpc_compile.bzl", _go_grpc_compile = "go_grpc_compile")
|
||||
load(":go_validate_compile.bzl", _go_validate_compile = "go_validate_compile")
|
||||
load(":go_proto_library.bzl", _go_proto_library = "go_proto_library")
|
||||
load(":go_grpc_library.bzl", _go_grpc_library = "go_grpc_library")
|
||||
load(":go_validate_library.bzl", _go_validate_library = "go_validate_library")
|
||||
|
||||
# Export go rules
|
||||
go_proto_compile = _go_proto_compile
|
||||
go_grpc_compile = _go_grpc_compile
|
||||
go_validate_compile = _go_validate_compile
|
||||
go_proto_library = _go_proto_library
|
||||
go_grpc_library = _go_grpc_library
|
||||
go_validate_library = _go_validate_library
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
"""Generated definition of go_validate_compile."""
|
||||
|
||||
load(
|
||||
"//:defs.bzl",
|
||||
"ProtoPluginInfo",
|
||||
"proto_compile_attrs",
|
||||
"proto_compile_impl",
|
||||
)
|
||||
|
||||
# Create compile rule
|
||||
go_validate_compile = rule(
|
||||
implementation = proto_compile_impl,
|
||||
attrs = dict(
|
||||
proto_compile_attrs,
|
||||
_plugins = attr.label_list(
|
||||
providers = [ProtoPluginInfo],
|
||||
default = [
|
||||
Label("//go:go_plugin"),
|
||||
Label("//go:grpc_go_plugin"),
|
||||
Label("//go:validate_go_plugin"),
|
||||
],
|
||||
doc = "List of protoc plugins to apply",
|
||||
),
|
||||
),
|
||||
toolchains = [str(Label("//protobuf:toolchain_type"))],
|
||||
)
|
|
@ -0,0 +1,35 @@
|
|||
"""Generated definition of go_validate_library."""
|
||||
|
||||
load("//go:go_grpc_library.bzl", "GRPC_DEPS")
|
||||
load("//go:go_validate_compile.bzl", "go_validate_compile")
|
||||
load("//internal:compile.bzl", "proto_compile_attrs")
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
def go_validate_library(name, **kwargs):
|
||||
# Compile protos
|
||||
name_pb = name + "_pb"
|
||||
go_validate_compile(
|
||||
name = name_pb,
|
||||
prefix_path = kwargs.get("prefix_path", kwargs.get("importpath", "")),
|
||||
**{
|
||||
k: v
|
||||
for (k, v) in kwargs.items()
|
||||
if k in ["protos" if "protos" in kwargs else "deps"] + [
|
||||
key
|
||||
for key in proto_compile_attrs.keys()
|
||||
if key != "prefix_path"
|
||||
]
|
||||
} # Forward args
|
||||
)
|
||||
|
||||
# Create go library
|
||||
go_library(
|
||||
name = name,
|
||||
srcs = [name_pb],
|
||||
deps = kwargs.get("go_deps", []) + VALIDATE_DEPS + kwargs.get("deps", []),
|
||||
importpath = kwargs.get("importpath"),
|
||||
visibility = kwargs.get("visibility"),
|
||||
tags = kwargs.get("tags"),
|
||||
)
|
||||
|
||||
VALIDATE_DEPS = [] + GRPC_DEPS
|
|
@ -25,3 +25,32 @@ def go_repos(**kwargs): # buildifier: disable=function-docstring
|
|||
sum = "h1:M1YKkFIboKNieVO5DLUEVzQfGwJD30Nv2jfUgzb5UcE=",
|
||||
version = "v1.1.0",
|
||||
)
|
||||
|
||||
# For validate
|
||||
go_repository(
|
||||
name = "com_github_envoyproxy_protoc_gen_validate",
|
||||
importpath = "github.com/envoyproxy/protoc-gen-validate",
|
||||
sum = "h1:4CF52PCseTFt4bE+Yk3dIpdVi7XWuPVMhPtm4FaIJPM=",
|
||||
version = "v0.6.1",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_lyft_protoc_gen_star",
|
||||
importpath = "github.com/lyft/protoc-gen-star",
|
||||
sum = "h1:xOpFu4vwmIoUeUrRuAtdCrZZymT/6AkW/bsUWA506Fo=",
|
||||
version = "v0.6.0",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_iancoleman_strcase",
|
||||
importpath = "github.com/iancoleman/strcase",
|
||||
sum = "h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=",
|
||||
version = "v0.2.0",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_spf13_afero",
|
||||
importpath = "github.com/spf13/afero",
|
||||
sum = "h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=",
|
||||
version = "v1.6.0",
|
||||
)
|
||||
|
|
|
@ -73,8 +73,7 @@ PROTO_DEPS = [
|
|||
"@org_golang_google_protobuf//types/known/wrapperspb:go_default_library",
|
||||
]`)
|
||||
|
||||
var goGrpcLibraryRuleTemplate = mustTemplate(
|
||||
`load("//{{ .Lang.Dir }}:{{ .Rule.Base}}_proto_library.bzl", "PROTO_DEPS")
|
||||
var goGrpcLibraryRuleTemplate = mustTemplate(`load("//{{ .Lang.Dir }}:{{ .Rule.Base}}_proto_library.bzl", "PROTO_DEPS")
|
||||
` + goLibraryRuleTemplateString + `
|
||||
# Create {{ .Lang.Name }} library
|
||||
go_library(
|
||||
|
@ -92,6 +91,20 @@ GRPC_DEPS = [
|
|||
"@org_golang_google_grpc//status:go_default_library",
|
||||
] + PROTO_DEPS`)
|
||||
|
||||
var goValidateLibraryRuleTemplate = mustTemplate(`load("//{{ .Lang.Dir }}:{{ .Rule.Base}}_grpc_library.bzl", "GRPC_DEPS")
|
||||
` + goLibraryRuleTemplateString + `
|
||||
# Create {{ .Lang.Name }} library
|
||||
go_library(
|
||||
name = name,
|
||||
srcs = [name_pb],
|
||||
deps = kwargs.get("go_deps", []) + VALIDATE_DEPS + kwargs.get("deps", []),
|
||||
importpath = kwargs.get("importpath"),
|
||||
visibility = kwargs.get("visibility"),
|
||||
tags = kwargs.get("tags"),
|
||||
)
|
||||
|
||||
VALIDATE_DEPS = [] + GRPC_DEPS`)
|
||||
|
||||
// For go, produce one library for all protos, since they are all in the same package
|
||||
var goProtoLibraryExampleTemplate = mustTemplate(`load("@rules_proto_grpc//{{ .Lang.Dir }}:defs.bzl", "{{ .Rule.Name }}")
|
||||
|
||||
|
@ -116,6 +129,17 @@ var goGrpcLibraryExampleTemplate = mustTemplate(`load("@rules_proto_grpc//{{ .La
|
|||
],
|
||||
)`)
|
||||
|
||||
var goValidateLibraryExampleTemplate = mustTemplate(`load("@rules_proto_grpc//{{ .Lang.Dir }}:defs.bzl", "{{ .Rule.Name }}")
|
||||
|
||||
{{ .Rule.Name }}(
|
||||
name = "greeter_{{ .Lang.Name }}_{{ .Rule.Kind }}",
|
||||
importpath = "github.com/rules-proto-grpc/rules_proto_grpc/example/proto",
|
||||
protos = [
|
||||
"@rules_proto_grpc//example/proto:greeter_grpc",
|
||||
"@rules_proto_grpc//example/proto:thing_proto",
|
||||
],
|
||||
)`)
|
||||
|
||||
var goLibraryRuleAttrs = append(append([]*Attr(nil), libraryRuleAttrs...), []*Attr{
|
||||
&Attr{
|
||||
Name: "importpath",
|
||||
|
@ -156,6 +180,18 @@ func makeGo() *Language {
|
|||
Doc: "Generates Go protobuf and gRPC ``.go`` files",
|
||||
Attrs: compileRuleAttrs,
|
||||
},
|
||||
&Rule{
|
||||
Name: "go_validate_compile",
|
||||
Base: "go",
|
||||
Kind: "validate",
|
||||
Implementation: compileRuleTemplate,
|
||||
Plugins: []string{"//go:go_plugin", "//go:grpc_go_plugin", "//go:validate_go_plugin"},
|
||||
WorkspaceExample: goWorkspaceTemplate,
|
||||
BuildExample: grpcCompileExampleTemplate,
|
||||
Doc: "Generates Go protobuf and gRPC validation ``.go`` files",
|
||||
Attrs: compileRuleAttrs,
|
||||
Experimental: true,
|
||||
},
|
||||
&Rule{
|
||||
Name: "go_proto_library",
|
||||
Base: "go",
|
||||
|
@ -176,6 +212,17 @@ func makeGo() *Language {
|
|||
Doc: "Generates a Go protobuf and gRPC library using ``go_library`` from ``rules_go``",
|
||||
Attrs: goLibraryRuleAttrs,
|
||||
},
|
||||
&Rule{
|
||||
Name: "go_validate_library",
|
||||
Base: "go",
|
||||
Kind: "validate",
|
||||
Implementation: goValidateLibraryRuleTemplate,
|
||||
WorkspaceExample: goWorkspaceTemplate,
|
||||
BuildExample: goValidateLibraryExampleTemplate,
|
||||
Doc: "Generates a Go protobuf and gRPC validation library using ``go_library`` from ``rules_go``",
|
||||
Attrs: goLibraryRuleAttrs,
|
||||
Experimental: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -323,7 +323,7 @@ func mustWriteLanguageReadme(dir string, lang *Language) {
|
|||
out.ln()
|
||||
|
||||
if rule.Experimental {
|
||||
out.w(".. warning:: This rule is experimental. It may not work correctly!")
|
||||
out.w(".. warning:: This rule is experimental. It may not work correctly or may change in future releases!")
|
||||
out.ln()
|
||||
}
|
||||
out.w(rule.Doc)
|
||||
|
|
Loading…
Reference in New Issue