Skip to content

Commit ecb5bec

Browse files
authored
Add Rust distribution targets and their CI workflows (#168)
## What is the goal of this PR? We added crate distribution targets (`assemble_crate` and `deploy_crate`) for Rust, and added CI workflows for deploying snapshot and release crates. ## What are the changes implemented in this PR? We recently tried adding an `assemble_crate` rule to our existing Rust proto codebase to distribute Rust proto bindings, but it didn't work - it didn't contain any protobuf source code, because the `assemble_crate` rule doesn't support Cargo build scripts. But instead of actually adding that support, we had a rethink of the build architecture. The old idea was (following Tonic's own docs) for `typedb-protocol` to come bundled with the `.proto` sources and a Cargo build script that would allow the end-user to compile the protobufs on-the-fly. This would require them to have `protoc` installed in their environment, and would dramatically increase their compilation time and overhead. A better option would be to bundle the generated Rust sources. So we've created the `rust_tonic_compile` rule that enables just that in typedb/typedb-dependencies#391. Now, both `rust_library` and `assemble_crate` rules can depend on `typedb_protocol` seamlessly, so we can depend on `typedb_protocol` either through Bazel or Cargo. As this PR stabilises the release process, we've gone ahead and added the relevant CI workflows: `deploy-crate-snapshot` and `deploy-crate-release`.
1 parent 26782a5 commit ecb5bec

File tree

5 files changed

+45
-60
lines changed

5 files changed

+45
-60
lines changed

.factory/automation.yml

+15
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ build:
7979
export DEPLOY_PIP_PASSWORD=$REPO_VATICLE_PASSWORD
8080
bazel run --define version=$(git rev-parse HEAD) //grpc/python:deploy-pip -- snapshot
8181
dependencies: [build, build-dependency]
82+
deploy-crate-snapshot:
83+
filter:
84+
owner: vaticle
85+
branch: master
86+
image: vaticle-ubuntu-22.04
87+
command: |
88+
export DEPLOY_CRATE_TOKEN=$REPO_VATICLE_CRATES_TOKEN
89+
bazel run --define version=$(git rev-parse HEAD) //grpc/rust:deploy_crate -- snapshot
90+
dependencies: [build, build-dependency]
8291

8392
release:
8493
filter:
@@ -129,3 +138,9 @@ release:
129138
export DEPLOY_PIP_PASSWORD=$REPO_PYPI_PASSWORD
130139
bazel run --define version=$(cat VERSION) //grpc/python:deploy-pip -- release
131140
dependencies: [deploy-github]
141+
deploy-crate-release:
142+
image: vaticle-ubuntu-22.04
143+
command: |
144+
export DEPLOY_CRATE_TOKEN=$REPO_CRATES_TOKEN
145+
bazel run --define version=$(cat VERSION) //grpc/rust:deploy_crate -- release
146+
dependencies: [build, build-dependency]

dependencies/vaticle/repositories.bzl

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
2020
def vaticle_dependencies():
2121
git_repository(
2222
name = "vaticle_dependencies",
23-
remote = "https://github.com/vaticle/dependencies",
24-
commit = "5be6d949ca1e04e4179ea6acb3432be713b9dfb8", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
23+
remote = "https://github.com/alexjpwalker/dependencies",
24+
commit = "1bf0ec950a59ad170c826f9fe163701c2e0b2233", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
2525
)

grpc/rust/BUILD

+27-14
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
#
1717

1818
load("@rules_rust//rust:defs.bzl", "rust_library")
19-
load("@rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script")
19+
load("@vaticle_bazel_distribution//crates:rules.bzl", "assemble_crate", "deploy_crate")
20+
load("@vaticle_dependencies//distribution:deployment.bzl", "deployment")
2021
load("@vaticle_dependencies//tool/checkstyle:rules.bzl", "checkstyle_test")
22+
load("@vaticle_dependencies//builder/grpc/rust:compile.bzl", "rust_tonic_compile")
2123

22-
cargo_build_script(
24+
rust_tonic_compile(
2325
name = "typedb_protocol_src",
24-
srcs = ["build.rs"],
25-
data = [
26+
packages = ["typedb.protocol"],
27+
srcs = [
2628
"//cluster:service-proto",
2729
"//cluster:server-proto",
2830
"//cluster:user-proto",
@@ -36,21 +38,16 @@ cargo_build_script(
3638
"//common:transaction-proto",
3739
"//core:database-proto",
3840
"//core:service-proto",
39-
"@com_google_protobuf//:protoc",
40-
],
41-
build_script_env = {
42-
"PROTOC": "$(execpath @com_google_protobuf//:protoc)"
43-
},
44-
deps = [
45-
"@vaticle_dependencies//library/crates:tonic_build"
46-
],
41+
]
4742
)
4843

4944
rust_library(
5045
name = "typedb_protocol",
51-
srcs = ["lib.rs"],
52-
deps = [
46+
srcs = [
5347
":typedb_protocol_src",
48+
"lib.rs",
49+
],
50+
deps = [
5451
"@vaticle_dependencies//library/crates:tonic",
5552
"@vaticle_dependencies//library/crates:prost",
5653
],
@@ -60,6 +57,22 @@ rust_library(
6057
visibility = ["//visibility:public"],
6158
)
6259

60+
assemble_crate(
61+
name = "assemble_crate",
62+
target = ":typedb_protocol",
63+
description = "TypeDB Protocol",
64+
homepage = "https://github.com/vaticle/typedb-protocol",
65+
license = "AGPL-3.0-or-later",
66+
repository = "https://github.com/vaticle/typedb-protocol",
67+
)
68+
69+
deploy_crate(
70+
name = "deploy_crate",
71+
target = ":assemble_crate",
72+
snapshot = deployment["crate.snapshot"],
73+
release = deployment["crate.release"]
74+
)
75+
6376
checkstyle_test(
6477
name = "checkstyle",
6578
include = glob(["*"]),

grpc/rust/build.rs

-43
This file was deleted.

grpc/rust/lib.rs

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

18-
tonic::include_proto!("typedb.protocol");
18+
include!("typedb.protocol.rs");

0 commit comments

Comments
 (0)