Skip to content

Commit 78e529d

Browse files
authored
Clean up old Rust gRPC compile code that used the 'grpc' crate (#166)
## What is the goal of this PR? We cleaned up old Rust gRPC compile code that was using the `grpc` crate, as we are now using the `tonic` crate instead. ## What are the changes implemented in this PR? We successfully migrated `typedb-client-rust` from using the `grpc` crate to the more actively-maintained `tonic` crate, and from the `protobuf` crate (used by `grpc`) to the `prost` crate used by `tonic`. So, we can now freely delete the old gRPC compiler code using the `grpc` crate from `typedb-protocol`. We've also integrated the Rust IDE sync tool into `typedb-protocol`, which is needed to provide IntelliSense in our Rust sources.
1 parent e612350 commit 78e529d

File tree

9 files changed

+68
-127
lines changed

9 files changed

+68
-127
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ bazel-*
3636
# Compiled files #
3737
dist/
3838
out/
39+
target/
3940
*.class
4041

42+
# Cargo files #
43+
Cargo.toml
44+
Cargo.lock
45+
4146
# Mobile Tools for Java (J2ME) files #
4247
.mtj.tmp/
4348

BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ exports_files(["README.md"])
5959
filegroup(
6060
name = "ci",
6161
data = [
62+
"@vaticle_dependencies//ide/rust:sync",
6263
"@vaticle_dependencies//library/maven:update",
6364
"@vaticle_dependencies//tool/bazelrun:rbe",
6465
"@vaticle_dependencies//tool/unuseddeps:unused-deps",

WORKSPACE

-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ java_grpc_compile()
7676
load("@stackb_rules_proto//node:deps.bzl", "node_grpc_compile")
7777
node_grpc_compile()
7878

79-
load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories")
80-
rust_proto_repositories()
81-
register_toolchains("//grpc/rust:proto_toolchain")
82-
8379
# Load //tool/checkstyle
8480
load("@vaticle_dependencies//tool/checkstyle:deps.bzl", checkstyle_deps = "deps")
8581
checkstyle_deps()

dependencies/ide/BUILD

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# Copyright (C) 2022 Vaticle
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU Affero General Public License as
6+
# published by the Free Software Foundation, either version 3 of the
7+
# License, or (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU Affero General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Affero General Public License
15+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
#
17+
18+
load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
19+
20+
checkstyle_test(
21+
name = "checkstyle",
22+
include = glob(["*"]),
23+
license_type = "agpl-header",
24+
size = "small",
25+
)

dependencies/ide/sync.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (C) 2022 Vaticle
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Affero General Public License as
7+
# published by the Free Software Foundation, either version 3 of the
8+
# License, or (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Affero General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Affero General Public License
16+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
#
18+
19+
bazel run @vaticle_dependencies//ide/rust:sync

dependencies/vaticle/repositories.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ def vaticle_dependencies():
2121
git_repository(
2222
name = "vaticle_dependencies",
2323
remote = "https://github.com/vaticle/dependencies",
24-
commit = "4464b506ca469f37d3b696fb2f1eda34061cdaa1", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
24+
commit = "5be6d949ca1e04e4179ea6acb3432be713b9dfb8", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
2525
)

grpc/rust/BUILD

+16-77
Original file line numberDiff line numberDiff line change
@@ -15,80 +15,12 @@
1515
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
#
1717

18-
load("@rules_rust//proto:proto.bzl", "rust_grpc_library")
19-
load("@rules_rust//proto:toolchain.bzl", "rust_proto_toolchain")
20-
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library")
18+
load("@rules_rust//rust:defs.bzl", "rust_library")
2119
load("@rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script")
2220
load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
2321

24-
# TODO: once we clarify how we should compile the gRPC + Protobuf library, delete this target
25-
rust_binary(
26-
name = "proto_compile",
27-
srcs = ["main.rs"],
28-
data = [
29-
"//cluster:service-proto",
30-
"//cluster:server-proto",
31-
"//cluster:user-proto",
32-
"//cluster:database-proto",
33-
"//common:answer-proto",
34-
"//common:concept-proto",
35-
"//common:logic-proto",
36-
"//common:options-proto",
37-
"//common:query-proto",
38-
"//common:session-proto",
39-
"//common:transaction-proto",
40-
"//core:database-proto",
41-
"//core:service-proto",
42-
],
43-
deps = [
44-
"@vaticle_dependencies//library/crates:protoc_rust_grpc",
45-
],
46-
)
47-
48-
rust_proto_toolchain(
49-
name = "proto_toolchain_impl",
50-
# Path to the protobuf compiler.
51-
protoc = "@com_google_protobuf//:protoc",
52-
# Protobuf compiler plugin to generate rust gRPC stubs.
53-
grpc_plugin = "@vaticle_dependencies//library/crates:cargo_bin_protoc_gen_rust_grpc",
54-
# Protobuf compiler plugin to generate rust protobuf stubs.
55-
proto_plugin = "@vaticle_dependencies//library/crates:cargo_bin_protoc_gen_rust",
56-
)
57-
58-
toolchain(
59-
name = "proto_toolchain",
60-
toolchain = ":proto_toolchain_impl",
61-
toolchain_type = "@rules_rust//proto:toolchain_type",
62-
)
63-
64-
rust_grpc_library(
65-
name = "typedb_protocol_src",
66-
deps = [
67-
"//cluster:service-proto",
68-
"//cluster:server-proto",
69-
"//cluster:user-proto",
70-
"//cluster:database-proto",
71-
"//common:answer-proto",
72-
"//common:concept-proto",
73-
"//common:logic-proto",
74-
"//common:options-proto",
75-
"//common:query-proto",
76-
"//common:session-proto",
77-
"//common:transaction-proto",
78-
"//core:database-proto",
79-
"//core:service-proto",
80-
]
81-
)
82-
83-
checkstyle_test(
84-
name = "checkstyle",
85-
include = glob(["*"]),
86-
license_type = "agpl-header",
87-
size = "small",
88-
)
89-
9022
cargo_build_script(
91-
name = "typedb-protocol-src",
23+
name = "typedb_protocol_src",
9224
srcs = ["build.rs"],
9325
data = [
9426
"//cluster:service-proto",
@@ -110,20 +42,27 @@ cargo_build_script(
11042
"PROTOC": "$(execpath @com_google_protobuf//:protoc)"
11143
},
11244
deps = [
113-
"@vaticle_dependencies//library/crates:tonic_build",
45+
"@vaticle_dependencies//library/crates:tonic_build"
11446
],
11547
)
11648

11749
rust_library(
118-
name = "typedb-protocol",
119-
crate_name = "typedb_protocol_client",
120-
srcs = [
121-
"lib.rs"
122-
],
50+
name = "typedb_protocol",
51+
srcs = ["lib.rs"],
12352
deps = [
124-
":typedb-protocol-src",
53+
":typedb_protocol_src",
12554
"@vaticle_dependencies//library/crates:tonic",
12655
"@vaticle_dependencies//library/crates:prost",
12756
],
57+
tags = [
58+
"crate-name=typedb-protocol",
59+
],
12860
visibility = ["//visibility:public"],
12961
)
62+
63+
checkstyle_test(
64+
name = "checkstyle",
65+
include = glob(["*"]),
66+
license_type = "agpl-header",
67+
size = "small",
68+
)

grpc/rust/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
fn main() -> Result<(), Box<dyn std::error::Error>> {
1919
tonic_build::configure()
20+
.build_client(true)
2021
.build_server(true)
2122
.compile(
2223
&[

grpc/rust/main.rs

-45
This file was deleted.

0 commit comments

Comments
 (0)