This commit is contained in:
parent
c379d44d37
commit
1f76470ac4
6 changed files with 56 additions and 53 deletions
|
|
@ -1,18 +1,12 @@
|
||||||
load("@rules_proto//proto:defs.bzl", "proto_library")
|
load("@rules_proto//proto:defs.bzl", "proto_library")
|
||||||
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
|
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
|
||||||
|
|
||||||
# Simple proto for testing
|
|
||||||
proto_library(
|
|
||||||
name = "simple_proto",
|
|
||||||
srcs = ["simple.proto"],
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Prost generator binary for converting proto files to Rust code
|
# Prost generator binary for converting proto files to Rust code
|
||||||
rust_binary(
|
rust_binary(
|
||||||
name = "prost_generator",
|
name = "prost_generator",
|
||||||
srcs = ["prost_generator.rs"],
|
srcs = ["prost_generator.rs"],
|
||||||
edition = "2021",
|
edition = "2021",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
"@crates//:prost",
|
"@crates//:prost",
|
||||||
"@crates//:prost-build",
|
"@crates//:prost-build",
|
||||||
|
|
@ -21,33 +15,6 @@ rust_binary(
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Generate Rust code for simple proto using prost generator
|
|
||||||
genrule(
|
|
||||||
name = "generate_simple_rust",
|
|
||||||
srcs = ["simple.proto"],
|
|
||||||
outs = ["simple.rs"],
|
|
||||||
cmd = "PROTOC=$(location @com_google_protobuf//:protoc) $(location :prost_generator) $(location simple.proto) /dev/null $@",
|
|
||||||
tools = [
|
|
||||||
":prost_generator",
|
|
||||||
"@com_google_protobuf//:protoc",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Test the simple generation
|
|
||||||
rust_test(
|
|
||||||
name = "simple_test",
|
|
||||||
srcs = [
|
|
||||||
"simple_test.rs",
|
|
||||||
":generate_simple_rust",
|
|
||||||
],
|
|
||||||
edition = "2021",
|
|
||||||
deps = [
|
|
||||||
"@crates//:prost",
|
|
||||||
"@crates//:serde",
|
|
||||||
"@crates//:serde_json",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Generate Rust code for databuild proto
|
# Generate Rust code for databuild proto
|
||||||
genrule(
|
genrule(
|
||||||
name = "generate_databuild_rust",
|
name = "generate_databuild_rust",
|
||||||
|
|
@ -57,9 +24,10 @@ genrule(
|
||||||
outs = ["databuild.rs"],
|
outs = ["databuild.rs"],
|
||||||
cmd = "PROTOC=$(location @com_google_protobuf//:protoc) $(location :prost_generator) $(location databuild.proto) /dev/null $@",
|
cmd = "PROTOC=$(location @com_google_protobuf//:protoc) $(location :prost_generator) $(location databuild.proto) /dev/null $@",
|
||||||
tools = [
|
tools = [
|
||||||
":prost_generator",
|
"//databuild:prost_generator",
|
||||||
"@com_google_protobuf//:protoc",
|
"@com_google_protobuf//:protoc",
|
||||||
],
|
],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# DataBuild library using generated prost code
|
# DataBuild library using generated prost code
|
||||||
|
|
@ -79,21 +47,6 @@ rust_library(
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Test the databuild generation
|
|
||||||
rust_test(
|
|
||||||
name = "databuild_test",
|
|
||||||
srcs = [
|
|
||||||
"databuild_test.rs",
|
|
||||||
":generate_databuild_rust",
|
|
||||||
],
|
|
||||||
edition = "2021",
|
|
||||||
deps = [
|
|
||||||
"@crates//:prost",
|
|
||||||
"@crates//:serde",
|
|
||||||
"@crates//:serde_json",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Legacy filegroup for backwards compatibility
|
# Legacy filegroup for backwards compatibility
|
||||||
filegroup(
|
filegroup(
|
||||||
name = "proto",
|
name = "proto",
|
||||||
|
|
|
||||||
|
|
@ -68,8 +68,7 @@ let job_config = JobConfig {
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bazel test //databuild:databuild_test
|
bazel test //databuild:...
|
||||||
bazel build //databuild:databuild
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Benefits of This Approach
|
## Benefits of This Approach
|
||||||
|
|
|
||||||
51
databuild/test/BUILD.bazel
Normal file
51
databuild/test/BUILD.bazel
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
load("@rules_proto//proto:defs.bzl", "proto_library")
|
||||||
|
load("@rules_rust//rust:defs.bzl", "rust_test")
|
||||||
|
|
||||||
|
# Test the databuild generation
|
||||||
|
rust_test(
|
||||||
|
name = "databuild_test",
|
||||||
|
srcs = [
|
||||||
|
"databuild_test.rs",
|
||||||
|
"//databuild:generate_databuild_rust",
|
||||||
|
],
|
||||||
|
edition = "2021",
|
||||||
|
deps = [
|
||||||
|
"@crates//:prost",
|
||||||
|
"@crates//:serde",
|
||||||
|
"@crates//:serde_json",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
# Generate Rust code for simple proto using prost generator
|
||||||
|
genrule(
|
||||||
|
name = "generate_simple_rust",
|
||||||
|
srcs = ["simple.proto"],
|
||||||
|
outs = ["simple.rs"],
|
||||||
|
cmd = "PROTOC=$(location @com_google_protobuf//:protoc) $(location //databuild:prost_generator) $(location simple.proto) /dev/null $@",
|
||||||
|
tools = [
|
||||||
|
"//databuild:prost_generator",
|
||||||
|
"@com_google_protobuf//:protoc",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
# Simple proto for testing
|
||||||
|
proto_library(
|
||||||
|
name = "simple_proto",
|
||||||
|
srcs = ["simple.proto"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
# Test the simple generation
|
||||||
|
rust_test(
|
||||||
|
name = "simple_test",
|
||||||
|
srcs = [
|
||||||
|
"simple_test.rs",
|
||||||
|
":generate_simple_rust",
|
||||||
|
],
|
||||||
|
edition = "2021",
|
||||||
|
deps = [
|
||||||
|
"@crates//:prost",
|
||||||
|
"@crates//:serde",
|
||||||
|
"@crates//:serde_json",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// Include the generated protobuf code
|
// Include the generated protobuf code
|
||||||
include!("databuild.rs");
|
include!("../databuild.rs");
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
Loading…
Reference in a new issue