构建 Rust Protobuf
描述如何使用 Blaze 构建 Rust Protobuf。
为 Protobuf 定义构建 Rust 库的过程与其他编程语言类似
使用语言无关的
proto_library
规则proto_library( name = "person_proto", srcs = ["person.proto"], )
创建一个 Rust 库
load("//third_party/protobuf/rust:defs.bzl", "rust_proto_library") proto_library( name = "person_proto", srcs = ["person.proto"], ) rust_proto_library( name = "person_rust_proto", deps = [":person_proto"], )
通过将其包含在 Rust 二进制文件中来使用该库
load("//third_party/bazel_rules/rules_rust/rust:defs.bzl", "rust_binary") load("//third_party/protobuf/rust:defs.bzl", "rust_proto_library") proto_library( name = "person_proto", srcs = ["person.proto"], ) rust_proto_library( name = "person_rust_proto", deps = [":person_proto"], ) rust_binary( name = "greet", srcs = ["greet.rs"], deps = [ ":person_rust_proto", ], )
注意
不要直接使用rust_upb_proto_library
或 rust_cc_proto_library
。rust_proto_library
会检查全局构建标志为您选择合适的后端。