From 945b757aefc90a1a89f5f59139c56e0bbee9aee7 Mon Sep 17 00:00:00 2001 From: John Millikin Date: Thu, 9 Nov 2017 12:55:18 -0800 Subject: [PATCH] Add a Bazel build file for lightstep-tracer-cpp. This lets projects that use the Bazel build system (http://bazel.build) more easily depend on Lightstep's C++ tracer. To generate `config.h` and `version.h`, the config shells out to `cmake` instead of duplicating the existing version definitions from `CMakeLists.txt`. The unprefixed `collector.pb.h` includes and vendoring of `googleapis` gave me some trouble, so I used `local_repository` to treat those as separate Bazel workspaces. We should be able to clean that up when `lightstep-tracer-common` gets its own BUILD files. --- BUILD.bazel | 59 +++++++++++++++++++ WORKSPACE | 11 ++++ lightstep-tracer-common/BUILD | 37 ++++++++++++ lightstep-tracer-common/WORKSPACE | 1 + .../third_party/googleapis/BUILD | 11 ++++ .../third_party/googleapis/WORKSPACE | 0 6 files changed, 119 insertions(+) create mode 100644 BUILD.bazel create mode 100644 WORKSPACE create mode 100644 lightstep-tracer-common/BUILD create mode 100644 lightstep-tracer-common/WORKSPACE create mode 100644 lightstep-tracer-common/third_party/googleapis/BUILD create mode 100644 lightstep-tracer-common/third_party/googleapis/WORKSPACE diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 00000000..c0c0c51f --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,59 @@ +cc_library( + name = "lightstep_tracer", + srcs = glob([ + "src/*.cpp", + "src/*.h", + ]), + hdrs = glob(["include/lightstep/*.h"]) + [ + ":include/lightstep/config.h", + ":include/lightstep/version.h", + ], + strip_include_prefix = "include", + visibility = ["//visibility:public"], + deps = [ + "@com_lightstep_tracer_common//:lightstep_protos", + ":3rd_party_base64", + ":3rd_party_catch", + # https://github.com/opentracing/opentracing-cpp + "@io_opentracing_cpp//:opentracing", + ], +) + +genrule( + name = "generate_version_h", + srcs = glob([ + "*", + "cmake/**/*", + "example/**/*", + "src/*", + "3rd_party/**/*", + ]), + outs = [ + "include/lightstep/config.h", + "include/lightstep/version.h", + ], + cmd = """ + cmake \\ + -DBUILD_TESTING=OFF \\ + -DWITH_GRPC=OFF \\ + -DOPENTRACING_INCLUDE_DIR="" \\ + -DOPENTRACING_LIBRARY="" \\ + -L \\ + $$(dirname $(location :CMakeLists.txt)) + mv include/lightstep/config.h $(location :include/lightstep/config.h) + mv include/lightstep/version.h $(location :include/lightstep/version.h) + """, +) + +cc_library( + name = "3rd_party_base64", + srcs = glob(["3rd_party/base64/src/*.cpp"]), + hdrs = glob(["3rd_party/base64/include/**/*.h"]), + strip_include_prefix = "3rd_party/base64/include", +) + +cc_library( + name = "3rd_party_catch", + hdrs = glob(["3rd_party/catch/include/**/*.hpp"]), + strip_include_prefix = "3rd_party/catch/include", +) diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 00000000..4c186ea6 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,11 @@ +workspace(name = "com_lightstep_tracer_cpp") + +local_repository( + name = "com_lightstep_tracer_common", + path = "lightstep-tracer-common", +) + +local_repository( + name = "lightstep_vendored_googleapis", + path = "lightstep-tracer-common/third_party/googleapis", +) diff --git a/lightstep-tracer-common/BUILD b/lightstep-tracer-common/BUILD new file mode 100644 index 00000000..de38c123 --- /dev/null +++ b/lightstep-tracer-common/BUILD @@ -0,0 +1,37 @@ +proto_library( + name = "collector_proto", + srcs = ["collector.proto"], + deps = [ + "@lightstep_vendored_googleapis//:googleapis_proto", + "@com_google_protobuf//:timestamp_proto", + ], + visibility = ["//visibility:public"], +) + +cc_proto_library( + name = "collector_proto_cc", + deps = [":collector_proto"], +) + +proto_library( + name = "lightstep_carrier_proto", + srcs = ["lightstep_carrier.proto"], + visibility = ["//visibility:public"], +) + +cc_proto_library( + name = "lightstep_carrier_proto_cc", + deps = [":lightstep_carrier_proto"], +) + +# FIXME: this rule allows `#include ` to work, but it +# would be nicer to have properly prefixed include paths instead. +cc_library( + name = "lightstep_protos", + deps = [ + ":collector_proto_cc", + ":lightstep_carrier_proto_cc", + ], + visibility = ["//visibility:public"], + includes = ["."] +) diff --git a/lightstep-tracer-common/WORKSPACE b/lightstep-tracer-common/WORKSPACE new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/lightstep-tracer-common/WORKSPACE @@ -0,0 +1 @@ + diff --git a/lightstep-tracer-common/third_party/googleapis/BUILD b/lightstep-tracer-common/third_party/googleapis/BUILD new file mode 100644 index 00000000..2adec340 --- /dev/null +++ b/lightstep-tracer-common/third_party/googleapis/BUILD @@ -0,0 +1,11 @@ +proto_library( + name = "googleapis_proto", + srcs = [ + "google/api/annotations.proto", + "google/api/http.proto", + ], + deps = [ + "@com_google_protobuf//:descriptor_proto", + ], + visibility = ["//visibility:public"], +) diff --git a/lightstep-tracer-common/third_party/googleapis/WORKSPACE b/lightstep-tracer-common/third_party/googleapis/WORKSPACE new file mode 100644 index 00000000..e69de29b