Skip to content

Commit 51742fe

Browse files
committed
Adds nodejs support.
1 parent 11b15ff commit 51742fe

File tree

15 files changed

+277
-26
lines changed

15 files changed

+277
-26
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ os:
66
# - osx
77

88
env:
9-
- V=HEAD URL=http://ci.bazel.io/job/Bazel/JAVA_VERSION=1.8,PLATFORM_NAME=linux-x86_64/lastSuccessfulBuild/artifact/output/ci/bazel--installer.sh FLAGS='--worker_verbose --strategy=Javac=worker --strategy=JsChecker=worker'
9+
- V=0.3.2rc3 URL=https://storage.googleapis.com/bazel/0.3.2/rc3/bazel-0.3.2rc3-installer-linux-x86_64.sh FLAGS=''
1010
- V=0.3.1 URL=https://github.com/bazelbuild/bazel/releases/download/0.3.1/bazel-0.3.1-installer-linux-x86_64.sh FLAGS=''
1111

1212
before_install:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ of this project are to:
4747
| [Go (gogo)](gogo) | [gogo_proto_compile](gogo#gogo_proto_compile) | [gogo_proto_library](gogo#gogo_proto_library) | [v1.0.0](https://github.com/grpc/grpc-go/releases/tag/v1.0.0) |
4848
| [gRPC gateway](grpc_gateway) | [grpc_gateway_proto_compile](grpc_gateway#grpc_gateway_proto_compile)<br/>[grpc_gateway_swagger_compile](grpc_gateway#grpc_gateway_swagger_compile) | [grpc_gateway_proto_library](grpc_gateway#grpc_gateway_proto_library)<br/>[grpc_gateway_binary](grpc_gateway#grpc_gateway_binary) | [v1.0.0](https://github.com/grpc/grpc-go/releases/tag/v1.0.0) |
4949
| [Java](java) | [java_proto_compile](java#java_proto_compile) | [java_proto_library](java#java_proto_library) | [v1.0.1](https://github.com/grpc/grpc-java/releases/tag/v1.0.1) |
50-
| [Node](node) | [node_proto_compile](js#node_proto_compile) | | <sup>4</sup> |
50+
| [Node](node) | [node_proto_compile](js#node_proto_compile) | [node_proto_library](js#node_proto_library) | [1.0.0](https://www.npmjs.com/package/grpc) |
5151
| [Objective-C](objc) | [objc_proto_compile](objc#objc_proto_compile) | [objc_proto_library](objc#objc_proto_library) <sup>5</sup> | <sup>4</sup> |
5252
| [Python](python) | [py_proto_compile](python#py_proto_compile) | | <sup>4</sup> |
5353
| [Ruby](ruby) | [ruby_proto_compile](ruby#ruby_proto_compile) | | <sup>4</sup> |
@@ -112,6 +112,7 @@ to load before the `*_proto_repositories()` function is invoked:
112112
| grpc_gateway_proto_repositories | [rules_go](https://github.com/bazelbuild/rules_go) |
113113
| closure_proto_repositories | [rules_closure](https://github.com/bazelbuild/rules_closure) |
114114
| csharp_proto_repositories | [rules_dotnet](https://github.com/bazelbuild/rules_dotnet) |
115+
| node_proto_repositories | [rules_node](https://github.com/pubref/rules_node) |
115116

116117
If you're only interested in the `proto_compile` rule and not any
117118
language-specific rules, just load the generic `proto_repositories`

WORKSPACE

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
3030
closure_repositories()
3131

3232
# ================================================================
33-
# csharp_proto_library support requires rules_dotnet (fork)
33+
# csharp_proto_library support requires rules_dotnet (forked)
3434
# ================================================================
3535

3636
git_repository(
@@ -40,9 +40,27 @@ git_repository(
4040
)
4141

4242
load("@io_bazel_rules_dotnet//dotnet:csharp.bzl", "csharp_repositories")
43-
4443
csharp_repositories(use_local_mono = False)
4544

45+
46+
# ================================================================
47+
# node_proto_library support requires rules_node
48+
# ================================================================
49+
50+
# local_repository(
51+
# name = "org_pubref_rules_node",
52+
# path = "/Users/pcj/github/rules_node",
53+
# )
54+
55+
git_repository(
56+
name = "org_pubref_rules_node",
57+
remote = "https://github.com/pubref/rules_node.git",
58+
commit = "d93a80ac4920c52da8adccbca66a3118a27018fd", # Oct 2, 2016
59+
)
60+
61+
load("@org_pubref_rules_node//node:rules.bzl", "node_repositories")
62+
node_repositories()
63+
4664
# ================================================================
4765
# Specific Languages Support
4866
# ================================================================
@@ -53,6 +71,9 @@ proto_repositories()
5371
load("//cpp:rules.bzl", "cpp_proto_repositories")
5472
cpp_proto_repositories()
5573

74+
load("//csharp:rules.bzl", "csharp_proto_repositories")
75+
csharp_proto_repositories()
76+
5677
load("//java:rules.bzl", "java_proto_repositories", "nano_proto_repositories")
5778
java_proto_repositories()
5879
nano_proto_repositories()
@@ -63,11 +84,11 @@ go_proto_repositories()
6384
load("//gogo:rules.bzl", "gogo_proto_repositories")
6485
gogo_proto_repositories()
6586

66-
load("//csharp:rules.bzl", "csharp_proto_repositories")
67-
csharp_proto_repositories()
87+
load("//grpc_gateway:rules.bzl", "grpc_gateway_proto_repositories")
88+
grpc_gateway_proto_repositories()
89+
90+
load("//node:rules.bzl", "node_proto_repositories")
91+
node_proto_repositories()
6892

6993
load("//objc:rules.bzl", "objc_proto_repositories")
7094
objc_proto_repositories()
71-
72-
load("//grpc_gateway:rules.bzl", "grpc_gateway_proto_repositories")
73-
grpc_gateway_proto_repositories()

cpp/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ proto_language(
1111
supports_grpc = True,
1212
grpc_file_extensions = [".grpc.pb.h", ".grpc.pb.cc"],
1313
grpc_plugin = "//external:protoc_gen_grpc_cpp",
14-
grpc_plugin_name = "grpc",
14+
grpc_plugin_name = "grpc_cpp",
1515
grpc_compile_deps = [
1616
'@com_github_grpc_grpc//:grpc++',
1717
],

examples/helloworld/node/BUILD

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
load("@org_pubref_rules_node//node:rules.bzl", "node_binary")
2+
3+
# Server works, but not the the client (for reasons I dont yet
4+
# understand)
5+
6+
node_binary(
7+
name = "client",
8+
main = "greeter_client.js",
9+
deps = [
10+
"//examples/helloworld/proto:node",
11+
],
12+
modules = [
13+
"@npm_protobuf_stack//:modules",
14+
"@npm_grpc//:modules",
15+
],
16+
)
17+
18+
node_binary(
19+
name = "server",
20+
main = "greeter_server.js",
21+
deps = [
22+
"//examples/helloworld/proto:node",
23+
],
24+
modules = [
25+
"@npm_protobuf_stack//:modules",
26+
"@npm_grpc//:modules",
27+
],
28+
)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const jspb = require('google-protobuf');
4+
const grpc = require('grpc');
5+
const messages = require('examples-helloworld-proto-node');
6+
const services_path = path.dirname(require.resolve('examples-helloworld-proto-node'));
7+
const services = require(services_path + '/helloworld_grpc_pb');
8+
9+
function main() {
10+
console.log("Running main");
11+
var cred = grpc.credentials.createInsecure()
12+
console.log(cred.constructor.classname)
13+
console.log("grpc.credentials: " + cred)
14+
var client = new services.GreeterClient('localhost:50051', cred);
15+
var user;
16+
if (process.argv.length >= 3) {
17+
user = process.argv[2];
18+
} else {
19+
user = 'world';
20+
}
21+
22+
client.sayHello(request, function(err, response) {
23+
console.log('Greeting:', response.getMessage());
24+
});
25+
26+
27+
// var user = "Foo";
28+
// var request = new messages.HelloRequest();
29+
// request.setName(user);
30+
// console.log("Hello " + request.getName());
31+
32+
}
33+
34+
main();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const path = require('path')
2+
const messages = require('examples-helloworld-proto-node');
3+
const services_path = path.dirname(require.resolve('examples-helloworld-proto-node'));
4+
const services = require(services_path + '/helloworld_grpc_pb');
5+
6+
var grpc = require('grpc');
7+
8+
/**
9+
* Implements the SayHello RPC method.
10+
*/
11+
function sayHello(call, callback) {
12+
var reply = new messages.HelloReply();
13+
reply.setMessage('Hello ' + call.request.getName());
14+
callback(null, reply);
15+
}
16+
17+
/**
18+
* Starts an RPC server that receives requests for the Greeter service at the
19+
* sample server port
20+
*/
21+
function main() {
22+
var server = new grpc.Server();
23+
server.addService(services.GreeterService, {sayHello: sayHello});
24+
server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
25+
server.start();
26+
}
27+
28+
main();

examples/helloworld/proto/BUILD

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ load("//go:rules.bzl", "go_proto_library")
66
load("//gogo:rules.bzl", "gogo_proto_library")
77
load("//java:rules.bzl", "java_proto_library")
88
load("//csharp:rules.bzl", "csharp_proto_library")
9+
load("//node:rules.bzl", "node_proto_library")
910

1011
filegroup(
1112
name = "protos",
@@ -44,9 +45,18 @@ cc_proto_library(
4445
with_grpc = True,
4546
)
4647

48+
node_proto_library(
49+
name = "node",
50+
proto_deps = [
51+
"//examples/proto:node",
52+
],
53+
protos = [":protos"],
54+
verbose = 0,
55+
with_grpc = True,
56+
)
57+
4758
java_proto_library(
4859
name = "java",
49-
output_to_workspace = False,
5060
proto_deps = [
5161
"//examples/proto:java",
5262
],
@@ -58,15 +68,14 @@ java_proto_library(
5868
proto_compile(
5969
name = "py",
6070
langs = ["//python"],
61-
output_to_workspace = False,
6271
protos = [":protos"],
63-
with_grpc = False,
72+
with_grpc = True,
73+
verbose = 1,
6474
)
6575

6676
proto_compile(
6777
name = "ruby",
6878
langs = ["//ruby"],
69-
output_to_workspace = False,
7079
protos = [":protos"],
7180
with_grpc = False,
7281
)

examples/proto/BUILD

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ load("//csharp:rules.bzl", "csharp_proto_compile", "csharp_proto_library")
66
load("//go:rules.bzl", "go_proto_library")
77
load("//java:rules.bzl", "java_proto_library")
88
load("//closure:rules.bzl", "closure_proto_library")
9-
load("//node:rules.bzl", "node_proto_compile")
9+
load("//node:rules.bzl", "node_proto_compile", "node_proto_library")
1010
load("//objc:rules.bzl", "objc_proto_library")
1111

1212
filegroup(
@@ -47,11 +47,18 @@ csharp_proto_library(
4747
verbose = 0,
4848
)
4949

50+
node_proto_library(
51+
name = "node",
52+
protos = [":protos"],
53+
with_grpc = False,
54+
verbose = 0,
55+
)
56+
5057
# This conflicts with outputs from other rules here but demonstrates
5158
# how to generate multiple language outputs simultaneously.
52-
59+
#
5360
# proto_compile(
54-
# name = "pluri",
61+
# name = "pluriproto",
5562
# protos = [":protos"],
5663
# langs = [
5764
# "//ruby",
@@ -61,6 +68,8 @@ csharp_proto_library(
6168
# "//cpp",
6269
# "//objc",
6370
# "//closure",
71+
# "//csharp",
72+
# "//go",
6473
# "//node",
6574
# ],
6675
# verbose = 2,

node/BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ proto_language(
88
pb_file_extensions = ["_pb.js"],
99
pb_options = [
1010
"import_style=commonjs",
11-
"error_on_name_conflict",
1211
"binary",
1312
],
13+
supports_grpc = True,
14+
grpc_file_extensions = ["_grpc_pb.js"],
15+
grpc_plugin = "@com_github_grpc_grpc//:grpc_node_plugin",
16+
grpc_plugin_name = "grpc_node",
1417
)

0 commit comments

Comments
 (0)