Taken from https://github.com/abseil/abseil-cpp/pull/884 From 8ef49c10f419ff8e6e3865c06ea6dfe36be642ff Mon Sep 17 00:00:00 2001 From: Pascal Muetschard Date: Mon, 11 Jan 2021 15:17:06 -0800 Subject: [PATCH] Don't assume Windows means MSVC in the bazel BUILD files. When selecting the compiler flags, use the compiler setting, rather than the platform setting, to detect if MSVC flags are required. --- absl/BUILD.bazel | 24 ++++++++++++++++++++++++ absl/base/BUILD.bazel | 4 ++-- absl/copts/configure_copts.bzl | 6 +++--- absl/debugging/BUILD.bazel | 8 ++++---- absl/random/internal/BUILD.bazel | 6 +++--- absl/synchronization/BUILD.bazel | 2 +- 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/absl/BUILD.bazel b/absl/BUILD.bazel index 0b772df..651b3f4 100644 --- a/absl/BUILD.bazel +++ b/absl/BUILD.bazel @@ -28,6 +28,30 @@ create_llvm_config( visibility = [":__subpackages__"], ) +config_setting( + name = "msvc_compiler", + flag_values = { + "@bazel_tools//tools/cpp:compiler": "msvc-cl", + }, + visibility = [":__subpackages__"], +) + +config_setting( + name = "clang_cl_compiler", + flag_values = { + "@bazel_tools//tools/cpp:compiler": "clang-cl", + }, + visibility = [":__subpackages__"], +) + +alias( + name = "msvc_compat_compiler", + actual = select({ + ":clang_cl_compiler": ":clang_cl_compiler", + "//conditions:default": ":msvc_compiler", + }) +) + config_setting( name = "osx", constraint_values = [ diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel index 9d96abe..817c06a 100644 --- a/absl/base/BUILD.bazel +++ b/absl/base/BUILD.bazel @@ -160,7 +160,7 @@ cc_library( ], copts = ABSL_DEFAULT_COPTS, linkopts = select({ - "//absl:windows": [], + "//absl:msvc_compat_compiler": [], "//absl:wasm": [], "//conditions:default": ["-pthread"], }) + ABSL_DEFAULT_LINKOPTS, @@ -220,7 +220,7 @@ cc_library( ], copts = ABSL_DEFAULT_COPTS, linkopts = select({ - "//absl:windows": [ + "//absl:msvc_compat_compiler": [ "-DEFAULTLIB:advapi32.lib", ], "//absl:wasm": [], diff --git a/absl/copts/configure_copts.bzl b/absl/copts/configure_copts.bzl index ff9a5ea..5d00332 100644 --- a/absl/copts/configure_copts.bzl +++ b/absl/copts/configure_copts.bzl @@ -22,7 +22,7 @@ load( ) ABSL_DEFAULT_COPTS = select({ - "//absl:windows": ABSL_MSVC_FLAGS, + "//absl:msvc_compat_compiler": ABSL_MSVC_FLAGS, "//absl:llvm_compiler": ABSL_LLVM_FLAGS, "//conditions:default": ABSL_GCC_FLAGS, }) @@ -30,13 +30,13 @@ ABSL_DEFAULT_COPTS = select({ # in absence of modules (--compiler=gcc or -c opt), cc_tests leak their copts # to their (included header) dependencies and fail to build outside absl ABSL_TEST_COPTS = ABSL_DEFAULT_COPTS + select({ - "//absl:windows": ABSL_MSVC_TEST_FLAGS, + "//absl:msvc_compat_compiler": ABSL_MSVC_TEST_FLAGS, "//absl:llvm_compiler": ABSL_LLVM_TEST_FLAGS, "//conditions:default": ABSL_GCC_TEST_FLAGS, }) ABSL_DEFAULT_LINKOPTS = select({ - "//absl:windows": ABSL_MSVC_LINKOPTS, + "//absl:msvc_compat_compiler": ABSL_MSVC_LINKOPTS, "//conditions:default": [], }) diff --git a/absl/debugging/BUILD.bazel b/absl/debugging/BUILD.bazel index 86faac9..d0984b9 100644 --- a/absl/debugging/BUILD.bazel +++ b/absl/debugging/BUILD.bazel @@ -66,7 +66,7 @@ cc_library( ], copts = ABSL_DEFAULT_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS + select({ - "//absl:windows": ["-DEFAULTLIB:dbghelp.lib"], + "//absl:msvc_compat_compiler": ["-DEFAULTLIB:dbghelp.lib"], "//conditions:default": [], }), deps = [ @@ -86,11 +86,11 @@ cc_test( name = "symbolize_test", srcs = ["symbolize_test.cc"], copts = ABSL_TEST_COPTS + select({ - "//absl:windows": ["/Z7"], + "//absl:msvc_compat_compiler": ["/Z7"], "//conditions:default": [], }), linkopts = ABSL_DEFAULT_LINKOPTS + select({ - "//absl:windows": ["/DEBUG"], + "//absl:msvc_compat_compiler": ["/DEBUG"], "//conditions:default": [], }), deps = [ @@ -148,7 +148,7 @@ cc_test( srcs = ["failure_signal_handler_test.cc"], copts = ABSL_TEST_COPTS, linkopts = select({ - "//absl:windows": [], + "//absl:msvc_compat_compiler": [], "//absl:wasm": [], "//conditions:default": ["-pthread"], }) + ABSL_DEFAULT_LINKOPTS, diff --git a/absl/random/internal/BUILD.bazel b/absl/random/internal/BUILD.bazel index 8485e28..944f512 100644 --- a/absl/random/internal/BUILD.bazel +++ b/absl/random/internal/BUILD.bazel @@ -75,7 +75,7 @@ cc_library( ], copts = ABSL_DEFAULT_COPTS, linkopts = ABSL_DEFAULT_LINKOPTS + select({ - "//absl:windows": ["-DEFAULTLIB:bcrypt.lib"], + "//absl:msvc_compat_compiler": ["-DEFAULTLIB:bcrypt.lib"], "//conditions:default": [], }), deps = [ @@ -98,7 +98,7 @@ cc_library( ], copts = ABSL_DEFAULT_COPTS, linkopts = select({ - "//absl:windows": [], + "//absl:msvc_compat_compiler": [], "//absl:wasm": [], "//conditions:default": ["-pthread"], }) + ABSL_DEFAULT_LINKOPTS, @@ -320,7 +320,7 @@ cc_library( "randen_hwaes.h", ], copts = ABSL_DEFAULT_COPTS + ABSL_RANDOM_RANDEN_COPTS + select({ - "//absl:windows": [], + "//absl:msvc_compat_compiler": [], "//conditions:default": ["-Wno-pass-failed"], }), linkopts = ABSL_DEFAULT_LINKOPTS, diff --git a/absl/synchronization/BUILD.bazel b/absl/synchronization/BUILD.bazel index 4d4d680..b75bb42 100644 --- a/absl/synchronization/BUILD.bazel +++ b/absl/synchronization/BUILD.bazel @@ -89,7 +89,7 @@ cc_library( ], copts = ABSL_DEFAULT_COPTS, linkopts = select({ - "//absl:windows": [], + "//absl:msvc_compat_compiler": [], "//absl:wasm": [], "//conditions:default": ["-pthread"], }) + ABSL_DEFAULT_LINKOPTS,