From 1ab79884ac9b78e04787558bd86536381b64bc50 Mon Sep 17 00:00:00 2001 From: Yesudeep Mangalapilly Date: Thu, 23 Sep 2021 14:29:22 -0700 Subject: [PATCH 1/2] Fix linker errors on (Free|Open)BSD. --- src/BUILD.bazel | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/BUILD.bazel b/src/BUILD.bazel index d41d0fc528c..c94c7d2120a 100644 --- a/src/BUILD.bazel +++ b/src/BUILD.bazel @@ -5,6 +5,20 @@ package( default_visibility = ["//visibility:private"], ) +config_setting( + name = "platform_freebsd", + constraint_values = [ + "@platforms//os:freebsd", + ], +) + +config_setting( + name = "platform_openbsd", + constraint_values = [ + "@platforms//os:openbsd", + ], +) + # Public flatc library to compile flatbuffer files at runtime. cc_library( name = "flatbuffers", @@ -17,6 +31,11 @@ cc_library( "util.cpp", ], hdrs = ["//:public_headers"], + linkopts = select({ + ":platform_freebsd": ["-lm"], + ":platform_openbsd": ["-lm"], + "//conditions:default": [], + }), strip_include_prefix = "/include", visibility = ["//:__pkg__"], ) From aeed28ec7f48ec6d94a3a3e401a2575e5a45e209 Mon Sep 17 00:00:00 2001 From: Yesudeep Mangalapilly Date: Fri, 24 Sep 2021 19:46:27 -0700 Subject: [PATCH 2/2] Adds a TODO for the FreeBSD linker flags: -lm and moves platform config to main BUILD.bazel --- BUILD.bazel | 14 ++++++++++++++ src/BUILD.bazel | 22 ++++++---------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 4e40b718b14..395008cc232 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -10,6 +10,20 @@ exports_files([ "LICENSE", ]) +config_setting( + name = "platform_freebsd", + constraint_values = [ + "@platforms//os:freebsd", + ], +) + +config_setting( + name = "platform_openbsd", + constraint_values = [ + "@platforms//os:openbsd", + ], +) + # Public flatc library to compile flatbuffer files at runtime. cc_library( name = "flatbuffers", diff --git a/src/BUILD.bazel b/src/BUILD.bazel index c94c7d2120a..a1cad077fbd 100644 --- a/src/BUILD.bazel +++ b/src/BUILD.bazel @@ -5,20 +5,6 @@ package( default_visibility = ["//visibility:private"], ) -config_setting( - name = "platform_freebsd", - constraint_values = [ - "@platforms//os:freebsd", - ], -) - -config_setting( - name = "platform_openbsd", - constraint_values = [ - "@platforms//os:openbsd", - ], -) - # Public flatc library to compile flatbuffer files at runtime. cc_library( name = "flatbuffers", @@ -32,8 +18,12 @@ cc_library( ], hdrs = ["//:public_headers"], linkopts = select({ - ":platform_freebsd": ["-lm"], - ":platform_openbsd": ["-lm"], + # TODO: Bazel uses `clang` instead of `clang++` to link + # C++ code on BSD. Temporarily adding these linker flags while + # we wait for Bazel to resolve + # https://github.com/bazelbuild/bazel/issues/12023. + "//:platform_freebsd": ["-lm"], + "//:platform_openbsd": ["-lm"], "//conditions:default": [], }), strip_include_prefix = "/include",