diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2019-05-15 17:33:06 -0700 |
---|---|---|
committer | Joshua Haberman <jhaberman@gmail.com> | 2019-05-15 17:33:06 -0700 |
commit | 240bf641de10a056a048b9b7fa0de811a39bb707 (patch) | |
tree | 9f39652626744ab3eafd1bfe0820692da9fcdb48 /examples | |
parent | 77600acc84be092dac7c58772e8ee01185c7405d (diff) |
Working example dir for Bazel.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/bazel/BUILD | 18 | ||||
-rw-r--r-- | examples/bazel/WORKSPACE | 44 | ||||
-rw-r--r-- | examples/bazel/foo.proto | 7 | ||||
-rw-r--r-- | examples/bazel/test_binary.c | 17 |
4 files changed, 86 insertions, 0 deletions
diff --git a/examples/bazel/BUILD b/examples/bazel/BUILD new file mode 100644 index 0000000..2e94d46 --- /dev/null +++ b/examples/bazel/BUILD @@ -0,0 +1,18 @@ + +load("@upb//:upb_proto_library.bzl", "upb_proto_library") + +proto_library( + name = "foo_proto", + srcs = ["foo.proto"], +) + +upb_proto_library( + name = "foo_upbproto", + deps = [":foo_proto"], +) + +cc_binary( + name = "test_binary", + srcs = ["test_binary.c"], + deps = [":foo_upbproto"], +) diff --git a/examples/bazel/WORKSPACE b/examples/bazel/WORKSPACE new file mode 100644 index 0000000..01d3efd --- /dev/null +++ b/examples/bazel/WORKSPACE @@ -0,0 +1,44 @@ + +workspace(name = "upb_example") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +git_repository( + name = "upb", + remote = "https://github.com/protocolbuffers/upb.git", + commit = "d5af87d06bbe3abad66970ce9c7ae0a7de8bb3c6", +) + +load("@upb//:repository_defs.bzl", "bazel_version_repository") + +bazel_version_repository( + name = "bazel_version", +) + +git_repository( + name = "absl", + commit = "070f6e47b33a2909d039e620c873204f78809492", + remote = "https://github.com/abseil/abseil-cpp.git", + shallow_since = "1541627663 -0500", +) + +git_repository( + name = "com_google_protobuf", + remote = "https://github.com/protocolbuffers/protobuf.git", + commit = "d41002663fd04325ead28439dfd5ce2822b0d6fb", +) + +http_archive( + name = "bazel_skylib", + strip_prefix = "bazel-skylib-master", + urls = ["https://github.com/bazelbuild/bazel-skylib/archive/master.tar.gz"], +) + +http_archive( + name = "zlib", + build_file = "@com_google_protobuf//:third_party/zlib.BUILD", + sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1", + strip_prefix = "zlib-1.2.11", + urls = ["https://zlib.net/zlib-1.2.11.tar.gz"], +) diff --git a/examples/bazel/foo.proto b/examples/bazel/foo.proto new file mode 100644 index 0000000..f68b994 --- /dev/null +++ b/examples/bazel/foo.proto @@ -0,0 +1,7 @@ + +syntax = "proto2"; + +message Foo { + optional int64 time = 1; + optional string greeting = 2; +} diff --git a/examples/bazel/test_binary.c b/examples/bazel/test_binary.c new file mode 100644 index 0000000..78f367a --- /dev/null +++ b/examples/bazel/test_binary.c @@ -0,0 +1,17 @@ + +#include <time.h> + +#include "foo.upb.h" + +int main() { + upb_arena *arena = upb_arena_new(); + Foo* foo = Foo_new(arena); + const char greeting[] = "Hello, World!\n"; + + Foo_set_time(foo, time(NULL)); + /* Warning: the proto will not copy this, the string data must outlive + * the proto. */ + Foo_set_greeting(foo, upb_strview_makez(greeting)); + + upb_arena_free(arena); +} |