diff --git a/.gitignore b/.gitignore index eb15433281d..55e4918abeb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,9 @@ _output/ .idea + +# Bazel. +bazel-bin +bazel-genfiles +bazel-grpc-gateway +bazel-out +bazel-testlogs diff --git a/.travis.yml b/.travis.yml index 730f72a278b..2500db428d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,41 +1,49 @@ language: go sudo: false go: -- 1.9.x -- 1.10.x -- master + - 1.9.x + - 1.10.x + - master go_import_path: github.com/grpc-ecosystem/grpc-gateway cache: directories: - - $HOME/local - - ${TRAVIS_BUILD_DIR}/examples/browser/node_modules + - $HOME/local + - ${TRAVIS_BUILD_DIR}/examples/browser/node_modules + - $HOME/.cache/_grpc_gateway_bazel before_install: -- ./.travis/install-protoc.sh 3.1.0 -- ./.travis/install-swagger-codegen.sh 2.2.2 -- nvm install v6.1 && nvm use v6.1 && node --version -- go get github.com/golang/lint/golint -- go get github.com/dghubble/sling -- go get github.com/go-resty/resty + - if [ "${USE_BAZEL}" = true ]; then ./.travis/install-bazel.sh 0.12.0; fi + - if [ -z "${USE_BAZEL}" ]; then ./.travis/install-protoc.sh 3.1.0; fi + - if [ -z "${USE_BAZEL}" ]; then ./.travis/install-swagger-codegen.sh 2.2.2; fi + - if [ -z "${USE_BAZEL}" ]; then nvm install v6.1 && nvm use v6.1 && node --version; fi + - go get github.com/golang/lint/golint + - go get github.com/dghubble/sling + - go get github.com/go-resty/resty install: -- go get github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway -- go get github.com/grpc-ecosystem/grpc-gateway/runtime -- go get github.com/grpc-ecosystem/grpc-gateway/examples -- go get github.com/grpc-ecosystem/grpc-gateway/examples/server + - go get github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway + - go get github.com/grpc-ecosystem/grpc-gateway/runtime + - go get github.com/grpc-ecosystem/grpc-gateway/examples + - go get github.com/grpc-ecosystem/grpc-gateway/examples/server before_script: -- sh -c 'cd examples/browser && npm install' + - sh -c 'cd examples/browser && npm install' script: -- make realclean && make examples SWAGGER_CODEGEN="java -jar $HOME/local/swagger-codegen-cli.jar" -- if (go version | grep -q "${GO_VERSION_TO_DIFF_TEST}") && [ -z "${GATEWAY_PLUGIN_FLAGS}" ]; then test -z "$(git status --porcelain)" || (git status; git diff; exit 1); fi -- env GLOG_logtostderr=1 go test -race -v github.com/grpc-ecosystem/grpc-gateway/... -- if (go version | grep -q "${GO_VERSION_TO_DIFF_TEST}") && [ -z "${GATEWAY_PLUGIN_FLAGS}" ]; then env GLOG_logtostderr=1 ./bin/coverage; fi -- make lint -- sh -c 'cd examples/browser && node ./node_modules/gulp/bin/gulp' + - if [ "${USE_BAZEL}" = true ]; then ./.travis/bazel-build.sh; fi + - if [ "${USE_BAZEL}" = true ]; then ./.travis/bazel-test.sh; fi + - if [ -z "${USE_BAZEL}" ]; then make realclean && make examples SWAGGER_CODEGEN="java -jar $HOME/local/swagger-codegen-cli.jar"; fi + - if [ -z "${USE_BAZEL}" ] && (go version | grep -q "${GO_VERSION_TO_DIFF_TEST}") && [ -z "${GATEWAY_PLUGIN_FLAGS}" ]; then test -z "$(git status --porcelain)" || (git status; git diff; exit 1); fi + - if [ -z "${USE_BAZEL}" ]; then env GLOG_logtostderr=1 go test -race -v github.com/grpc-ecosystem/grpc-gateway/...; fi + - if [ -z "${USE_BAZEL}" ]; then make lint; fi + - if [ -z "${USE_BAZEL}" ]; then sh -c 'cd examples/browser && node ./node_modules/gulp/bin/gulp'; fi + - if (go version | grep -q "${GO_VERSION_TO_DIFF_TEST}") && [ -z "${GATEWAY_PLUGIN_FLAGS}" ]; then env GLOG_logtostderr=1 ./bin/coverage; fi after_success: - bash <(curl -s https://codecov.io/bash) env: global: - - "PATH=$PATH:$HOME/local/bin" - - GO_VERSION_TO_DIFF_TEST="go version go1\.10\.[0-9]\+ linux/amd64" + - "PATH=$PATH:$HOME/local/bin" + - GO_VERSION_TO_DIFF_TEST="go version go1\.10\.[0-9]\+ linux/amd64" matrix: - - GATEWAY_PLUGIN_FLAGS= - - GATEWAY_PLUGIN_FLAGS=request_context=false + - GATEWAY_PLUGIN_FLAGS= + - GATEWAY_PLUGIN_FLAGS=request_context=false +matrix: + include: + - go: master + env: USE_BAZEL=true diff --git a/.travis/bazel-build.sh b/.travis/bazel-build.sh new file mode 100755 index 00000000000..f46781d414b --- /dev/null +++ b/.travis/bazel-build.sh @@ -0,0 +1,10 @@ +#!/bin/sh -eu + +bazel \ + --batch \ + --output_base=$HOME/.cache/_grpc_gateway_bazel \ + --host_jvm_args=-Xmx500m \ + --host_jvm_args=-Xms500m \ + build \ + --local_resources=400,1,1.0 \ + //... diff --git a/.travis/bazel-test.sh b/.travis/bazel-test.sh new file mode 100755 index 00000000000..86dbbf3270a --- /dev/null +++ b/.travis/bazel-test.sh @@ -0,0 +1,12 @@ +#!/bin/sh -eu + +bazel \ + --batch \ + --output_base=$HOME/.cache/_grpc_gateway_bazel \ + --host_jvm_args=-Xmx500m \ + --host_jvm_args=-Xms500m \ + test \ + --local_resources=400,1,1.0 \ + --test_output=errors \ + --features=race \ + //... diff --git a/.travis/install-bazel.sh b/.travis/install-bazel.sh new file mode 100755 index 00000000000..9bebe44cdd2 --- /dev/null +++ b/.travis/install-bazel.sh @@ -0,0 +1,20 @@ +#!/bin/sh -eu + +bazel_version=$1 + +if test -z "${bazel_version}"; then + echo "Usage: .travis/install-bazel.sh bazel-version" + exit 1 +fi + +if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then + OS=darwin +else + OS=linux +fi + +filename=bazel-${bazel_version}-installer-${OS}-x86_64.sh +wget https://github.com/bazelbuild/bazel/releases/download/${bazel_version}/${filename} +chmod +x $filename +./$filename --user +rm -f $filename diff --git a/BUILD b/BUILD new file mode 100644 index 00000000000..0ab0afa13f7 --- /dev/null +++ b/BUILD @@ -0,0 +1,23 @@ +load("@bazel_gazelle//:def.bzl", "gazelle") + +# gazelle:exclude third_party + +gazelle( + name = "gazelle_diff", + mode = "diff", + prefix = "github.com/grpc-ecosystem/grpc-gateway", +) + +gazelle( + name = "gazelle_fix", + mode = "fix", + prefix = "github.com/grpc-ecosystem/grpc-gateway", +) + +package_group( + name = "generators", + packages = [ + "//protoc-gen-grpc-gateway/...", + "//protoc-gen-swagger/...", + ], +) diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 00000000000..5727c218261 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,41 @@ +workspace(name = "grpc_ecosystem_grpc_gateway") + +http_archive( + name = "io_bazel_rules_go", + url = "https://github.com/bazelbuild/rules_go/releases/download/0.10.3/rules_go-0.10.3.tar.gz", + sha256 = "feba3278c13cde8d67e341a837f69a029f698d7a27ddbb2a202be7a10b22142a", +) + +http_archive( + name = "bazel_gazelle", + url = "https://github.com/bazelbuild/bazel-gazelle/releases/download/0.10.1/bazel-gazelle-0.10.1.tar.gz", + sha256 = "d03625db67e9fb0905bbd206fa97e32ae9da894fe234a493e7517fd25faec914", +) + +load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains") + +go_rules_dependencies() + +go_register_toolchains() + +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") + +gazelle_dependencies() + +load("@io_bazel_rules_go//go:def.bzl", "go_repository") + +go_repository( + name = "com_github_rogpeppe_fastuuid", + commit = "6724a57986aff9bff1a1770e9347036def7c89f6", + importpath = "github.com/rogpeppe/fastuuid", +) + +go_repository( + name = "com_github_go_resty_resty", + commit = "f8815663de1e64d57cdd4ee9e2b2fa96977a030e", + importpath = "github.com/go-resty/resty", +) + +load("//:repositories.bzl", "repositories") + +repositories() diff --git a/codegenerator/BUILD.bazel b/codegenerator/BUILD.bazel new file mode 100644 index 00000000000..1eddaaf7395 --- /dev/null +++ b/codegenerator/BUILD.bazel @@ -0,0 +1,26 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +package(default_visibility = ["//:generators"]) + +go_library( + name = "go_default_library", + srcs = [ + "doc.go", + "parse_req.go", + ], + importpath = "github.com/grpc-ecosystem/grpc-gateway/codegenerator", + deps = [ + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/plugin:go_default_library", + ], +) + +go_test( + name = "go_default_xtest", + srcs = ["parse_req_test.go"], + deps = [ + ":go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/plugin:go_default_library", + ], +) diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel new file mode 100644 index 00000000000..a6964471274 --- /dev/null +++ b/examples/BUILD.bazel @@ -0,0 +1,45 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test") + +package(default_visibility = ["//visibility:private"]) + +go_library( + name = "go_default_library", + srcs = ["main.go"], + importpath = "github.com/grpc-ecosystem/grpc-gateway/examples", + deps = [ + "//examples/examplepb:go_default_library", + "//runtime:go_default_library", + "@com_github_golang_glog//:go_default_library", + "@org_golang_google_grpc//:go_default_library", + ], +) + +go_binary( + name = "examples", + embed = [":go_default_library"], +) + +go_test( + name = "go_default_test", + size = "small", + srcs = [ + "client_test.go", + "integration_test.go", + "main_test.go", + "proto_error_test.go", + ], + embed = [":go_default_library"], + deps = [ + "//examples/clients/abe:go_default_library", + "//examples/clients/echo:go_default_library", + "//examples/examplepb:go_default_library", + "//examples/server:go_default_library", + "//examples/sub:go_default_library", + "//runtime:go_default_library", + "@com_github_golang_protobuf//jsonpb:go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//ptypes/empty:go_default_library", + "@org_golang_google_genproto//googleapis/rpc/status:go_default_library", + "@org_golang_google_grpc//codes:go_default_library", + ], +) diff --git a/examples/clients/abe/BUILD.bazel b/examples/clients/abe/BUILD.bazel new file mode 100644 index 00000000000..b09b173ecc1 --- /dev/null +++ b/examples/clients/abe/BUILD.bazel @@ -0,0 +1,26 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +package(default_visibility = ["//visibility:public"]) + +go_library( + name = "go_default_library", + srcs = [ + "ProtobufDuration.go", + "a_bit_of_everything_nested.go", + "a_bit_of_everything_service_api.go", + "api_client.go", + "api_response.go", + "camel_case_service_name_api.go", + "configuration.go", + "echo_rpc_api.go", + "echo_service_api.go", + "examplepb_a_bit_of_everything.go", + "examplepb_body.go", + "examplepb_numeric_enum.go", + "nested_deep_enum.go", + "protobuf_empty.go", + "sub_string_message.go", + ], + importpath = "github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe", + deps = ["@com_github_go_resty_resty//:go_default_library"], +) diff --git a/examples/clients/echo/BUILD.bazel b/examples/clients/echo/BUILD.bazel new file mode 100644 index 00000000000..99243f3cded --- /dev/null +++ b/examples/clients/echo/BUILD.bazel @@ -0,0 +1,16 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +package(default_visibility = ["//visibility:public"]) + +go_library( + name = "go_default_library", + srcs = [ + "api_client.go", + "api_response.go", + "configuration.go", + "echo_service_api.go", + "examplepb_simple_message.go", + ], + importpath = "github.com/grpc-ecosystem/grpc-gateway/examples/clients/echo", + deps = ["@com_github_go_resty_resty//:go_default_library"], +) diff --git a/examples/examplepb/BUILD.bazel b/examples/examplepb/BUILD.bazel new file mode 100644 index 00000000000..e1617185067 --- /dev/null +++ b/examples/examplepb/BUILD.bazel @@ -0,0 +1,51 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") + +package(default_visibility = ["//visibility:public"]) + +proto_library( + name = "examplepb_proto", + srcs = [ + "a_bit_of_everything.proto", + "echo_service.proto", + "flow_combination.proto", + "stream.proto", + "wrappers.proto", + ], + deps = [ + "//examples/sub:sub_proto", + "//examples/sub2:sub2_proto", + "//protoc-gen-swagger/options:options_proto", + "@com_github_googleapis_googleapis//google/api:api_proto", + "@com_google_protobuf//:duration_proto", + "@com_google_protobuf//:empty_proto", + "@com_google_protobuf//:timestamp_proto", + "@com_google_protobuf//:wrappers_proto", + ], +) + +go_proto_library( + name = "examplepb_go_proto", + compilers = [ + "@io_bazel_rules_go//proto:go_grpc", + "//protoc-gen-grpc-gateway:go_gen_grpc_gateway", + ], + importpath = "github.com/grpc-ecosystem/grpc-gateway/examples/examplepb", + proto = ":examplepb_proto", + deps = [ + "//examples/sub:go_default_library", + "//examples/sub2:go_default_library", + "//protoc-gen-swagger/options:go_default_library", + "@com_github_golang_protobuf//ptypes/duration:go_default_library", + "@com_github_golang_protobuf//ptypes/empty:go_default_library", + "@com_github_golang_protobuf//ptypes/timestamp:go_default_library", + "@com_github_golang_protobuf//ptypes/wrappers:go_default_library", + "@com_github_googleapis_googleapis//google/api:go_default_library", + ], +) + +go_library( + name = "go_default_library", + embed = [":examplepb_go_proto"], + importpath = "github.com/grpc-ecosystem/grpc-gateway/examples/examplepb", +) diff --git a/examples/server/BUILD.bazel b/examples/server/BUILD.bazel new file mode 100644 index 00000000000..0982db9636f --- /dev/null +++ b/examples/server/BUILD.bazel @@ -0,0 +1,29 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +package(default_visibility = ["//visibility:public"]) + +go_library( + name = "go_default_library", + srcs = [ + "a_bit_of_everything.go", + "echo.go", + "flow_combination.go", + "main.go", + ], + importpath = "github.com/grpc-ecosystem/grpc-gateway/examples/server", + deps = [ + "//examples/examplepb:go_default_library", + "//examples/sub:go_default_library", + "//examples/sub2:go_default_library", + "@com_github_golang_glog//:go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//ptypes/duration:go_default_library", + "@com_github_golang_protobuf//ptypes/empty:go_default_library", + "@com_github_rogpeppe_fastuuid//:go_default_library", + "@org_golang_google_genproto//googleapis/rpc/errdetails:go_default_library", + "@org_golang_google_grpc//:go_default_library", + "@org_golang_google_grpc//codes:go_default_library", + "@org_golang_google_grpc//metadata:go_default_library", + "@org_golang_google_grpc//status:go_default_library", + ], +) diff --git a/examples/server/cmd/example-server/BUILD.bazel b/examples/server/cmd/example-server/BUILD.bazel new file mode 100644 index 00000000000..bf03bdc5ee8 --- /dev/null +++ b/examples/server/cmd/example-server/BUILD.bazel @@ -0,0 +1,18 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") + +package(default_visibility = ["//visibility:private"]) + +go_library( + name = "go_default_library", + srcs = ["main.go"], + importpath = "github.com/grpc-ecosystem/grpc-gateway/examples/server/cmd/example-server", + deps = [ + "//examples/server:go_default_library", + "@com_github_golang_glog//:go_default_library", + ], +) + +go_binary( + name = "example-server", + embed = [":go_default_library"], +) diff --git a/examples/sub/BUILD.bazel b/examples/sub/BUILD.bazel new file mode 100644 index 00000000000..399c18f9bb0 --- /dev/null +++ b/examples/sub/BUILD.bazel @@ -0,0 +1,21 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") + +package(default_visibility = ["//visibility:public"]) + +proto_library( + name = "sub_proto", + srcs = ["message.proto"], +) + +go_proto_library( + name = "sub_go_proto", + importpath = "github.com/grpc-ecosystem/grpc-gateway/examples/sub", + proto = ":sub_proto", +) + +go_library( + name = "go_default_library", + embed = [":sub_go_proto"], + importpath = "github.com/grpc-ecosystem/grpc-gateway/examples/sub", +) diff --git a/examples/sub2/BUILD.bazel b/examples/sub2/BUILD.bazel new file mode 100644 index 00000000000..08a67fa7e8d --- /dev/null +++ b/examples/sub2/BUILD.bazel @@ -0,0 +1,21 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") + +package(default_visibility = ["//visibility:public"]) + +proto_library( + name = "sub2_proto", + srcs = ["message.proto"], +) + +go_proto_library( + name = "sub2_go_proto", + importpath = "github.com/grpc-ecosystem/grpc-gateway/examples/sub2", + proto = ":sub2_proto", +) + +go_library( + name = "go_default_library", + embed = [":sub2_go_proto"], + importpath = "github.com/grpc-ecosystem/grpc-gateway/examples/sub2", +) diff --git a/options/BUILD.bazel b/options/BUILD.bazel new file mode 100644 index 00000000000..cb544aaa283 --- /dev/null +++ b/options/BUILD.bazel @@ -0,0 +1,23 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") + +package(default_visibility = ["//visibility:public"]) + +proto_library( + name = "options_proto", + srcs = ["options.proto"], + deps = ["@com_google_protobuf//:descriptor_proto"], +) + +go_proto_library( + name = "options_go_proto", + importpath = "github.com/grpc-ecosystem/grpc-gateway/options", + proto = ":options_proto", + deps = ["@com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library"], +) + +go_library( + name = "go_default_library", + embed = [":options_go_proto"], + importpath = "github.com/grpc-ecosystem/grpc-gateway/options", +) diff --git a/protoc-gen-grpc-gateway/BUILD.bazel b/protoc-gen-grpc-gateway/BUILD.bazel new file mode 100644 index 00000000000..fc4850fb695 --- /dev/null +++ b/protoc-gen-grpc-gateway/BUILD.bazel @@ -0,0 +1,41 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") +load("@io_bazel_rules_go//proto:compiler.bzl", "go_proto_compiler") + +package(default_visibility = ["//visibility:private"]) + +go_library( + name = "go_default_library", + srcs = ["main.go"], + importpath = "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway", + deps = [ + "//codegenerator:go_default_library", + "//protoc-gen-grpc-gateway/descriptor:go_default_library", + "//protoc-gen-grpc-gateway/gengateway:go_default_library", + "@com_github_golang_glog//:go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/plugin:go_default_library", + ], +) + +go_binary( + name = "protoc-gen-grpc-gateway", + embed = [":go_default_library"], +) + +go_proto_compiler( + name = "go_gen_grpc_gateway", + options = ["logtostderr=true"], + plugin = ":protoc-gen-grpc-gateway", + suffix = ".pb.gw.go", + visibility = ["//visibility:public"], + deps = [ + "//runtime:go_default_library", + "//utilities:go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", + "@org_golang_google_grpc//:go_default_library", + "@org_golang_google_grpc//codes:go_default_library", + "@org_golang_google_grpc//grpclog:go_default_library", + "@org_golang_google_grpc//status:go_default_library", + "@org_golang_x_net//context:go_default_library", + ], +) diff --git a/protoc-gen-grpc-gateway/descriptor/BUILD.bazel b/protoc-gen-grpc-gateway/descriptor/BUILD.bazel new file mode 100644 index 00000000000..7c68fa88582 --- /dev/null +++ b/protoc-gen-grpc-gateway/descriptor/BUILD.bazel @@ -0,0 +1,39 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +package(default_visibility = ["//:generators"]) + +go_library( + name = "go_default_library", + srcs = [ + "registry.go", + "services.go", + "types.go", + ], + importpath = "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor", + deps = [ + "//protoc-gen-grpc-gateway/httprule:go_default_library", + "@com_github_golang_glog//:go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/generator:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/plugin:go_default_library", + "@org_golang_google_genproto//googleapis/api/annotations:go_default_library", + ], +) + +go_test( + name = "go_default_test", + size = "small", + srcs = [ + "registry_test.go", + "services_test.go", + "types_test.go", + ], + embed = [":go_default_library"], + deps = [ + "//protoc-gen-grpc-gateway/httprule:go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/plugin:go_default_library", + ], +) diff --git a/protoc-gen-grpc-gateway/generator/BUILD.bazel b/protoc-gen-grpc-gateway/generator/BUILD.bazel new file mode 100644 index 00000000000..5995e5df888 --- /dev/null +++ b/protoc-gen-grpc-gateway/generator/BUILD.bazel @@ -0,0 +1,13 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +package(default_visibility = ["//:generators"]) + +go_library( + name = "go_default_library", + srcs = ["generator.go"], + importpath = "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/generator", + deps = [ + "//protoc-gen-grpc-gateway/descriptor:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/plugin:go_default_library", + ], +) diff --git a/protoc-gen-grpc-gateway/gengateway/BUILD.bazel b/protoc-gen-grpc-gateway/gengateway/BUILD.bazel new file mode 100644 index 00000000000..517909b5046 --- /dev/null +++ b/protoc-gen-grpc-gateway/gengateway/BUILD.bazel @@ -0,0 +1,38 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +package(default_visibility = ["//protoc-gen-grpc-gateway:__subpackages__"]) + +go_library( + name = "go_default_library", + srcs = [ + "doc.go", + "generator.go", + "template.go", + ], + importpath = "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway", + deps = [ + "//protoc-gen-grpc-gateway/descriptor:go_default_library", + "//protoc-gen-grpc-gateway/generator:go_default_library", + "//utilities:go_default_library", + "@com_github_golang_glog//:go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/plugin:go_default_library", + "@org_golang_google_genproto//googleapis/api/annotations:go_default_library", + ], +) + +go_test( + name = "go_default_test", + size = "small", + srcs = [ + "generator_test.go", + "template_test.go", + ], + embed = [":go_default_library"], + deps = [ + "//protoc-gen-grpc-gateway/descriptor:go_default_library", + "//protoc-gen-grpc-gateway/httprule:go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library", + ], +) diff --git a/protoc-gen-grpc-gateway/httprule/BUILD.bazel b/protoc-gen-grpc-gateway/httprule/BUILD.bazel new file mode 100644 index 00000000000..89f94a14b45 --- /dev/null +++ b/protoc-gen-grpc-gateway/httprule/BUILD.bazel @@ -0,0 +1,32 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +package(default_visibility = ["//:generators"]) + +go_library( + name = "go_default_library", + srcs = [ + "compile.go", + "parse.go", + "types.go", + ], + importpath = "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule", + deps = [ + "//utilities:go_default_library", + "@com_github_golang_glog//:go_default_library", + ], +) + +go_test( + name = "go_default_test", + size = "small", + srcs = [ + "compile_test.go", + "parse_test.go", + "types_test.go", + ], + embed = [":go_default_library"], + deps = [ + "//utilities:go_default_library", + "@com_github_golang_glog//:go_default_library", + ], +) diff --git a/protoc-gen-swagger/BUILD.bazel b/protoc-gen-swagger/BUILD.bazel new file mode 100644 index 00000000000..4a76d2f85c4 --- /dev/null +++ b/protoc-gen-swagger/BUILD.bazel @@ -0,0 +1,29 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test") + +package(default_visibility = ["//visibility:private"]) + +go_library( + name = "go_default_library", + srcs = ["main.go"], + importpath = "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger", + deps = [ + "//codegenerator:go_default_library", + "//protoc-gen-grpc-gateway/descriptor:go_default_library", + "//protoc-gen-swagger/genswagger:go_default_library", + "@com_github_golang_glog//:go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/plugin:go_default_library", + ], +) + +go_binary( + name = "protoc-gen-swagger", + embed = [":go_default_library"], +) + +go_test( + name = "go_default_test", + size = "small", + srcs = ["main_test.go"], + embed = [":go_default_library"], +) diff --git a/protoc-gen-swagger/genswagger/BUILD.bazel b/protoc-gen-swagger/genswagger/BUILD.bazel new file mode 100644 index 00000000000..7f34844a7a0 --- /dev/null +++ b/protoc-gen-swagger/genswagger/BUILD.bazel @@ -0,0 +1,37 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +package(default_visibility = ["//protoc-gen-swagger:__subpackages__"]) + +go_library( + name = "go_default_library", + srcs = [ + "doc.go", + "generator.go", + "template.go", + "types.go", + ], + importpath = "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger", + deps = [ + "//protoc-gen-grpc-gateway/descriptor:go_default_library", + "//protoc-gen-grpc-gateway/generator:go_default_library", + "//protoc-gen-swagger/options:go_default_library", + "@com_github_golang_glog//:go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/plugin:go_default_library", + ], +) + +go_test( + name = "go_default_test", + size = "small", + srcs = ["template_test.go"], + embed = [":go_default_library"], + deps = [ + "//protoc-gen-grpc-gateway/descriptor:go_default_library", + "//protoc-gen-grpc-gateway/httprule:go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library", + "@com_github_golang_protobuf//protoc-gen-go/plugin:go_default_library", + ], +) diff --git a/protoc-gen-swagger/options/BUILD.bazel b/protoc-gen-swagger/options/BUILD.bazel new file mode 100644 index 00000000000..476cb59db4b --- /dev/null +++ b/protoc-gen-swagger/options/BUILD.bazel @@ -0,0 +1,33 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") + +package(default_visibility = ["//visibility:public"]) + +proto_library( + name = "options_proto", + srcs = [ + "annotations.proto", + "openapiv2.proto", + ], + deps = [ + "@com_google_protobuf//:any_proto", + "@com_google_protobuf//:descriptor_proto", + ], +) + +go_proto_library( + name = "options_go_proto", + compilers = ["@io_bazel_rules_go//proto:go_grpc"], + importpath = "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options", + proto = ":options_proto", + deps = [ + "@com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library", + "@com_github_golang_protobuf//ptypes/any:go_default_library", + ], +) + +go_library( + name = "go_default_library", + embed = [":options_go_proto"], + importpath = "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options", +) diff --git a/repositories.bzl b/repositories.bzl new file mode 100644 index 00000000000..959b20cfffa --- /dev/null +++ b/repositories.bzl @@ -0,0 +1,49 @@ +GOOGLEAPIS_GOOGLE_API_BUILD_CONTENTS = """ +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") + +package(default_visibility = ["//visibility:public"]) + +proto_library( + name = "api_proto", + srcs = [ + "annotations.proto", + "http.proto", + ], + deps = ["@com_google_protobuf//:descriptor_proto"], +) + +go_proto_library( + name = "api_go_proto", + importpath = "google.golang.org/genproto/googleapis/api/annotations", + proto = ":api_proto", + deps = ["@com_github_golang_protobuf//protoc-gen-go/descriptor:go_default_library"], +) + +go_library( + name = "go_default_library", + embed = [":api_go_proto"], + importpath = "google.golang.org/genproto/googleapis/api/annotations", +) +""" + +def _googleapis_repository_impl(ctx): + googleapis_commit = "e1c0c726290a55065c0c46a62dacc9372939973b" + ctx.download_and_extract( + url = "https://github.com/googleapis/googleapis/archive/{commit}.tar.gz".format( + commit = googleapis_commit, + ), + sha256 = "9508971cb4a7c0fe03bc1bfafbd0abc9654c80b4c70e360a6c534938d06d8fb9", + stripPrefix = "googleapis-{}".format(googleapis_commit), + ) + + ctx.file("google/api/BUILD.bazel", GOOGLEAPIS_GOOGLE_API_BUILD_CONTENTS) + + +_googleapis_repository = repository_rule( + implementation = _googleapis_repository_impl, +) + + +def repositories(): + _googleapis_repository(name = "com_github_googleapis_googleapis") diff --git a/runtime/BUILD.bazel b/runtime/BUILD.bazel new file mode 100644 index 00000000000..e8964f02426 --- /dev/null +++ b/runtime/BUILD.bazel @@ -0,0 +1,82 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +package(default_visibility = ["//visibility:public"]) + +go_library( + name = "go_default_library", + srcs = [ + "context.go", + "convert.go", + "doc.go", + "errors.go", + "handler.go", + "marshal_json.go", + "marshal_jsonpb.go", + "marshal_proto.go", + "marshaler.go", + "marshaler_registry.go", + "mux.go", + "pattern.go", + "proto2_convert.go", + "proto_errors.go", + "query.go", + ], + importpath = "github.com/grpc-ecosystem/grpc-gateway/runtime", + deps = [ + "//runtime/internal:go_default_library", + "//utilities:go_default_library", + "@com_github_golang_protobuf//jsonpb:go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//ptypes:go_default_library", + "@com_github_golang_protobuf//ptypes/any:go_default_library", + "@com_github_golang_protobuf//ptypes/duration:go_default_library", + "@com_github_golang_protobuf//ptypes/timestamp:go_default_library", + "@org_golang_google_grpc//codes:go_default_library", + "@org_golang_google_grpc//grpclog:go_default_library", + "@org_golang_google_grpc//metadata:go_default_library", + "@org_golang_google_grpc//status:go_default_library", + ], +) + +go_test( + name = "go_default_test", + size = "small", + srcs = ["pattern_test.go"], + embed = [":go_default_library"], + deps = ["//utilities:go_default_library"], +) + +go_test( + name = "go_default_xtest", + size = "small", + srcs = [ + "context_test.go", + "errors_test.go", + "handler_test.go", + "marshal_json_test.go", + "marshal_jsonpb_test.go", + "marshal_proto_test.go", + "marshaler_registry_test.go", + "mux_test.go", + "query_test.go", + ], + deps = [ + ":go_default_library", + "//examples/examplepb:go_default_library", + "//runtime/internal:go_default_library", + "//utilities:go_default_library", + "@com_github_golang_protobuf//jsonpb:go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_golang_protobuf//ptypes:go_default_library", + "@com_github_golang_protobuf//ptypes/duration:go_default_library", + "@com_github_golang_protobuf//ptypes/empty:go_default_library", + "@com_github_golang_protobuf//ptypes/struct:go_default_library", + "@com_github_golang_protobuf//ptypes/timestamp:go_default_library", + "@com_github_golang_protobuf//ptypes/wrappers:go_default_library", + "@org_golang_google_genproto//protobuf/field_mask:go_default_library", + "@org_golang_google_grpc//:go_default_library", + "@org_golang_google_grpc//codes:go_default_library", + "@org_golang_google_grpc//metadata:go_default_library", + "@org_golang_google_grpc//status:go_default_library", + ], +) diff --git a/runtime/internal/BUILD.bazel b/runtime/internal/BUILD.bazel new file mode 100644 index 00000000000..937e66089ee --- /dev/null +++ b/runtime/internal/BUILD.bazel @@ -0,0 +1,23 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") + +package(default_visibility = ["//runtime:__subpackages__"]) + +proto_library( + name = "internal_proto", + srcs = ["stream_chunk.proto"], + deps = ["@com_google_protobuf//:any_proto"], +) + +go_proto_library( + name = "internal_go_proto", + importpath = "github.com/grpc-ecosystem/grpc-gateway/runtime/internal", + proto = ":internal_proto", + deps = ["@com_github_golang_protobuf//ptypes/any:go_default_library"], +) + +go_library( + name = "go_default_library", + embed = [":internal_go_proto"], + importpath = "github.com/grpc-ecosystem/grpc-gateway/runtime/internal", +) diff --git a/utilities/BUILD.bazel b/utilities/BUILD.bazel new file mode 100644 index 00000000000..58d291c3738 --- /dev/null +++ b/utilities/BUILD.bazel @@ -0,0 +1,20 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +package(default_visibility = ["//visibility:public"]) + +go_library( + name = "go_default_library", + srcs = [ + "doc.go", + "pattern.go", + "trie.go", + ], + importpath = "github.com/grpc-ecosystem/grpc-gateway/utilities", +) + +go_test( + name = "go_default_xtest", + size = "small", + srcs = ["trie_test.go"], + deps = [":go_default_library"], +)