From e1e216ee8c5d5ad54920cc989d22e27951253d3e Mon Sep 17 00:00:00 2001 From: John Millikin Date: Tue, 20 Feb 2018 20:45:05 -0800 Subject: [PATCH 1/3] Add myself to CONTRIBUTORS under the corp CLA for Stripe, Inc. --- AUTHORS | 1 + CONTRIBUTORS | 1 + 2 files changed, 2 insertions(+) diff --git a/AUTHORS b/AUTHORS index 4e4c4ed475..81092b2244 100644 --- a/AUTHORS +++ b/AUTHORS @@ -38,6 +38,7 @@ Radoslav Yovchev Roman Lebedev Shuo Chen Steinar H. Gunderson +Stripe, Inc. Yixuan Qiu Yusuke Suzuki Zbigniew Skowron diff --git a/CONTRIBUTORS b/CONTRIBUTORS index c59134b9bd..9e9bf630fc 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -38,6 +38,7 @@ Ismael Jimenez Martinez Jern-Kuan Leong JianXiong Zhou Joao Paulo Magalhaes +John Millikin Jussi Knuuttila Kai Wolf Kishan Kumar From ce54db3f198c6538335a1aa955447da5f37d78e7 Mon Sep 17 00:00:00 2001 From: John Millikin Date: Tue, 20 Feb 2018 20:36:14 -0800 Subject: [PATCH 2/3] Add support for building with Bazel. Limitations compared to existing CMake rules: * Defaults to using C++11 ``, with an override via Bazel flag `--define` of `google_benchmark.have_regex`. The TravisCI config sets the regex implementation to `posix` because it uses ancient compilers. * Debug vs Opt mode can't be set per test. TravisCI runs all the tests in debug mode to satisfy `diagnostics_test`, which depends on `CHECK` being live. --- .gitignore | 3 +++ .travis.yml | 11 +++++++++++ BUILD.bazel | 21 ++++++++++++++++++++ WORKSPACE | 7 +++++++ bazel/BUILD | 16 +++++++++++++++ bazel/have_regex.bzl | 7 +++++++ test/BUILD | 47 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 112 insertions(+) create mode 100644 BUILD.bazel create mode 100644 WORKSPACE create mode 100644 bazel/BUILD create mode 100644 bazel/have_regex.bzl create mode 100644 test/BUILD diff --git a/.gitignore b/.gitignore index 93d5ced634..aca5f93885 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,9 @@ build.ninja install_manifest.txt rules.ninja +# bazel output symlinks. +bazel-* + # out-of-source build top-level folders. build/ _build/ diff --git a/.travis.yml b/.travis.yml index a52683f15b..137cc9876c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -159,11 +159,22 @@ install: brew update; brew install gcc@7; fi + - if [ "${TRAVIS_OS_NAME}" == "linux" ]; then + sudo apt-get update -qq; + sudo apt-get install -qq unzip; + wget https://github.com/bazelbuild/bazel/releases/download/0.10.1/bazel-0.10.1-installer-linux-x86_64.sh --output-document bazel-installer.sh; + sudo bash bazel-installer.sh; + fi + - if [ "${TRAVIS_OS_NAME}" == "osx" ]; then + curl -L -o bazel-installer.sh https://github.com/bazelbuild/bazel/releases/download/0.10.1/bazel-0.10.1-installer-darwin-x86_64.sh; + sudo bash bazel-installer.sh; + fi script: - cmake -DCMAKE_C_COMPILER=${C_COMPILER} -DCMAKE_CXX_COMPILER=${COMPILER} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_CXX_FLAGS="${EXTRA_FLAGS}" -DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON -DBENCHMARK_BUILD_32_BITS=${BUILD_32_BITS} .. - make - ctest -C ${BUILD_TYPE} --output-on-failure + - bazel test -c dbg --define google_benchmark.have_regex=posix --announce_rc --verbose_failures --test_output=errors --keep_going //test/... after_success: - if [ "${BUILD_TYPE}" == "Coverage" -a "${TRAVIS_OS_NAME}" == "linux" ]; then diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 0000000000..883ccc4439 --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,21 @@ +licenses(["notice"]) + +load("//bazel:have_regex.bzl", "have_regex_copts") + +cc_library( + name = "benchmark", + srcs = glob([ + "src/*.cc", + "src/*.h", + ]), + hdrs = ["include/benchmark/benchmark.h"], + copts = have_regex_copts(), + strip_include_prefix = "include", + visibility = ["//visibility:public"], +) + +cc_library( + name = "benchmark_internal_headers", + hdrs = glob(["src/*.h"]), + visibility = ["//test:__pkg__"], +) diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000000..78a7f00075 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,7 @@ +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +git_repository( + name = "com_google_googletest", + commit = "3f0cf6b62ad1eb50d8736538363d3580dd640c3e", # HEAD + remote = "https://github.com/google/googletest", +) diff --git a/bazel/BUILD b/bazel/BUILD new file mode 100644 index 0000000000..dcbd4376b7 --- /dev/null +++ b/bazel/BUILD @@ -0,0 +1,16 @@ +package(default_visibility = ["//:__subpackages__"]) + +config_setting( + name = "have_std_regex", + values = {"define": "google_benchmark.have_regex=std"}, +) + +config_setting( + name = "have_posix_regex", + values = {"define": "google_benchmark.have_regex=posix"}, +) + +config_setting( + name = "have_gnu_posix_regex", + values = {"define": "google_benchmark.have_regex=gnu_posix"}, +) diff --git a/bazel/have_regex.bzl b/bazel/have_regex.bzl new file mode 100644 index 0000000000..6ea5ba01a2 --- /dev/null +++ b/bazel/have_regex.bzl @@ -0,0 +1,7 @@ +def have_regex_copts(): + return select({ + "//bazel:have_std_regex": ["-DHAVE_STD_REGEX"], + "//bazel:have_posix_regex": ["-DHAVE_POSIX_REGEX"], + "//bazel:have_gnu_posix_regex": ["-DHAVE_GNU_POSIX_REGEX"], + "//conditions:default": ["-DHAVE_STD_REGEX"], + }) diff --git a/test/BUILD b/test/BUILD new file mode 100644 index 0000000000..9e5d4936d9 --- /dev/null +++ b/test/BUILD @@ -0,0 +1,47 @@ +load("//bazel:have_regex.bzl", "have_regex_copts") + +NEEDS_GTEST_MAIN = [ + "statistics_test.cc", +] + +TEST_COPTS = [ + "-pedantic", + "-pedantic-errors", + "-std=c++11", +] + have_regex_copts() + +TEST_ARGS = ["--benchmark_min_time=0.01"] + +cc_library( + name = "output_test_helper", + testonly = 1, + srcs = ["output_test_helper.cc"], + hdrs = ["output_test.h"], + copts = TEST_COPTS, + deps = [ + "//:benchmark", + "//:benchmark_internal_headers", + ], +) + +[cc_test( + name = test_src[:-len(".cc")], + size = "small", + srcs = [test_src], + args = TEST_ARGS + ({ + "user_counters_tabular_test.cc": ["--benchmark_counters_tabular=true"], + }).get(test_src, []), + copts = TEST_COPTS + ({ + "cxx03_test.cc": ["-std=c++03"], + # Some of the issues with DoNotOptimize only occur when optimization is enabled + "donotoptimize_test.cc": ["-O3"], + }).get(test_src, []), + deps = [ + ":output_test_helper", + "//:benchmark", + "//:benchmark_internal_headers", + "@com_google_googletest//:gtest", + ] + ( + ["@com_google_googletest//:gtest_main"] if (test_src in NEEDS_GTEST_MAIN) else [] + ), +) for test_src in glob(["*_test.cc"])] From fd49f8b1a8032924ed2052221a19a9ac8f67edb4 Mon Sep 17 00:00:00 2001 From: John Millikin Date: Wed, 7 Mar 2018 10:18:36 -0800 Subject: [PATCH 3/3] Set Bazel workspace name so other repos can refer to it by stable name. This is recommended by the Bazel style guide to avoid each dependent workspace defining its own name for the dependency. --- WORKSPACE | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WORKSPACE b/WORKSPACE index 78a7f00075..9ba32fd75e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,3 +1,5 @@ +workspace(name = "com_github_google_benchmark") + load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") git_repository(