Skip to content

Commit

Permalink
Finalise Bazel support
Browse files Browse the repository at this point in the history
  • Loading branch information
Helcaraxan committed Dec 24, 2019
1 parent 3197598 commit f73ec5a
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@

# Build and script artefacts.
deps/
bazel-*

78 changes: 70 additions & 8 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,26 +1,88 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:compiler.bzl", "go_proto_compiler")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")

proto_library(
name = "validator_proto",
filegroup(
name = "validators",
srcs = ["validator.proto"],
visibility = ["//visibility:public"],
)

proto_library(
name = "validators_proto",
srcs = [":validators"],
import_prefix = "github.com/mwitkow/go-proto-validators",
deps = [
"@com_google_protobuf//:descriptor_proto",
],
visibility = ["//visibility:public"],
)

go_library(
name = "go_default_library",
srcs = [
"helper.go",
"validator.pb.go",
go_proto_compiler(
name = "go_proto_validators",
plugin = "//protoc-gen-govalidators",
options = ["gogoimport=false"],
suffix = ".validator.pb.go",
valid_archive = False,
deps = [
":validators_golang",
"@com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library",
],
visibility = ["//visibility:public"],
)

go_proto_compiler(
name = "gogo_proto_validators",
plugin = "//protoc-gen-govalidators",
options = ["gogoimport=true"],
suffix = ".validator.pb.go",
valid_archive = False,
deps = [
":validators_gogo",
"@com_github_gogo_protobuf//protoc-gen-gogo/descriptor:go_default_library",
],
visibility = ["//visibility:public"],
)

go_proto_library(
name = "_validators_gogo",
importpath = "github.com/mwitkow/go-proto-validators",
proto = ":validators_proto",
compilers = [
"@io_bazel_rules_go//proto:gogo_proto",
],
deps = [
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_gogo_protobuf//protoc-gen-gogo/descriptor:go_default_library",
],
visibility = ["//:__pkg__"],
)

go_proto_library(
name = "_validators_golang",
importpath = "github.com/mwitkow/go-proto-validators",
proto = ":validators_proto",
compilers = [
"@io_bazel_rules_go//proto:go_proto",
],
deps = [
"@com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library",
],
visibility = ["//:__pkg__"],
)

go_library(
name = "validators_gogo",
importpath = "github.com/mwitkow/go-proto-validators",
srcs = ["helper.go"],
embed = [":_validators_gogo"],
visibility = ["//visibility:public"],
)

go_library(
name = "validators_golang",
importpath = "github.com/mwitkow/go-proto-validators",
srcs = ["helper.go"],
embed = [":_validators_golang"],
visibility = ["//visibility:public"],
)
67 changes: 65 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ workspace(name = "com_github_mwitkow_go_proto_validators")

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

GO_VERSION="1.13.5"
GO_VERSION = "1.13.5"

http_archive(
name = "rules_proto",
Expand All @@ -15,10 +15,15 @@ http_archive(

http_archive(
name = "com_google_protobuf",
sha256 = "678d91d8a939a1ef9cb268e1f20c14cd55e40361dc397bb5881e4e1e532679b1",
strip_prefix = "protobuf-3.10.1",
url = "https://github.com/protocolbuffers/protobuf/archive/v3.10.1.zip",
)

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

protobuf_deps()

http_archive(
name = "io_bazel_rules_go",
sha256 = "d5de13e9a994527b6dc41f39ad9ceee3214974dacb18f73a5fa2a4458ae6d3c9",
Expand All @@ -34,6 +39,7 @@ go_register_toolchains(go_version = GO_VERSION)

http_archive(
name = "bazel_gazelle",
sha256 = "d987004a72697334a095bbaa18d615804a28280201a50ed6c234c40ccc41e493",
strip_prefix = "bazel-gazelle-0.19.1",
urls = [
"https://github.com/bazelbuild/bazel-gazelle/archive/v0.19.1.tar.gz",
Expand All @@ -47,5 +53,62 @@ gazelle_dependencies()
go_repository(
name = "com_github_gogo_protobuf",
importpath = "github.com/gogo/protobuf",
version = "v1.3.1",
sum = "h1:G8O7TerXerS4F6sx9OV7/nRfJdnXgHZu/S/7F2SN+UE=",
version = "v1.3.0",
)

go_repository(
name = "com_github_davecgh_go_spew",
importpath = "github.com/davecgh/go-spew",
sum = "h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=",
version = "v1.1.0",
)

go_repository(
name = "com_github_golang_protobuf",
importpath = "github.com/golang/protobuf",
sum = "h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=",
version = "v1.3.2",
)

go_repository(
name = "com_github_kisielk_errcheck",
importpath = "github.com/kisielk/errcheck",
sum = "h1:reN85Pxc5larApoH1keMBiu2GWtPqXQ1nc9gx+jOU+E=",
version = "v1.2.0",
)

go_repository(
name = "com_github_kisielk_gotool",
importpath = "github.com/kisielk/gotool",
sum = "h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=",
version = "v1.0.0",
)

go_repository(
name = "com_github_pmezard_go_difflib",
importpath = "github.com/pmezard/go-difflib",
sum = "h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=",
version = "v1.0.0",
)

go_repository(
name = "com_github_stretchr_objx",
importpath = "github.com/stretchr/objx",
sum = "h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=",
version = "v0.1.0",
)

go_repository(
name = "com_github_stretchr_testify",
importpath = "github.com/stretchr/testify",
sum = "h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=",
version = "v1.3.0",
)

go_repository(
name = "org_golang_x_tools",
importpath = "golang.org/x/tools",
sum = "h1:NIou6eNFigscvKJmsbyez16S2cIS6idossORlFtSt2E=",
version = "v0.0.0-20181030221726-6c7e314b6563",
)
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module github.com/mwitkow/go-proto-validators

go 1.13

require (
github.com/gogo/protobuf v1.3.0
github.com/golang/protobuf v1.3.2
Expand Down
6 changes: 3 additions & 3 deletions plugin/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["plugin.go"],
importpath = "github.com/mwitkow/go-proto-validators/plugin",
visibility = ["//visibility:public"],
srcs = ["plugin.go"],
deps = [
"//:go_default_library",
"//:validators_gogo",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_gogo_protobuf//protoc-gen-gogo/descriptor:go_default_library",
"@com_github_gogo_protobuf//protoc-gen-gogo/generator:go_default_library",
"@com_github_gogo_protobuf//vanity:go_default_library",
],
visibility = ["//visibility:public"],
)
36 changes: 36 additions & 0 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
load("@rules_proto//proto:defs.bzl", "proto_library")

proto_library(
name = "proto2",
srcs = ["validator_proto2.proto"],
deps = [
"//:validators_proto",
"@gogo_special_proto//github.com/gogo/protobuf/gogoproto",
],
visibility = ["//test:__subpackages__"],
)

proto_library(
name = "proto3",
srcs = ["validator_proto3.proto"],
deps = [
"//:validators_proto",
"@gogo_special_proto//github.com/gogo/protobuf/gogoproto",
],
visibility = ["//test:__subpackages__"],
)

proto_library(
name = "proto3_oneof",
srcs = ["validator_proto3_oneof.proto"],
deps = [
"//:validators_proto",
],
visibility = ["//test:__subpackages__"],
)

proto_library(
name = "proto3_map",
srcs = ["validator_proto3_map.proto"],
visibility = ["//test:__subpackages__"],
)
28 changes: 28 additions & 0 deletions test/gogo/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
load("@io_bazel_rules_go//go:def.bzl", "go_test")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

go_proto_library(
name = "gogo_proto",
importpath = "dummy",
protos = [
"//test:proto2",
"//test:proto3",
"//test:proto3_oneof",
"//test:proto3_map",
],
compilers = [
"//:gogo_proto_validators",
"@io_bazel_rules_go//proto:gogo_proto",
],
visibility = [":__pkg__"]
)

go_test(
name = "go_default_test",
importpath = "dummy",
srcs = ["validator_test.go"],
embed = [":gogo_proto"],
deps = [
"@com_github_stretchr_testify//assert:go_default_library",
],
)
31 changes: 31 additions & 0 deletions test/golang/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@io_bazel_rules_go//go:def.bzl", "go_test")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

go_proto_library(
name = "go_proto",
importpath = "dummy",
protos = [
"//test:proto2",
"//test:proto3",
"//test:proto3_oneof",
"//test:proto3_map",
],
compilers = [
"//:go_proto_validators",
"@io_bazel_rules_go//proto:go_proto",
],
deps = [
"@com_github_gogo_protobuf//gogoproto:go_default_library",
],
visibility = [":__pkg__"]
)

go_test(
name = "go_default_test",
importpath = "dummy",
srcs = ["validator_test.go"],
embed = [":go_proto"],
deps = [
"@com_github_stretchr_testify//assert:go_default_library",
],
)
3 changes: 0 additions & 3 deletions test/validator_proto3_map.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
syntax = "proto3";
package validatortest;

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";

message ValueType {
string something = 1 ;
}
Expand Down
1 change: 0 additions & 1 deletion test/validator_proto3_oneof.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
syntax = "proto3";
package validatortest;

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";

message ExternalMsg {
Expand Down

0 comments on commit f73ec5a

Please sign in to comment.