examples: add bazel build example

## Bazel

If you prefer to use Bazel:
```
(With Bazel v0.4.5 or above.)
$ bazel build :hello-world-server :hello-world-client
$ # Run the server:
$ bazel-bin/hello-world-server
$ # In another terminal run the client
$ bazel-bin/hello-world-client
```
This commit is contained in:
ZHANG Dapeng 2017-06-29 12:25:54 -07:00 committed by GitHub
parent 8f75f8ee7c
commit 36f7b34b6e
4 changed files with 128 additions and 0 deletions

1
.gitignore vendored
View File

@ -9,6 +9,7 @@ target
# Bazel # Bazel
bazel-bin bazel-bin
bazel-examples
bazel-genfiles bazel-genfiles
bazel-grpc-java bazel-grpc-java
bazel-out bazel-out

98
examples/BUILD.bazel Normal file
View File

@ -0,0 +1,98 @@
load("@grpc_java//:java_grpc_library.bzl", "java_grpc_library")
proto_library(
name = "helloworld_proto",
srcs = ["src/main/proto/helloworld.proto"],
)
java_proto_library(
name = "helloworld_java_proto",
deps = [":helloworld_proto"],
)
java_grpc_library(
name = "helloworld_java_grpc",
srcs = [":helloworld_proto"],
deps = [":helloworld_java_proto"],
)
proto_library(
name = "route_guide_proto",
srcs = ["src/main/proto/route_guide.proto"],
)
java_proto_library(
name = "route_guide_java_proto",
deps = [":route_guide_proto"],
)
java_grpc_library(
name = "route_guide_java_grpc",
srcs = [":route_guide_proto"],
deps = [":route_guide_java_proto"],
)
java_library(
name = "examples",
testonly = 1,
srcs = glob(
["src/main/java/**/*.java"],
),
resources = glob(
["src/main/resources/**"],
),
deps = [
":helloworld_java_grpc",
":helloworld_java_proto",
":route_guide_java_grpc",
":route_guide_java_proto",
"@com_google_api_grpc_google_common_protos//jar",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava//jar",
"@com_google_protobuf//:protobuf_java_util",
"@com_google_protobuf_java//:protobuf_java",
"@grpc_java//protobuf",
"@grpc_java//core",
"@grpc_java//stub",
],
)
java_binary(
name = "hello-world-client",
testonly = 1,
main_class = "io.grpc.examples.helloworld.HelloWorldClient",
runtime_deps = [
":examples",
"@grpc_java//netty",
],
)
java_binary(
name = "hello-world-server",
testonly = 1,
main_class = "io.grpc.examples.helloworld.HelloWorldServer",
runtime_deps = [
":examples",
"@grpc_java//netty",
],
)
java_binary(
name = "route-guide-client",
testonly = 1,
main_class = "io.grpc.examples.routeguide.RouteGuideClient",
runtime_deps = [
":examples",
"@grpc_java//netty",
],
)
java_binary(
name = "route-guide-server",
testonly = 1,
main_class = "io.grpc.examples.routeguide.RouteGuideServer",
runtime_deps = [
":examples",
"@grpc_java//netty",
],
)

View File

@ -49,6 +49,18 @@ $ # In another terminal run the client
$ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworld.HelloWorldClient $ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworld.HelloWorldClient
``` ```
## Bazel
If you prefer to use Bazel:
```
(With Bazel v0.4.5 or above.)
$ bazel build :hello-world-server :hello-world-client
$ # Run the server:
$ bazel-bin/hello-world-server
$ # In another terminal run the client
$ bazel-bin/hello-world-client
```
Unit test examples Unit test examples
============================================== ==============================================

17
examples/WORKSPACE Normal file
View File

@ -0,0 +1,17 @@
workspace(name = "examples")
# For released versions, use the tagged git-repository:
# git_repository(
# name = "grpc_java",
# remote = "https://github.com/grpc/grpc-java.git",
# tag = "<TAG>",
# )
local_repository(
name = "grpc_java",
path = "..",
)
load("@grpc_java//:repositories.bzl", "grpc_java_repositories")
grpc_java_repositories()