Skip to content

Add Bazel support #429

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Add Bazel support
This changeset is the result of running `gazelle` over the codebase,
which prepares it for use in Bazel environments.
  • Loading branch information
sgammon committed Sep 9, 2020

Verified

This commit was signed with the committer’s verified signature. The key has expired.
sgammon Sam Gammon
commit d76915a58a347a153cb6e37cb13244758e081279
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
@@ -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",
],
)
181 changes: 181 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
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",
strip_prefix = "protobuf-31ebe2ac71400344a5db91ffc13c4ddfb7589f92/",
sha256 = "0e8e32d44c9d4572975f43591b51cd3c77392661e4ded17fdfab81e8460344e8",
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", "go_repository")

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",
)

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"],
)
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"],
)
26 changes: 26 additions & 0 deletions extensions/validator_field/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "validator_field",
srcs = ["validator_field.go"],
importpath = "github.com/pseudomuto/protoc-gen-doc/extensions/validator_field",
visibility = ["//visibility:public"],
deps = [
"//extensions",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_mwitkow_go_proto_validators//:go_default_library",
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
],
)

go_test(
name = "validator_field_test",
srcs = ["validator_field_test.go"],
embed = [":validator_field"],
deps = [
"//extensions",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_mwitkow_go_proto_validators//:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
],
)
30 changes: 30 additions & 0 deletions fixtures/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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",
"Vehicle.proto",
],
visibility = ["//visibility:public"],
deps = ["//github.com/pseudomuto/protokit/fixtures:fixtures_proto"],
)

go_proto_library(
name = "com_example_go_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/pseudomuto/protoc-gen-doc/fixtures",
proto = ":com_example_proto",
visibility = ["//visibility:public"],
deps = ["//github.com/pseudomuto/protokit/fixtures:extend.proto"],
)

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

go_library(
name = "resources_lib",
srcs = ["main.go"],
importpath = "github.com/pseudomuto/protoc-gen-doc/resources",
visibility = ["//visibility:private"],
)

go_binary(
name = "resources",
embed = [":resources_lib"],
visibility = ["//visibility:public"],
)
8 changes: 8 additions & 0 deletions thirdparty/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 = "thirdparty",
srcs = ["generate.go"],
importpath = "github.com/pseudomuto/protoc-gen-doc/thirdparty",
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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 = "validate_proto",
srcs = ["validate.proto"],
visibility = ["//visibility:public"],
deps = [
"@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:timestamp_proto",
],
)

go_proto_library(
name = "validate_go_proto",
importpath = "github.com/envoyproxy/protoc-gen-validate/validate",
proto = ":validate_proto",
visibility = ["//visibility:public"],
)

go_library(
name = "validate",
embed = [":validate_go_proto"],
importpath = "github.com/envoyproxy/protoc-gen-validate/validate",
visibility = ["//visibility:public"],
)
24 changes: 24 additions & 0 deletions thirdparty/github.com/mwitkow/go-proto-validators/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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 = "validator_proto",
srcs = ["validator.proto"],
visibility = ["//visibility:public"],
deps = ["@com_google_protobuf//:descriptor_proto"],
)

go_proto_library(
name = "validator_go_proto",
importpath = "github.com/pseudomuto/protoc-gen-doc/thirdparty/github.com/mwitkow/go-proto-validators",
proto = ":validator_proto",
visibility = ["//visibility:public"],
)

go_library(
name = "go-proto-validators",
embed = [":validator_go_proto"],
importpath = "github.com/pseudomuto/protoc-gen-doc/thirdparty/github.com/mwitkow/go-proto-validators",
visibility = ["//visibility:public"],
)
24 changes: 24 additions & 0 deletions thirdparty/github.com/pseudomuto/protokit/fixtures/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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_pseudomuto_protokit_v1_proto",
srcs = ["extend.proto"],
visibility = ["//visibility:public"],
deps = ["@com_google_protobuf//:descriptor_proto"],
)

go_proto_library(
name = "com_pseudomuto_protokit_v1_go_proto",
importpath = "github.com/pseudomuto/protoc-gen-doc/thirdparty/github.com/pseudomuto/protokit/fixtures",
proto = ":com_pseudomuto_protokit_v1_proto",
visibility = ["//visibility:public"],
)

go_library(
name = "fixtures",
embed = [":com_pseudomuto_protokit_v1_go_proto"],
importpath = "github.com/pseudomuto/protoc-gen-doc/thirdparty/github.com/pseudomuto/protokit/fixtures",
visibility = ["//visibility:public"],
)
66 changes: 66 additions & 0 deletions tools/bazel.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

# bazelrc file
# bazel >= 0.18 looks for %workspace%/.bazelrc (which redirects here)
# Older bazel versions look for %workspace%/tools/bazel.rc (this file)
# See https://github.com/bazelbuild/bazel/issues/6319


##
# Base Settings
##

common --experimental_allow_incremental_repository_updates

run --incompatible_restrict_string_escapes=false
run --incompatible_strict_action_env

build --strategy=sandboxed
build --incompatible_restrict_string_escapes=false
build --watchfs
build --symlink_prefix=dist/
build --nolegacy_external_runfiles
build --incompatible_strict_action_env
build --interface_shared_objects
build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla

build --worker_sandboxing
build --disk_cache=~/.cache/bazel-disk-cache
build:dbg --compilation_mode=dbg

common:ci --curses=no

build:ci --worker_max_instances=32
build:ci --local_cpu_resources=32
build:ci --local_ram_resources="HOST_RAM*.8"
build:ci --experimental_persistent_javac
build:ci --verbose_failures
build:ci --worker_verbose
build:ci --repository_cache=~/.cache/bazel/repo
build:ci --disk_cache=~/.cache/bazel/disk

run:ci --worker_max_instances=32
run:ci --local_cpu_resources=32
run:ci --local_ram_resources="HOST_RAM*.8"
run:ci --experimental_persistent_javac
run:ci --verbose_failures
run:ci --worker_verbose
run:ci --repository_cache=~/.cache/bazel/repo
run:ci --disk_cache=~/.cache/bazel/disk

test:ci --test_output=all
test:ci --test_verbose_timeout_warnings

fetch:ci --repository_cache=~/.cache/bazel/repo
query:ci --repository_cache=~/.cache/bazel/repo

build:release --compilation_mode=opt
build:release --copt=-Wframe-larger-than=16384
build:release --copt=-O3
run:release --compilation_mode=opt
run:release --copt=-Wframe-larger-than=16384
run:release --copt=-O3

query --output=label_kind

try-import %workspace%/.bazelrc.user