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

Add Bazel support #429

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

# load bazelrc from the legacy location
# as recommended in https://github.com/bazelbuild/bazel/issues/6319
import %workspace%/tools/bazel.rc

1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.4.1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/test/*.dat
/vendor
/tmp/
bazel-out
45 changes: 45 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "protoc-gen-doc",
srcs = [
"doc.go",
"filters.go",
"plugin.go",
"renderer.go",
"resources.go",
"template.go",
"version.go",
],
importpath = "github.com/pseudomuto/protoc-gen-doc",
visibility = ["//visibility:public"],
deps = [
"//extensions",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_masterminds_sprig//:go_default_library",
"@com_github_pseudomuto_protokit//:go_default_library",
"@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto",
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
],
)

go_test(
name = "protoc-gen-doc_test",
srcs = [
"bench_test.go",
"filters_test.go",
"plugin_test.go",
"renderer_test.go",
"template_test.go",
],
embed = [":protoc-gen-doc"],
deps = [
"//extensions",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_pseudomuto_protokit//:go_default_library",
"@com_github_pseudomuto_protokit//utils:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
"@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto",
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
],
)
52 changes: 52 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
workspace(
name = "protoc_gen_doc",
)

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

http_archive(
name = "io_bazel_rules_go",
sha256 = "7f1aa43d986df189f7cf30e81dd2dc9d8ed7c74e356341a17267f6d7e5748382",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.24.1/rules_go-v0.24.1.tar.gz",
"https://github.com/bazelbuild/rules_go/releases/download/v0.24.1/rules_go-v0.24.1.tar.gz",
],
)

http_archive(
name = "bazel_gazelle",
sha256 = "d4113967ab451dd4d2d767c3ca5f927fec4b30f3b2c6f8135a2033b9c05a5687",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.0/bazel-gazelle-v0.22.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.0/bazel-gazelle-v0.22.0.tar.gz",
],
)

http_archive(
name = "com_google_protobuf",
sha256 = "0e8e32d44c9d4572975f43591b51cd3c77392661e4ded17fdfab81e8460344e8",
strip_prefix = "protobuf-31ebe2ac71400344a5db91ffc13c4ddfb7589f92/",
urls = [
"https://github.com/google/protobuf/archive/31ebe2ac71400344a5db91ffc13c4ddfb7589f92.tar.gz",
],
)

load(
"@com_google_protobuf//:protobuf_deps.bzl",
"protobuf_deps",
)

protobuf_deps()

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
load("//defs:deps.bzl", "go_dependencies")

# gazelle:repository_macro deps.bzl%go_dependencies
go_dependencies()

go_rules_dependencies()

go_register_toolchains()

gazelle_dependencies()
34 changes: 34 additions & 0 deletions cmd/protoc-gen-doc/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

go_library(
name = "protoc-gen-doc_lib",
srcs = [
"flags.go",
"main.go",
],
importpath = "github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc",
visibility = ["//visibility:private"],
deps = [
"//:protoc-gen-doc",
"//extensions/google_api_http",
"//extensions/lyft_validate",
"//extensions/validator_field",
"@com_github_pseudomuto_protokit//:go_default_library",
],
)

go_binary(
name = "protoc-gen-doc",
embed = [":protoc-gen-doc_lib"],
visibility = ["//visibility:public"],
)

go_test(
name = "protoc-gen-doc_test",
srcs = [
"flags_test.go",
"main_test.go",
],
embed = [":protoc-gen-doc_lib"],
deps = ["@com_github_stretchr_testify//require:go_default_library"],
)
3 changes: 3 additions & 0 deletions defs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

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

117 changes: 117 additions & 0 deletions defs/deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
load("@bazel_gazelle//:deps.bzl", "go_repository")

def go_dependencies():
go_repository(
name = "com_github_aokoli_goutils",
importpath = "github.com/aokoli/goutils",
sum = "h1:7fpzNGoJ3VA8qcrm++XEE1QUe0mIwNeLa02Nwq7RDkg=",
version = "v1.0.1",
)
go_repository(
name = "com_github_davecgh_go_spew",
importpath = "github.com/davecgh/go-spew",
sum = "h1:XxMZvQZtTXpWMNWK82vdjCLCe7uGMFXdTsJH0v3Hkvw=",
version = "v0.0.0-20161028175848-04cdfd42973b",
)
go_repository(
name = "com_github_envoyproxy_protoc_gen_validate",
importpath = "github.com/envoyproxy/protoc-gen-validate",
sum = "h1:bV5JGEB1ouEzZa0hgVDFFiClrUEuGWRaAc/3mxR2QK0=",
version = "v0.3.0-java",
)
go_repository(
name = "com_github_gogo_protobuf",
importpath = "github.com/gogo/protobuf",
sum = "h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=",
version = "v1.1.1",
)
go_repository(
name = "com_github_golang_protobuf",
importpath = "github.com/golang/protobuf",
sum = "h1:0iH4Ffd/meGoXqF2lSAhZHt8X+cPgkfn/cb6Cce5Vpc=",
version = "v1.1.0",
)
go_repository(
name = "com_github_google_uuid",
importpath = "github.com/google/uuid",
sum = "h1:jWtZjFEUE/Bz0IeIhqCnyZ3HG6KRXSntXe4SjtuTH7c=",
version = "v0.0.0-20161128191214-064e2069ce9c",
)
go_repository(
name = "com_github_huandu_xstrings",
importpath = "github.com/huandu/xstrings",
sum = "h1:pO2K/gKgKaat5LdpAhxhluX2GPQMaI3W5FUz/I/UnWk=",
version = "v1.0.0",
)
go_repository(
name = "com_github_imdario_mergo",
importpath = "github.com/imdario/mergo",
sum = "h1:mKkfHkZWD8dC7WxKx3N9WCF0Y+dLau45704YQmY6H94=",
version = "v0.3.4",
)
go_repository(
name = "com_github_masterminds_semver",
importpath = "github.com/Masterminds/semver",
sum = "h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc=",
version = "v1.4.2",
)
go_repository(
name = "com_github_masterminds_sprig",
importpath = "github.com/Masterminds/sprig",
sum = "h1:0gSxPGWS9PAr7U2NsQ2YQg6juRDINkUyuvbb4b2Xm8w=",
version = "v2.15.0+incompatible",
)
go_repository(
name = "com_github_mwitkow_go_proto_validators",
importpath = "github.com/mwitkow/go-proto-validators",
sum = "h1:28i1IjGcx8AofiB4N3q5Yls55VEaitzuEPkFJEVgGkA=",
version = "v0.0.0-20180403085117-0950a7990007",
)
go_repository(
name = "com_github_pmezard_go_difflib",
importpath = "github.com/pmezard/go-difflib",
sum = "h1:GD+A8+e+wFkqje55/2fOVnZPkoDIu1VooBWfNrnY8Uo=",
version = "v0.0.0-20151028094244-d8ed2627bdf0",
)
go_repository(
name = "com_github_pseudomuto_protokit",
importpath = "github.com/pseudomuto/protokit",
sum = "h1:hlnBDcy3YEDXH7kc9gV+NLaN0cDzhDvD1s7Y6FZ8RpM=",
version = "v0.2.0",
)
go_repository(
name = "com_github_stretchr_testify",
importpath = "github.com/stretchr/testify",
sum = "h1:Zx8Rp9ozC4FPFxfEKRSUu8+Ay3sZxEUZ7JrCWMbGgvE=",
version = "v0.0.0-20170130113145-4d4bfba8f1d1",
)
go_repository(
name = "in_gopkg_check_v1",
importpath = "gopkg.in/check.v1",
sum = "h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=",
version = "v0.0.0-20161208181325-20d25e280405",
)
go_repository(
name = "in_gopkg_yaml_v2",
importpath = "gopkg.in/yaml.v2",
sum = "h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=",
version = "v2.2.2",
)
go_repository(
name = "org_golang_google_genproto",
importpath = "google.golang.org/genproto",
sum = "h1:b69RmkJsx8NyRJsKF2mQ/AF8s4BNxwNsT4rQ3wON1U0=",
version = "v0.0.0-20181107211654-5fc9ac540362",
)
go_repository(
name = "org_golang_x_crypto",
importpath = "golang.org/x/crypto",
sum = "h1:O5C+XK++apFo5B+Vq4ujc/LkLwHxg9fDdgjgoIikBdA=",
version = "v0.0.0-20180501155221-613d6eafa307",
)
go_repository(
name = "org_golang_x_sync",
importpath = "golang.org/x/sync",
sum = "h1:IqXQ59gzdXv58Jmm2xn0tSOR9i6HqroaOFRQ3wR/dJQ=",
version = "v0.0.0-20190412183630-56d357773e84",
)
4 changes: 4 additions & 0 deletions deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

load("//defs:deps.bzl", _go_dependencies="go_dependencies")
go_dependencies = _go_dependencies

39 changes: 39 additions & 0 deletions examples/proto/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
name = "com_example_proto",
srcs = [
"Booking.proto",
"Customer.proto",
"IgnoreMe.proto",
"Vehicle.proto",
],
visibility = ["//visibility:public"],
deps = [
"//github.com/envoyproxy/protoc-gen-validate/validate:validate_proto",
"//github.com/mwitkow/go-proto-validators:validators_proto",
"@go_googleapis//google/api:annotations_proto",
],
)

go_proto_library(
name = "com_example_go_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/pseudomuto/protoc-gen-doc/examples/proto",
proto = ":com_example_proto",
visibility = ["//visibility:public"],
deps = [
"//github.com/envoyproxy/protoc-gen-validate/validate:validate.proto",
"//github.com/mwitkow/go-proto-validators:validator.proto",
"@go_googleapis//google/api:annotations_go_proto",
],
)

go_library(
name = "proto",
embed = [":com_example_go_proto"],
importpath = "github.com/pseudomuto/protoc-gen-doc/examples/proto",
visibility = ["//visibility:public"],
)
8 changes: 8 additions & 0 deletions extensions/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "extensions",
srcs = ["extensions.go"],
importpath = "github.com/pseudomuto/protoc-gen-doc/extensions",
visibility = ["//visibility:public"],
)
25 changes: 25 additions & 0 deletions extensions/envoyproxy_validate/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "envoyproxy_validate",
srcs = ["envoyproxy_validate.go"],
importpath = "github.com/pseudomuto/protoc-gen-doc/extensions/envoyproxy_validate",
visibility = ["//visibility:public"],
deps = [
"//extensions",
"//thirdparty/github.com/envoyproxy/protoc-gen-validate/validate",
],
)

go_test(
name = "envoyproxy_validate_test",
srcs = ["envoyproxy_validate_test.go"],
embed = [":envoyproxy_validate"],
deps = [
"//extensions",
"//extensions/lyft_validate",
"//thirdparty/github.com/envoyproxy/protoc-gen-validate/validate",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
],
)
23 changes: 23 additions & 0 deletions extensions/google_api_http/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "google_api_http",
srcs = ["google_api_http.go"],
importpath = "github.com/pseudomuto/protoc-gen-doc/extensions/google_api_http",
visibility = ["//visibility:public"],
deps = [
"//extensions",
"@go_googleapis//google/api:annotations_go_proto",
],
)

go_test(
name = "google_api_http_test",
srcs = ["google_api_http_test.go"],
embed = [":google_api_http"],
deps = [
"//extensions",
"@com_github_stretchr_testify//require:go_default_library",
"@go_googleapis//google/api:annotations_go_proto",
],
)
9 changes: 9 additions & 0 deletions extensions/lyft_validate/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "lyft_validate",
srcs = ["alias.go"],
importpath = "github.com/pseudomuto/protoc-gen-doc/extensions/lyft_validate",
visibility = ["//visibility:public"],
deps = ["//extensions/envoyproxy_validate"],
)
Loading