Skip to content

Commit

Permalink
Adds -lm linker flag for FreeBSD/OpenBSD and uses github.com/bazelbui…
Browse files Browse the repository at this point in the history
…l… (#1032)

* 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.
  • Loading branch information
yesudeep authored Aug 28, 2020
1 parent 01c0ab7 commit 4475ff6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
31 changes: 27 additions & 4 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
load("@rules_cc//cc:defs.bzl", "cc_library")

licenses(["notice"])

config_setting(
name = "freebsd",
constraint_values = [
"@platforms//os:freebsd",
],
visibility = [":__subpackages__"],
)

config_setting(
name = "openbsd",
constraint_values = [
"@platforms//os:openbsd",
],
visibility = [":__subpackages__"],
)

config_setting(
name = "windows",
values = {
"cpu": "x64_windows",
},
constraint_values = [
"@platforms//os:windows",
],
visibility = [":__subpackages__"],
)

load("@rules_cc//cc:defs.bzl", "cc_library")
BSD_LINKOPTS = [
"-pthread",
"-lm",
]

cc_library(
name = "benchmark",
Expand All @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)

0 comments on commit 4475ff6

Please sign in to comment.