107 lines
2.4 KiB
Python
107 lines
2.4 KiB
Python
|
|
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test", "rust_binary")
|
|
load("@rules_proto//proto:defs.bzl", "proto_library")
|
|
|
|
# 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
|
|
rust_binary(
|
|
name = "prost_generator",
|
|
srcs = ["prost_generator.rs"],
|
|
deps = [
|
|
"@crates//:prost",
|
|
"@crates//:prost-build",
|
|
"@crates//:tempfile",
|
|
"@crates//:serde",
|
|
],
|
|
edition = "2021",
|
|
)
|
|
|
|
# Generate Rust code for simple proto using prost generator
|
|
genrule(
|
|
name = "generate_simple_rust",
|
|
srcs = ["simple.proto"],
|
|
outs = ["simple.rs"],
|
|
tools = [
|
|
":prost_generator",
|
|
"@com_google_protobuf//:protoc",
|
|
],
|
|
cmd = "PROTOC=$(location @com_google_protobuf//:protoc) $(location :prost_generator) $(location simple.proto) /dev/null $@",
|
|
)
|
|
|
|
|
|
# Test the simple generation
|
|
rust_test(
|
|
name = "simple_test",
|
|
srcs = [
|
|
"simple_test.rs",
|
|
":generate_simple_rust",
|
|
],
|
|
deps = [
|
|
"@crates//:prost",
|
|
"@crates//:serde",
|
|
"@crates//:serde_json",
|
|
],
|
|
edition = "2021",
|
|
)
|
|
|
|
|
|
# Generate Rust code for databuild proto
|
|
genrule(
|
|
name = "generate_databuild_rust",
|
|
srcs = [
|
|
"databuild.proto",
|
|
],
|
|
outs = ["databuild.rs"],
|
|
tools = [
|
|
":prost_generator",
|
|
"@com_google_protobuf//:protoc",
|
|
],
|
|
cmd = "PROTOC=$(location @com_google_protobuf//:protoc) $(location :prost_generator) $(location databuild.proto) /dev/null $@",
|
|
)
|
|
|
|
# DataBuild library using generated prost code
|
|
rust_library(
|
|
name = "databuild",
|
|
srcs = [
|
|
"lib.rs",
|
|
":generate_databuild_rust",
|
|
"structs.rs",
|
|
],
|
|
deps = [
|
|
"@crates//:prost",
|
|
"@crates//:prost-types",
|
|
"@crates//:serde",
|
|
],
|
|
edition = "2021",
|
|
visibility = ["//visibility:public"],
|
|
)
|
|
|
|
# Test the databuild generation
|
|
rust_test(
|
|
name = "databuild_test",
|
|
srcs = [
|
|
"databuild_test.rs",
|
|
":generate_databuild_rust",
|
|
],
|
|
deps = [
|
|
"@crates//:prost",
|
|
"@crates//:serde",
|
|
"@crates//:serde_json",
|
|
],
|
|
edition = "2021",
|
|
)
|
|
|
|
# Legacy filegroup for backwards compatibility
|
|
filegroup(
|
|
name = "proto",
|
|
srcs = ["databuild.proto"],
|
|
visibility = ["//visibility:public"],
|
|
)
|
|
|