Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel*
27 changes: 27 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# To find additional information on this release or newer ones visit:
# https://github.com/bazelbuild/rules_rust/releases
http_archive(
name = "rules_rust",
sha256 = "9d04e658878d23f4b00163a72da3db03ddb451273eb347df7d7c50838d698f49",
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.26.0/rules_rust-v0.26.0.tar.gz"],
)

load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")

rules_rust_dependencies()

rust_register_toolchains(
edition = "2021",
)

load("@rules_rust//proto/protobuf:repositories.bzl", "rust_proto_protobuf_dependencies", "rust_proto_protobuf_register_toolchains")

rust_proto_protobuf_dependencies()

rust_proto_protobuf_register_toolchains()

load("@rules_rust//proto/protobuf:transitive_repositories.bzl", "rust_proto_protobuf_transitive_repositories")

rust_proto_protobuf_transitive_repositories()
1 change: 1 addition & 0 deletions rust/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package(default_visibility = ["//visibility:public"])
27 changes: 27 additions & 0 deletions rust/protobuf/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
load("@rules_rust//proto/protobuf:toolchain.bzl", "PROTO_COMPILE_DEPS")
load("@rules_rust//proto/protobuf:defs.bzl", "rust_proto_library")
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library")
package(default_visibility = ["//visibility:public"])

proto_library(
name = "example_proto",
srcs = ["example.proto"],
)

rust_proto_library(
name = "example_proto_rust",
deps = [
":example_proto",
]
)

rust_binary(
name = "main",
srcs = [
"main.rs",
],
deps = [
":example_proto_rust",
# ]
] + PROTO_COMPILE_DEPS,
)
7 changes: 7 additions & 0 deletions rust/protobuf/example.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto2";

package example;

message Example {
optional uint64 id = 1;
}
9 changes: 9 additions & 0 deletions rust/protobuf/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use example_proto_rust;
use protobuf::Message;

fn main() {
let mut example = example_proto_rust::Example::new();
example.set_id(1);
println!("{:?}", example);
println!("is_initialized[{}]", example.is_initialized());
}