Rust-Protos kompilieren
Beschreibt, wie Rust-Protos mit Cargo oder Bazel erstellt werden.
Cargo
Siehe die protobuf-example Crate für ein Beispiel, wie Sie Ihren Build einrichten.
Bazel
Der Prozess des Erstellens einer Rust-Bibliothek für eine Protobuf-Definition ist ähnlich wie bei anderen Programmiersprachen
Verwenden Sie die sprachunabhängige Regel
proto_libraryproto_library( name = "person_proto", srcs = ["person.proto"], )Erstellen Sie eine Rust-Bibliothek
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"], )Verwenden Sie die Bibliothek, indem Sie sie in eine Rust-Binärdatei einbinden
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", ], )
Hinweis
Verwenden Sie nicht direktrust_upb_proto_library oder rust_cc_proto_library. rust_proto_library prüft das globale Build-Flag, um das geeignete Backend für Sie auszuwählen.