diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd12961 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bazel* diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000..09451c5 --- /dev/null +++ b/WORKSPACE @@ -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() diff --git a/rust/BUILD b/rust/BUILD new file mode 100644 index 0000000..a26f925 --- /dev/null +++ b/rust/BUILD @@ -0,0 +1 @@ +package(default_visibility = ["//visibility:public"]) \ No newline at end of file diff --git a/rust/protobuf/BUILD b/rust/protobuf/BUILD new file mode 100644 index 0000000..af52b11 --- /dev/null +++ b/rust/protobuf/BUILD @@ -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, +) diff --git a/rust/protobuf/example.proto b/rust/protobuf/example.proto new file mode 100644 index 0000000..b8af36f --- /dev/null +++ b/rust/protobuf/example.proto @@ -0,0 +1,7 @@ +syntax = "proto2"; + +package example; + +message Example { + optional uint64 id = 1; +} \ No newline at end of file diff --git a/rust/protobuf/main.rs b/rust/protobuf/main.rs new file mode 100644 index 0000000..4ec6974 --- /dev/null +++ b/rust/protobuf/main.rs @@ -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()); +} \ No newline at end of file