Skip to content

Commit

Permalink
examples: add bazel build
Browse files Browse the repository at this point in the history
  • Loading branch information
dapengzhang0 committed Jun 28, 2017
1 parent 4b94237 commit 7de9c2d
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ target

# Bazel
bazel-bin
bazel-examples
bazel-genfiles
bazel-grpc-java
bazel-out
Expand Down
95 changes: 95 additions & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
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",
],
)
11 changes: 11 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ $ # In another terminal run the client
$ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworld.HelloWorldClient
```

## Bazel

If you prefer to use Bazel:
```
(With Bazel v0.4.5 or above.)
$ # Run the server:
$ bazel run //:hello-world-server
$ # In another terminal run the client
$ bazel run //:hello-world-client
```

Unit test examples
==============================================

Expand Down
17 changes: 17 additions & 0 deletions examples/WORKSPACE
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 7de9c2d

Please sign in to comment.