From 031a772acfd304fb5678e6a53e6c4ac3b99103ff Mon Sep 17 00:00:00 2001 From: Brentley Jones Date: Thu, 17 Feb 2022 15:57:21 -0600 Subject: [PATCH] Fix uses of std++ on bsd (#14860) This fix is the same as https://github.com/bazelbuild/bazel/pull/14542 but for freebsd and openbsd Hopefully fixes https://github.com/bazelbuild/rules_rust/issues/978 Closes #14668. PiperOrigin-RevId: 429354084 (cherry picked from commit a987b98ea0d6da2656c4115568ef9cbe8a164550) Co-authored-by: Keith Smiley --- tools/cpp/cc_toolchain_config.bzl | 2 +- tools/cpp/unix_cc_configure.bzl | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/cpp/cc_toolchain_config.bzl b/tools/cpp/cc_toolchain_config.bzl index 821dfc0a261afb..953e2bd38496f2 100644 --- a/tools/cpp/cc_toolchain_config.bzl +++ b/tools/cpp/cc_toolchain_config.bzl @@ -371,7 +371,7 @@ def _impl(ctx): flag_groups = [ flag_group( flags = [ - "-lstdc++", + "-lc++", "-Wl,-z,relro,-z,now", "-no-canonical-prefixes", ], diff --git a/tools/cpp/unix_cc_configure.bzl b/tools/cpp/unix_cc_configure.bzl index 8070139431e888..a2749b01c37ddd 100644 --- a/tools/cpp/unix_cc_configure.bzl +++ b/tools/cpp/unix_cc_configure.bzl @@ -340,6 +340,7 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools): repository_ctx.file("tools/cpp/empty.cc", "int main() {}") darwin = cpu_value.startswith("darwin") + bsd = cpu_value == "freebsd" or cpu_value == "openbsd" cc = find_cc(repository_ctx, overriden_tools) is_clang = _is_clang(repository_ctx, cc) @@ -400,7 +401,8 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools): False, ), ":") - bazel_linkopts = "-lc++:-lm" if darwin else "-lstdc++:-lm" + use_libcpp = darwin or bsd + bazel_linkopts = "-lc++:-lm" if use_libcpp else "-lstdc++:-lm" bazel_linklibs = "" if repository_ctx.flag_enabled("incompatible_linkopts_to_linklibs"): bazel_linkopts, bazel_linklibs = bazel_linklibs, bazel_linkopts