Fix "'GLOG_EXPORT' macro redefined" on clang-cl
The previous approach used
--incompatible_enable_cc_toolchain_resolution, which is recommended by
the docs, but a Bazel developer told me it's obsolete. The new, old
approach is simpler and should stop the warning from being user-visible.
diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml
index eaf889f..9065173 100644
--- a/.bazelci/presubmit.yml
+++ b/.bazelci/presubmit.yml
@@ -47,18 +47,12 @@
environment:
BAZEL_VC: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC"
build_flags:
- - "--incompatible_enable_cc_toolchain_resolution"
- - "--extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl"
- - "--extra_execution_platforms=//:x64_windows-clang-cl"
+ - "--compiler=clang-cl"
- "--features=layering_check"
- - "--copt=-Wno-macro-redefined"
build_targets:
- "//..."
test_flags:
- - "--incompatible_enable_cc_toolchain_resolution"
- - "--extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl"
- - "--extra_execution_platforms=//:x64_windows-clang-cl"
+ - "--compiler=clang-cl"
- "--features=layering_check"
- - "--copt=-Wno-macro-redefined"
test_targets:
- "//..."
diff --git a/bazel/glog.bzl b/bazel/glog.bzl
index dcf6f41..4208d9e 100644
--- a/bazel/glog.bzl
+++ b/bazel/glog.bzl
@@ -46,6 +46,12 @@
values = {"cpu": "wasm"},
)
+ # Detect when building with clang-cl on Windows.
+ native.config_setting(
+ name = "clang-cl",
+ values = {"compiler": "clang-cl"},
+ )
+
common_copts = [
"-DGLOG_BAZEL_BUILD",
# Inject a C++ namespace.
@@ -100,12 +106,18 @@
]
windows_only_copts = [
+ # Override -DGLOG_EXPORT= from the cc_library's defines.
"-DGLOG_EXPORT=__declspec(dllexport)",
"-DGLOG_NO_ABBREVIATED_SEVERITIES",
"-DHAVE_SNPRINTF",
"-I" + src_windows,
]
+ clang_cl_only_copts = [
+ # Allow the override of -DGLOG_EXPORT.
+ "-Wno-macro-redefined",
+ ]
+
windows_only_srcs = [
"src/glog/log_severity.h",
"src/windows/dirent.h",
@@ -173,6 +185,10 @@
"@bazel_tools//src/conditions:freebsd": common_copts + linux_or_darwin_copts + freebsd_only_copts,
":wasm": common_copts + wasm_copts,
"//conditions:default": common_copts + linux_or_darwin_copts,
+ }) +
+ select({
+ ":clang-cl": clang_cl_only_copts,
+ "//conditions:default": []
}),
deps = gflags_deps + select({
"@bazel_tools//src/conditions:windows": [":strip_include_prefix_hack"],