From 4475ff6b8a7a4077d7492b76ef5278a3dc53a2e4 Mon Sep 17 00:00:00 2001 From: Yesudeep Mangalapilly Date: Fri, 28 Aug 2020 00:46:12 -0700 Subject: [PATCH] =?UTF-8?q?Adds=20-lm=20linker=20flag=20for=20FreeBSD/Open?= =?UTF-8?q?BSD=20and=20uses=20github.com/bazelbuil=E2=80=A6=20(#1032)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Adds -lm linker flag for (Free|Open)BSD and uses github.com/bazelbuild/platforms for platform detection. * Prefer selects.with_or to select the linkopts. * @platforms appears to be implicitly available. @bazel_skylib would require updating every dependent repository. * Re-enable platforms package. --- BUILD.bazel | 33 ++++++++++++++++++++++++++++----- WORKSPACE | 5 +++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index d97a019b..e38ebd72 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,14 +1,35 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + licenses(["notice"]) config_setting( - name = "windows", - values = { - "cpu": "x64_windows", - }, + name = "freebsd", + constraint_values = [ + "@platforms//os:freebsd", + ], visibility = [":__subpackages__"], ) -load("@rules_cc//cc:defs.bzl", "cc_library") +config_setting( + name = "openbsd", + constraint_values = [ + "@platforms//os:openbsd", + ], + visibility = [":__subpackages__"], +) + +config_setting( + name = "windows", + constraint_values = [ + "@platforms//os:windows", + ], + visibility = [":__subpackages__"], +) + +BSD_LINKOPTS = [ + "-pthread", + "-lm", +] cc_library( name = "benchmark", @@ -22,6 +43,8 @@ cc_library( hdrs = ["include/benchmark/benchmark.h"], linkopts = select({ ":windows": ["-DEFAULTLIB:shlwapi.lib"], + ":freebsd": BSD_LINKOPTS, + ":openbsd": BSD_LINKOPTS, "//conditions:default": ["-pthread"], }), strip_include_prefix = "include", diff --git a/WORKSPACE b/WORKSPACE index 5438ad36..7f2612b3 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -35,3 +35,8 @@ new_local_repository( path = "/usr/include/python3.6", # May be overwritten by setup.py. ) +http_archive( + name = "platforms", + strip_prefix = "platforms-master", + urls = ["https://github.com/bazelbuild/platforms/archive/master.zip"], +)