From 4c886c1f4661e76d4615a233fbbc2a84600a167d Mon Sep 17 00:00:00 2001 From: Caleb Gilmour Date: Wed, 18 Jul 2018 05:49:00 +0000 Subject: [PATCH 1/3] Add WORKSPACE, BUILD files for bazel --- .gitignore | 3 +++ 3rd_party/BUILD | 21 +++++++++++++++++++++ BUILD.bazel | 37 +++++++++++++++++++++++++++++++++++++ WORKSPACE | 12 ++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 3rd_party/BUILD create mode 100644 BUILD.bazel create mode 100644 WORKSPACE diff --git a/.gitignore b/.gitignore index daa3881a..0f2aaaed 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,6 @@ *.exe *.out *.app + +# Bazel +bazel-* diff --git a/3rd_party/BUILD b/3rd_party/BUILD new file mode 100644 index 00000000..2068a3b0 --- /dev/null +++ b/3rd_party/BUILD @@ -0,0 +1,21 @@ +cc_library( + name = "nlohmann", + hdrs = ["include/nlohmann/json.hpp"], + strip_include_prefix = "include", + visibility = ["//visibility:public"], +) + +cc_library( + name = "catch2", + hdrs = ["include/catch2/catch.hpp"], + strip_include_prefix = "include", + visibility = ["//visibility:public"], +) + +filegroup( + name = "sanitizers_cmake", + srcs = glob([ + "sanitizers-cmake/*", + ]), + visibility = ["//visibility:public"], +) diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 00000000..dbdd8ad4 --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,37 @@ +cc_library( + name = "dd_opentracing_cpp", + srcs = glob(["src/*.cpp", "src/*.h"]) + [ + ":version_number.h", + ], + hdrs = [ + "include/datadog/opentracing.h", + ], + strip_include_prefix = "include", + visibility = ["//visibility:public"], + deps = [ + "//3rd_party:nlohmann", + ], + copts = ["-std=c++14"], +) + +genrule( + name = "generate_version_number_h", + srcs = glob([ + "CMakeLists.txt", + "src/*", + ]) + [ + "//3rd_party:sanitizers_cmake", + ], + outs = [ + "version_number.h" + ], + cmd = """ + TEMP_DIR=$$(mktemp -d) + trap -- 'rm -r $$TEMP_DIR' EXIT + VERSION_NUMBER_H_OUT=$${PWD}/$(location :version_number.h) + CMAKE_ROOT=$$(dirname $${PWD}/$(location :CMakeLists.txt)) + cd $$TEMP_DIR + cmake -DBUILD_SHARED=OFF -DBUILD_TESTING=OFF -L $$CMAKE_ROOT + mv version_number.h $$VERSION_NUMBER_H_OUT + """, +) diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 00000000..27f165f1 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,12 @@ +workspace(name = "com_github_datadog_dd_opentracing_cpp") + +git_repository( + name = "io_opentracing_cpp", + remote = "https://github.com/opentracing/opentracing-cpp", + commit = "ac50154a7713877f877981c33c3375003b6ebfe1", +) + +local_repository( + name = "dd_opentracing_cpp_thirdparty", + path = "3rd_party", +) From 71a1d981538b8d3356d1166f2c4fee2db6bb0786 Mon Sep 17 00:00:00 2001 From: Caleb Gilmour Date: Mon, 23 Jul 2018 00:06:07 +0000 Subject: [PATCH 2/3] Update BUILD files, add msgpack dependency --- 3rd_party/BUILD | 21 --------------------- BUILD.bazel | 24 +++++++++++++++++++----- CMakeLists.txt | 5 +++++ WORKSPACE | 11 ++++++++--- bazel/external/msgpack.BUILD | 15 +++++++++++++++ 5 files changed, 47 insertions(+), 29 deletions(-) delete mode 100644 3rd_party/BUILD create mode 100644 bazel/external/msgpack.BUILD diff --git a/3rd_party/BUILD b/3rd_party/BUILD deleted file mode 100644 index 2068a3b0..00000000 --- a/3rd_party/BUILD +++ /dev/null @@ -1,21 +0,0 @@ -cc_library( - name = "nlohmann", - hdrs = ["include/nlohmann/json.hpp"], - strip_include_prefix = "include", - visibility = ["//visibility:public"], -) - -cc_library( - name = "catch2", - hdrs = ["include/catch2/catch.hpp"], - strip_include_prefix = "include", - visibility = ["//visibility:public"], -) - -filegroup( - name = "sanitizers_cmake", - srcs = glob([ - "sanitizers-cmake/*", - ]), - visibility = ["//visibility:public"], -) diff --git a/BUILD.bazel b/BUILD.bazel index dbdd8ad4..82663c60 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -9,7 +9,9 @@ cc_library( strip_include_prefix = "include", visibility = ["//visibility:public"], deps = [ - "//3rd_party:nlohmann", + "//:3rd_party_nlohmann", + "@io_opentracing_cpp//:opentracing", + "@com_github_msgpack_msgpack_c//:msgpack", ], copts = ["-std=c++14"], ) @@ -19,9 +21,7 @@ genrule( srcs = glob([ "CMakeLists.txt", "src/*", - ]) + [ - "//3rd_party:sanitizers_cmake", - ], + ]), outs = [ "version_number.h" ], @@ -31,7 +31,21 @@ genrule( VERSION_NUMBER_H_OUT=$${PWD}/$(location :version_number.h) CMAKE_ROOT=$$(dirname $${PWD}/$(location :CMakeLists.txt)) cd $$TEMP_DIR - cmake -DBUILD_SHARED=OFF -DBUILD_TESTING=OFF -L $$CMAKE_ROOT + cmake -DHEADERS_ONLY=ON -L $$CMAKE_ROOT mv version_number.h $$VERSION_NUMBER_H_OUT """, ) + +cc_library( + name = "3rd_party_nlohmann", + hdrs = ["3rd_party/include/nlohmann/json.hpp"], + strip_include_prefix = "3rd_party/include", + visibility = ["//visibility:public"], +) + +cc_library( + name = "3rd_party_catch2", + hdrs = ["3rd_party/include/catch2/catch.hpp"], + strip_include_prefix = "3rd_party/include", + visibility = ["//visibility:public"], +) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b094ee7..61990319 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ option(BUILD_SHARED "Builds shared library" ON) option(BUILD_STATIC "Builds static library" OFF) option(BUILD_PLUGIN "Builds plugin (requires gcc and not macos)" OFF) option(BUILD_TESTING "Builds tests, also enables BUILD_SHARED" OFF) +option(HEADERS_ONLY "Only generate version_number.h" OFF) if(BUILD_TESTING) set(BUILD_SHARED ON) @@ -37,6 +38,10 @@ configure_file( "${PROJECT_BINARY_DIR}/version_number.h") include_directories("${PROJECT_BINARY_DIR}") +if(HEADERS_ONLY) + return() +endif() + # Dependencies find_path(OPENTRACING_INCLUDE_DIR NAMES opentracing/tracer.h) find_library(OPENTRACING_LIB opentracing) diff --git a/WORKSPACE b/WORKSPACE index 27f165f1..0d5c93c5 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -6,7 +6,12 @@ git_repository( commit = "ac50154a7713877f877981c33c3375003b6ebfe1", ) -local_repository( - name = "dd_opentracing_cpp_thirdparty", - path = "3rd_party", +new_http_archive( + name = "com_github_msgpack_msgpack_c", + sha256 = "9859d44d336f9b023a79a3026bb6a558b2ea346107ab4eadba58236048650690", + strip_prefix = "msgpack-3.0.1", + urls = [ + "https://github.com/msgpack/msgpack-c/releases/download/cpp-3.0.1/msgpack-3.0.1.tar.gz", + ], + build_file = "bazel/external/msgpack.BUILD" ) diff --git a/bazel/external/msgpack.BUILD b/bazel/external/msgpack.BUILD new file mode 100644 index 00000000..a92e20c6 --- /dev/null +++ b/bazel/external/msgpack.BUILD @@ -0,0 +1,15 @@ +cc_library( + name = "msgpack", + srcs = glob([ + "src/*.c", + "include/**/*.h", + "include/**/*.hpp", + ]), + # hdrs = glob([ + # ]), + includes = [ + "include", + ], + strip_include_prefix = "include", + visibility = ["//visibility:public"], +) From 0becf4155626598f28cefa2b72ba6c5b101ec96a Mon Sep 17 00:00:00 2001 From: Caleb Gilmour Date: Sun, 29 Jul 2018 00:11:05 +0000 Subject: [PATCH 3/3] Remove commented bits. --- bazel/external/msgpack.BUILD | 2 -- 1 file changed, 2 deletions(-) diff --git a/bazel/external/msgpack.BUILD b/bazel/external/msgpack.BUILD index a92e20c6..3b3da01f 100644 --- a/bazel/external/msgpack.BUILD +++ b/bazel/external/msgpack.BUILD @@ -5,8 +5,6 @@ cc_library( "include/**/*.h", "include/**/*.hpp", ]), - # hdrs = glob([ - # ]), includes = [ "include", ],