From 309de5988eb949a27e077a24a1d83c0687d10d57 Mon Sep 17 00:00:00 2001 From: Paul Wankadia Date: Tue, 8 Oct 2019 21:09:51 +1100 Subject: [PATCH] Switch to Starlark for C++ rules. (#887) While I'm here, format all of the files that I touched. --- BUILD.bazel | 2 ++ WORKSPACE | 12 +++++++++--- test/BUILD | 48 ++++++++++++++++++++++++++++-------------------- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 6ee69f29..d97a019b 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -8,6 +8,8 @@ config_setting( visibility = [":__subpackages__"], ) +load("@rules_cc//cc:defs.bzl", "cc_library") + cc_library( name = "benchmark", srcs = glob( diff --git a/WORKSPACE b/WORKSPACE index 9a75f968..8df248a4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,7 +3,13 @@ workspace(name = "com_github_google_benchmark") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( - name = "com_google_googletest", - urls = ["https://github.com/google/googletest/archive/3f0cf6b62ad1eb50d8736538363d3580dd640c3e.zip"], - strip_prefix = "googletest-3f0cf6b62ad1eb50d8736538363d3580dd640c3e", + name = "rules_cc", + strip_prefix = "rules_cc-a508235df92e71d537fcbae0c7c952ea6957a912", + urls = ["https://github.com/bazelbuild/rules_cc/archive/a508235df92e71d537fcbae0c7c952ea6957a912.zip"], +) + +http_archive( + name = "com_google_googletest", + strip_prefix = "googletest-3f0cf6b62ad1eb50d8736538363d3580dd640c3e", + urls = ["https://github.com/google/googletest/archive/3f0cf6b62ad1eb50d8736538363d3580dd640c3e.zip"], ) diff --git a/test/BUILD b/test/BUILD index 3f174c48..9bb8cb02 100644 --- a/test/BUILD +++ b/test/BUILD @@ -5,7 +5,7 @@ TEST_COPTS = [ "-Wall", "-Wextra", "-Wshadow", -# "-Wshorten-64-to-32", + # "-Wshorten-64-to-32", "-Wfloat-equal", "-fstrict-aliasing", ] @@ -16,13 +16,14 @@ PER_SRC_COPTS = ({ "donotoptimize_test.cc": ["-O3"], }) - TEST_ARGS = ["--benchmark_min_time=0.01"] PER_SRC_TEST_ARGS = ({ "user_counters_tabular_test.cc": ["--benchmark_counters_tabular=true"], }) +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") + cc_library( name = "output_test_helper", testonly = 1, @@ -36,24 +37,31 @@ cc_library( ) [ - cc_test( - name = test_src[:-len(".cc")], - size = "small", - srcs = [test_src], - args = TEST_ARGS + PER_SRC_TEST_ARGS.get(test_src, []), - copts = TEST_COPTS + PER_SRC_COPTS.get(test_src, []), - deps = [ - ":output_test_helper", - "//:benchmark", - "//:benchmark_internal_headers", - "@com_google_googletest//:gtest", - ] + ( - ["@com_google_googletest//:gtest_main"] if (test_src[-len("gtest.cc"):] == "gtest.cc") else [] - ), - # FIXME: Add support for assembly tests to bazel. - # See Issue #556 - # https://github.com/google/benchmark/issues/556 - ) for test_src in glob(["*test.cc"], exclude = ["*_assembly_test.cc", "link_main_test.cc"]) + cc_test( + name = test_src[:-len(".cc")], + size = "small", + srcs = [test_src], + args = TEST_ARGS + PER_SRC_TEST_ARGS.get(test_src, []), + copts = TEST_COPTS + PER_SRC_COPTS.get(test_src, []), + deps = [ + ":output_test_helper", + "//:benchmark", + "//:benchmark_internal_headers", + "@com_google_googletest//:gtest", + ] + ( + ["@com_google_googletest//:gtest_main"] if (test_src[-len("gtest.cc"):] == "gtest.cc") else [] + ), + # FIXME: Add support for assembly tests to bazel. + # See Issue #556 + # https://github.com/google/benchmark/issues/556 + ) + for test_src in glob( + ["*test.cc"], + exclude = [ + "*_assembly_test.cc", + "link_main_test.cc", + ], + ) ] cc_test(