Skip to content

Commit 9653402

Browse files
aarnphmssheng
andauthored
docs: gRPC advanced guides (bentoml#3034)
Advanced guides Provide snippets to quickly test and run client implementation with bazel. Signed-off-by: Aaron Pham <[email protected]> Co-authored-by: Sean Sheng <[email protected]>
1 parent 7ddfca4 commit 9653402

File tree

90 files changed

+5267
-201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+5267
-201
lines changed

.bazelignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
grpc-client/java/src/main/java/com/bentoml
2+
grpc-client/kotlin/src/main/kotlin/com/bentoml
3+
grpc-client/js/bentoml
4+
grpc-client/go/bentoml
5+
grpc-client/swift/Sources/bentoml
6+
**/*/node_modules
7+
grpc-client/thirdparty

.bazelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# load bazelrc from the legacy location as recommended
2+
# in https://github.com/bazelbuild/bazel/issues/6319
3+
import %workspace%/tools/bazel.rc

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,35 @@ catboost_info
117117

118118
# ignore pyvenv
119119
pyvenv.cfg
120+
121+
# bazel generated files
122+
bazel-*
123+
cpp/bentoml
124+
go/bentoml
125+
node/bentoml
126+
node_modules
127+
thirdparty
128+
129+
# Swift-related
130+
swift/**/*/bentoml
131+
.DS_Store
132+
/.build
133+
/Packages
134+
/*.xcodeproj
135+
xcuserdata/
136+
DerivedData/
137+
.swiftpm/config/registries.json
138+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
139+
.netrc
140+
Package.resolved
141+
142+
# Java-Kotlin
143+
**/*/java/**/*/bentoml
144+
**/*/kotlin/**/*/bentoml
145+
.gradle
146+
147+
# PHP generated stubs
148+
**/*/php/Bentoml
149+
**/*/php/GPBMetadata
150+
composer.lock
151+
vendor

BUILD.bazel

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
4+
5+
buildifier(
6+
name = "buildifier",
7+
)
8+
9+
# Create a generated proto library
10+
load("@rules_proto//proto:defs.bzl", "proto_library")
11+
12+
proto_library(
13+
name = "service_v1alpha1_proto",
14+
srcs = ["bentoml/grpc/v1alpha1/service.proto"],
15+
visibility = ["//grpc-client:__subpackages__"],
16+
deps = [
17+
"@com_google_protobuf//:struct_proto",
18+
"@com_google_protobuf//:wrappers_proto",
19+
],
20+
)

DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,5 +450,5 @@ your pull request.
450450

451451
## Documentations
452452

453-
Refers to [BentoML Documentation Guide](./docs/README.md) for how to build and write
453+
Refer to [BentoML Documentation Guide](./docs/README.md) for how to build and write
454454
docs.

MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ exclude *.yml *.yaml
55
exclude .git*
66
exclude bentoml/grpc/buf.yaml
77
exclude bentoml/_internal/frameworks/FRAMEWORK_TEMPLATE_PY
8+
exclude .bazelignore
9+
exclude .bazelrc
10+
exclude BUILD WORKSPACE
811

912
# Directories to exclude in PyPI package
1013
prune .devcontainer
@@ -20,6 +23,8 @@ prune */__pycache__
2023
prune */.DS_Store
2124
prune */.ipynb_checkpoints
2225
prune **/*/README*
26+
prune bazel-*
27+
prune grpc-client
2328

2429
# Patterns to exclude from any directory
2530
global-exclude *.py[cod]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ install-docs-deps: ## Install documentation dependencies
6969

7070
# Docs
7171
watch-docs: install-docs-deps ## Build and watch documentation
72-
sphinx-autobuild docs/source docs/build/html --watch $(GIT_ROOT)/bentoml
72+
sphinx-autobuild docs/source docs/build/html --watch $(GIT_ROOT)/bentoml --ignore "bazel-*"
7373
spellcheck-docs: ## Spell check documentation
7474
sphinx-build -b spelling ./docs/source ./docs/build || (echo "Error running spellchecker.. You may need to run 'make install-spellchecker-deps'"; exit 1)
7575

WORKSPACE

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
workspace(name = "bentoml")
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
# install buildifier
6+
http_archive(
7+
name = "com_github_bazelbuild_buildtools",
8+
sha256 = "ae34c344514e08c23e90da0e2d6cb700fcd28e80c02e23e4d5715dddcb42f7b3",
9+
strip_prefix = "buildtools-4.2.2",
10+
urls = [
11+
"https://github.com/bazelbuild/buildtools/archive/refs/tags/4.2.2.tar.gz",
12+
],
13+
)
14+
15+
# setup rules_proto and rules_proto_grpc
16+
http_archive(
17+
name = "rules_proto",
18+
sha256 = "e017528fd1c91c5a33f15493e3a398181a9e821a804eb7ff5acdd1d2d6c2b18d",
19+
strip_prefix = "rules_proto-4.0.0-3.20.0",
20+
urls = [
21+
"https://github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0-3.20.0.tar.gz",
22+
],
23+
)
24+
25+
http_archive(
26+
name = "rules_proto_grpc",
27+
sha256 = "507e38c8d95c7efa4f3b1c0595a8e8f139c885cb41a76cab7e20e4e67ae87731",
28+
strip_prefix = "rules_proto_grpc-4.1.1",
29+
urls = ["https://github.com/rules-proto-grpc/rules_proto_grpc/archive/4.1.1.tar.gz"],
30+
)
31+
32+
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
33+
load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_repos", "rules_proto_grpc_toolchains")
34+
35+
rules_proto_grpc_toolchains()
36+
37+
rules_proto_grpc_repos()
38+
39+
rules_proto_dependencies()
40+
41+
rules_proto_toolchains()
42+
43+
# We need to load go_grpc rules first
44+
load("@rules_proto_grpc//:repositories.bzl", "bazel_gazelle", "io_bazel_rules_go") # buildifier: disable=same-origin-load
45+
46+
io_bazel_rules_go()
47+
48+
bazel_gazelle()
49+
50+
load("@rules_proto_grpc//go:repositories.bzl", rules_proto_grpc_go_repos = "go_repos")
51+
52+
rules_proto_grpc_go_repos()
53+
54+
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
55+
56+
go_rules_dependencies()
57+
58+
go_register_toolchains(version = "1.19")
59+
60+
# grpc/grpc dependencies
61+
# Currently c3714eced8c51db9092e0adc2a1dfb715655c795 address
62+
# some build issues with upb for C++.
63+
# TODO: Update this to v1.50.0 when 1.50.0 is out.
64+
http_archive(
65+
name = "com_github_grpc_grpc",
66+
strip_prefix = "grpc-c3714eced8c51db9092e0adc2a1dfb715655c795",
67+
urls = [
68+
"https://github.com/grpc/grpc/archive/c3714eced8c51db9092e0adc2a1dfb715655c795.tar.gz",
69+
],
70+
)
71+
72+
# Override the abseil-cpp version defined in grpc_deps(), which doesn't work on latest macOS
73+
# Fixes https://github.com/bazelbuild/bazel/issues/15168
74+
# This section is excerpted from https://github.com/bazelbuild/bazel/blob/master/distdir_deps.bzl
75+
http_archive(
76+
name = "com_google_absl",
77+
sha256 = "dcf71b9cba8dc0ca9940c4b316a0c796be8fab42b070bb6b7cab62b48f0e66c4",
78+
strip_prefix = "abseil-cpp-20211102.0",
79+
urls = [
80+
"https://mirror.bazel.build/github.com/abseil/abseil-cpp/archive/refs/tags/20211102.0.tar.gz",
81+
"https://github.com/abseil/abseil-cpp/archive/refs/tags/20211102.0.tar.gz",
82+
],
83+
)
84+
85+
# Projects using gRPC as an external dependency must call both grpc_deps() and
86+
# grpc_extra_deps().
87+
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
88+
89+
grpc_deps()
90+
91+
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
92+
93+
grpc_extra_deps()
94+
95+
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
96+
97+
protobuf_deps()
98+
99+
http_archive(
100+
name = "com_google_googleapis",
101+
sha256 = "5bb6b0253ccf64b53d6c7249625a7e3f6c3bc6402abd52d3778bfa48258703a0",
102+
strip_prefix = "googleapis-2f9af297c84c55c8b871ba4495e01ade42476c92",
103+
urls = [
104+
"https://mirror.bazel.build/github.com/googleapis/googleapis/archive/2f9af297c84c55c8b871ba4495e01ade42476c92.tar.gz",
105+
"https://github.com/googleapis/googleapis/archive/2f9af297c84c55c8b871ba4495e01ade42476c92.tar.gz",
106+
],
107+
)
108+
109+
http_archive(
110+
name = "upb",
111+
sha256 = "03b642a535656560cd95cab3b26e8c53ce37e472307dce5bb7e47c9953bbca0f",
112+
strip_prefix = "upb-e5f26018368b11aab672e8e8bb76513f3620c579",
113+
urls = [
114+
"https://mirror.bazel.build/github.com/protocolbuffers/upb/archive/e5f26018368b11aab672e8e8bb76513f3620c579.tar.gz",
115+
"https://github.com/protocolbuffers/upb/archive/e5f26018368b11aab672e8e8bb76513f3620c579.tar.gz",
116+
],
117+
)
118+
119+
http_archive(
120+
name = "bazel_gazelle",
121+
sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb",
122+
urls = [
123+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz",
124+
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz",
125+
],
126+
)
127+
128+
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
129+
130+
gazelle_dependencies()
131+
132+
# load python rules here
133+
# Using commit f0efec5cf8c0ae16483ee677a09ec70737a01bf5
134+
http_archive(
135+
name = "rules_python",
136+
strip_prefix = "rules_python-f0efec5cf8c0ae16483ee677a09ec70737a01bf5",
137+
url = "https://github.com/bazelbuild/rules_python/archive/f0efec5cf8c0ae16483ee677a09ec70737a01bf5.zip",
138+
)
139+
140+
load("@rules_python//python:pip.bzl", "pip_parse")
141+
142+
pip_parse(
143+
name = "bentoml_requirements",
144+
requirements_lock = "//grpc-client/python:requirements.lock.txt",
145+
)
146+
147+
# Load the starlark macro which will define your dependencies.
148+
load("@bentoml_requirements//:requirements.bzl", "install_deps")
149+
150+
# Call it to define repos for your requirements.
151+
install_deps()
152+
153+
# io_grpc_grpc_java is for java_grpc_library and related dependencies.
154+
# Using commit 0cda133c52ed937f9b0a19bcbfc36bf2892c7aa8
155+
http_archive(
156+
name = "io_grpc_grpc_java",
157+
sha256 = "35189faf484096c9eb2928c43b39f2457d1ca39046704ba8c65a69482f8ceed5",
158+
strip_prefix = "grpc-java-0cda133c52ed937f9b0a19bcbfc36bf2892c7aa8",
159+
urls = ["https://github.com/grpc/grpc-java/archive/0cda133c52ed937f9b0a19bcbfc36bf2892c7aa8.tar.gz"],
160+
)
161+
162+
http_archive(
163+
name = "rules_jvm_external",
164+
sha256 = "c21ce8b8c4ccac87c809c317def87644cdc3a9dd650c74f41698d761c95175f3",
165+
strip_prefix = "rules_jvm_external-1498ac6ccd3ea9cdb84afed65aa257c57abf3e0a",
166+
url = "https://github.com/bazelbuild/rules_jvm_external/archive/1498ac6ccd3ea9cdb84afed65aa257c57abf3e0a.zip",
167+
)
168+
169+
load("@rules_jvm_external//:defs.bzl", "maven_install")
170+
load("@io_grpc_grpc_java//:repositories.bzl", "IO_GRPC_GRPC_JAVA_ARTIFACTS", "IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS", "grpc_java_repositories")
171+
172+
IO_GRPC_GRPC_KOTLIN_ARTIFACTS = [
173+
"com.squareup:kotlinpoet:1.11.0",
174+
"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2",
175+
"org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.2",
176+
"org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.6.2",
177+
]
178+
179+
maven_install(
180+
artifacts = [
181+
"com.google.jimfs:jimfs:1.1",
182+
"com.google.truth.extensions:truth-proto-extension:1.0.1",
183+
"com.google.protobuf:protobuf-kotlin:3.18.0",
184+
] + IO_GRPC_GRPC_KOTLIN_ARTIFACTS + IO_GRPC_GRPC_JAVA_ARTIFACTS,
185+
generate_compat_repositories = True,
186+
override_targets = IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS,
187+
repositories = [
188+
"https://repo.maven.apache.org/maven2/",
189+
],
190+
)
191+
192+
load("@maven//:compat.bzl", "compat_repositories")
193+
194+
compat_repositories()
195+
196+
grpc_java_repositories()
197+
198+
# loading kotlin rules
199+
# first to load grpc/grpc-kotlin
200+
http_archive(
201+
name = "com_github_grpc_grpc_kotlin",
202+
sha256 = "b1ec1caa5d81f4fa4dca0662f8112711c82d7db6ba89c928ca7baa4de50afbb2",
203+
strip_prefix = "grpc-kotlin-a1659c1b3fb665e01a6854224c7fdcafc8e54d56",
204+
urls = ["https://github.com/grpc/grpc-kotlin/archive/a1659c1b3fb665e01a6854224c7fdcafc8e54d56.tar.gz"],
205+
)
206+
207+
http_archive(
208+
name = "io_bazel_rules_kotlin",
209+
sha256 = "a57591404423a52bd6b18ebba7979e8cd2243534736c5c94d35c89718ea38f94",
210+
urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/v1.6.0/rules_kotlin_release.tgz"],
211+
)
212+
213+
load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories")
214+
215+
kotlin_repositories()
216+
217+
load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")
218+
219+
kt_register_toolchains()
220+
221+
# swift rules
222+
# TODO: Currently fails at detecting compiled gRPC swift library
223+
# Since CgRPC is deprecated, seems like no rules are being maintained
224+
# for the newer swift implementation.

0 commit comments

Comments
 (0)