Skip to content
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

examples: add bazel build example #3150

Merged
merged 2 commits into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
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
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
98 changes: 98 additions & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work, because you can only have one bazel in a workspace running at a time. Instead do the following?

$ 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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh! Corrected and tried.

```

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()