構建 Rust Protos
描述如何使用 Cargo 或 Bazel 構建 Rust 原型。
Cargo
請參閱 protobuf-example crate,瞭解如何設定構建的示例。
Bazel
為 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 會檢查全域性構建標誌以選擇適合您的後端。