Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.0.0
11 changes: 11 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
filegroup(
name = "all_files",
testonly = True,
srcs = [
"BUILD.bazel",
"WORKSPACE",
"//protoc-gen-grpc-js:all_files",
"//rules:all_files",
] + glob(["*.bzl"]),
visibility = ["//visibility:public"],
)
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PHONY: goldens
goldens:
find . -name '*.prototext' | xargs rm
./tools/regenerate_golden_files.sh
91 changes: 66 additions & 25 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,37 +1,78 @@
workspace(name = "com_github_stackb_grpc_js")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
local_repository(
name = "build_stack_rules_proto",
path = "../rules_proto",
)

http_archive(
name = "bazel_skylib",
sha256 = "bbccf674aa441c266df9894182d80de104cabd19be98be002f6d478aaa31574d",
strip_prefix = "bazel-skylib-2169ae1c374aab4a09aa90e65efe1a3aad4e279b",
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"],
load(
"@build_stack_rules_proto//:deps.bzl",
"bazel_gazelle",
"bazel_skylib",
"com_github_grpc_grpc",
"com_google_protobuf",
"io_bazel_rules_closure",
"io_bazel_rules_go",
"rules_cc",
"zlib",
)

# ================================================================
# ==================================================
# C++
# ==================================================
#
rules_cc()

RULES_CLOSURE_VERSION = "50d3dc9e6d27a5577a0f95708466718825d579f4"
# ==================================================
# Go
# ==================================================
#
io_bazel_rules_go()

http_archive(
name = "io_bazel_rules_closure",
url = "https://github.com/bazelbuild/rules_closure/archive/%s.zip" % RULES_CLOSURE_VERSION,
strip_prefix = "rules_closure-%s" % RULES_CLOSURE_VERSION,
)
bazel_gazelle()

http_archive(
name = "net_zlib",
build_file = "@io_bazel_rules_closure//:third_party/zlib.BUILD",
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
strip_prefix = "zlib-1.2.11",
urls = ["https://zlib.net/zlib-1.2.11.tar.gz"],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains()

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

gazelle_dependencies()

bind(
name = "zlib",
actual = "@net_zlib//:zlib",
# ==================================================
# closure
# ==================================================
#
io_bazel_rules_closure()

load("@io_bazel_rules_closure//closure:repositories.bzl", "rules_closure_dependencies", "rules_closure_toolchains")

rules_closure_dependencies(
omit_bazel_skylib = True,
omit_com_google_protobuf = True,
omit_zlib = True,
)

load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
rules_closure_toolchains()

# ==================================================
# Protobuf
# ==================================================
#
com_google_protobuf()

bazel_skylib()

zlib()

# ==================================================
# gRPC
# ==================================================
#
com_github_grpc_grpc()

load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")

closure_repositories()
grpc_deps()
18 changes: 18 additions & 0 deletions protoc-gen-grpc-js/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@build_stack_rules_proto//rules:proto_plugin.bzl", "proto_plugin")

package(default_visibility = ["//visibility:public"])

proto_plugin(
name = "grpc_js",
exclusions = ["google/protobuf"], # TODO(pcj): is this needed?
outputs = ["{protopath}.grpc.js"],
tool = ":protoc-gen-grpc-js",
visibility = ["//visibility:public"],
)

cc_binary(
name = "protoc-gen-grpc-js",
srcs = [
Expand All @@ -9,3 +20,10 @@ cc_binary(
"@com_google_protobuf//:protoc_lib",
],
)

filegroup(
name = "all_files",
testonly = True,
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
8 changes: 8 additions & 0 deletions rules/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
filegroup(
name = "all_files",
testonly = True,
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)

exports_files(glob(["*.bzl"]))
6 changes: 6 additions & 0 deletions rules/grpc_js.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# rules for grpc_js
load("@build_stack_rules_proto//rules:grpc_js_grpc_compile.bzl", _grpc_js_grpc_compile = "grpc_js_grpc_compile")
load("@build_stack_rules_proto//rules:grpc_js_grpc_library.bzl", _grpc_js_grpc_library = "grpc_js_grpc_library")

grpc_js_grpc_compile = _grpc_js_grpc_compile
grpc_js_grpc_library = _grpc_js_grpc_library
18 changes: 18 additions & 0 deletions rules/grpc_js_grpc_compile.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load(
"@build_stack_rules_proto//rules:proto_aspect.bzl",
"proto_compile_aspect",
"proto_compile_rule_macro",
"proto_compile_rule",
)

_default_plugins = [
str(Label("@build_stack_rules_proto//plugins/closure/proto:proto")),
str(Label("//protoc-gen-grpc-js:grpc_js")),
]

_grpc_js_grpc_compile_aspect = proto_compile_aspect(_default_plugins, "grpc_js_grpc_compile_aspect")

_grpc_js_grpc_compile_rule = proto_compile_rule(_grpc_js_grpc_compile_aspect)

def grpc_js_grpc_compile(**kwargs):
proto_compile_rule_macro(_grpc_js_grpc_compile_rule, **kwargs)
66 changes: 66 additions & 0 deletions rules/grpc_js_grpc_compile_deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")

def _maybe(repo_rule, name, **kwargs):
if name not in native.existing_rules():
repo_rule(name = name, **kwargs)

def grpc_js_grpc_compile_deps():
bazel_skylib()
rules_python()
zlib()
com_github_stackb_grpc_js()
com_google_protobuf()


def bazel_skylib():
_maybe(
http_archive,
name = "bazel_skylib",
sha256 = "ebdf850bfef28d923a2cc67ddca86355a449b5e4f38b0a70e584dc24e5984aa6",
strip_prefix = "bazel-skylib-f80bc733d4b9f83d427ce3442be2e07427b2cc8d",
urls = [
"https://github.com/bazelbuild/bazel-skylib/archive/f80bc733d4b9f83d427ce3442be2e07427b2cc8d.tar.gz",
],
)
def rules_python():
_maybe(
http_archive,
name = "rules_python",
sha256 = "8cc0ad31c8fc699a49ad31628273529ef8929ded0a0859a3d841ce711a9a90d5",
strip_prefix = "rules_python-c7e068d38e2fec1d899e1c150e372f205c220e27",
urls = [
"https://github.com/bazelbuild/rules_python/archive/c7e068d38e2fec1d899e1c150e372f205c220e27.tar.gz",
],
)
def zlib():
_maybe(
http_archive,
name = "zlib",
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
strip_prefix = "zlib-1.2.11",
urls = [
"https://mirror.bazel.build/zlib.net/zlib-1.2.11.tar.gz",
"https://zlib.net/zlib-1.2.11.tar.gz",
],
build_file = "@build_stack_rules_proto//third_party:BUILD.bazel.zlib",
)
def com_github_stackb_grpc_js():
_maybe(
http_archive,
name = "com_github_stackb_grpc_js",
sha256 = "f9cb4d932badc71d90a89263eabc93551923bb5c621e0940c7cfeaa79ef02596",
strip_prefix = "grpc.js-beb6ac3b43247816c1a1ebf741ebf0c98203414a",
urls = [
"https://github.com/stackb/grpc.js/archive/beb6ac3b43247816c1a1ebf741ebf0c98203414a.tar.gz",
],
)
def com_google_protobuf():
_maybe(
http_archive,
name = "com_google_protobuf",
sha256 = "d0f5f605d0d656007ce6c8b5a82df3037e1d8fe8b121ed42e536f569dec16113",
strip_prefix = "protobuf-3.14.0",
urls = [
"https://github.com/protocolbuffers/protobuf/archive/v3.14.0.tar.gz",
],
)
91 changes: 91 additions & 0 deletions rules/grpc_js_grpc_library.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
load(
"@build_stack_rules_proto//rules:grpc_js_grpc_compile.bzl",
"grpc_js_grpc_compile",
)

load("@build_stack_rules_proto//rules:closure.bzl", "closure_proto_compile")

load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")

PROTO_DEPS = ["@io_bazel_rules_closure//closure/protobuf:jspb"]

def grpc_js_grpc_library(**kwargs):

name = kwargs.get("name")
name_pb = name + "_pb"
name_pb_lib = name + "_pb_lib"
name_pb_grpc = name + "_pb_grpc"

closure_deps = kwargs.pop("closure_deps", [])
deps = kwargs.get("deps", [])
verbose = kwargs.pop("verbose", 0)
visibility = kwargs.get("visibility", [])
tags = kwargs.get("tags", [])

closure_proto_compile(
name = name_pb,
deps = deps,
visibility = visibility,
verbose = verbose,
tags = tags,
)

grpc_js_grpc_compile(
name = name_pb_grpc,
deps = deps,
visibility = visibility,
verbose = verbose,
tags = tags,
)

closure_js_library(
name = name_pb_lib,
srcs = [name_pb],
deps = [
"@io_bazel_rules_closure//closure/protobuf:jspb",
] + closure_deps,
internal_descriptors = [
name_pb + "/descriptor.source.bin",
],
suppress = [
"JSC_LATE_PROVIDE_ERROR",
"JSC_UNDEFINED_VARIABLE",
"JSC_IMPLICITLY_NULLABLE_JSDOC",
"JSC_STRICT_INEXISTENT_PROPERTY",
"JSC_POSSIBLE_INEXISTENT_PROPERTY",
"JSC_UNRECOGNIZED_TYPE_ERROR",
# "stricterMissingRequireType",
# "analyzerChecks",
# "analyzerChecksInternal",
],
tags = tags,
visibility = visibility,
)

closure_js_library(
name = name,
srcs = [name_pb_grpc],
deps = [
name_pb_lib,
"@io_bazel_rules_closure//closure/library/promise",
"@com_github_stackb_grpc_js//js/grpc/stream/observer:call",
"@com_github_stackb_grpc_js//js/grpc",
"@com_github_stackb_grpc_js//js/grpc:api",
"@com_github_stackb_grpc_js//js/grpc:options",
] + closure_deps,
internal_descriptors = [
name_pb + "/descriptor.source.bin",
name_pb_grpc + "/descriptor.source.bin",
],
exports = [
name_pb_lib,
],
suppress = [
"JSC_IMPLICITLY_NULLABLE_JSDOC",
# "stricterMissingRequireType",
# "analyzerChecks",
# "analyzerChecksInternal",
],
tags = tags,
visibility = visibility,
)
Loading