commit
3b1acd2e9b
@ -0,0 +1,17 @@
|
||||
# External dependency to Google protobuf.
|
||||
http_archive(
|
||||
name = "protobuf",
|
||||
url = "http://github.com/google/protobuf/archive/v3.1.0.tar.gz",
|
||||
sha256 = "0a0ae63cbffc274efb573bdde9a253e3f32e458c41261df51c5dbc5ad541e8f7",
|
||||
strip_prefix = "protobuf-3.1.0",
|
||||
)
|
||||
|
||||
# External dependency to gtest 1.7.0. This method comes from
|
||||
# https://www.bazel.io/versions/master/docs/tutorial/cpp.html.
|
||||
new_http_archive(
|
||||
name = "gtest",
|
||||
url = "https://github.com/google/googletest/archive/release-1.7.0.zip",
|
||||
sha256 = "b58cb7547a28b2c718d1e38aee18a3659c9e3ff52440297e965f5edffe34b6d0",
|
||||
build_file = "third_party/gtest.BUILD",
|
||||
strip_prefix = "googletest-release-1.7.0",
|
||||
)
|
@ -0,0 +1,14 @@
|
||||
cc_library(
|
||||
name = "main",
|
||||
srcs = glob(
|
||||
["src/*.cc"],
|
||||
exclude = ["src/gtest-all.cc"]
|
||||
),
|
||||
hdrs = glob([
|
||||
"include/**/*.h",
|
||||
"src/*.h"
|
||||
]),
|
||||
copts = ["-Iexternal/gtest/include"],
|
||||
linkopts = ["-pthread"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
@ -0,0 +1,27 @@
|
||||
licenses(["notice"]) # Apache 2.0
|
||||
|
||||
load("@protobuf//:protobuf.bzl", "cc_proto_library")
|
||||
|
||||
cc_proto_library(
|
||||
name = "example_proto",
|
||||
srcs = ["example.proto"],
|
||||
protoc = "@protobuf//:protoc",
|
||||
default_runtime = "@protobuf//:protobuf",
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "example_lib",
|
||||
srcs = ["example_lib.cc"],
|
||||
hdrs = ["example_lib.h"],
|
||||
deps = [":example_proto"],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "example_lib_test",
|
||||
srcs = ["example_lib_test.cc"],
|
||||
copts = ["-Iexternal/gtest/include"],
|
||||
deps =[
|
||||
"@gtest//:main",
|
||||
":example_lib",
|
||||
],
|
||||
)
|
@ -0,0 +1 @@
|
||||
This package tests that Bazel can build protobuf related rules.
|
@ -0,0 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package third_party.protobuf_test;
|
||||
|
||||
message Greeting {
|
||||
string name = 1;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
#include "third_party/protobuf_test/example_lib.h"
|
||||
|
||||
namespace third_party {
|
||||
namespace protobuf_test {
|
||||
|
||||
std::string get_greet(const Greeting& who) {
|
||||
return "Hello " + who.name();
|
||||
}
|
||||
|
||||
} // namespace protobuf_test
|
||||
} // namespace thrid_party
|
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "third_party/protobuf_test/example.pb.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace third_party {
|
||||
namespace protobuf_test {
|
||||
|
||||
std::string get_greet(const Greeting &who);
|
||||
|
||||
} // namespace protobuf_test
|
||||
} // namespace third_party
|
@ -0,0 +1,15 @@
|
||||
#include "third_party/protobuf_test/example_lib.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace third_party {
|
||||
namespace protobuf_test {
|
||||
|
||||
TEST(ProtobufTest, GetGreet) {
|
||||
Greeting g;
|
||||
g.set_name("Paddle");
|
||||
EXPECT_EQ("Hello Paddle", get_greet(g));
|
||||
}
|
||||
|
||||
} // namespace protobuf_test
|
||||
} // namespace third_party
|
Loading…
Reference in new issue