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.
This commit is contained in:
Rodrigo Queiro 2022-03-02 12:34:46 +01:00 committed by Rodrigo Queiro
parent d153e294b8
commit 5addeedc0a
2 changed files with 18 additions and 8 deletions

View File

@ -47,18 +47,12 @@ tasks:
environment: environment:
BAZEL_VC: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC" BAZEL_VC: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC"
build_flags: build_flags:
- "--incompatible_enable_cc_toolchain_resolution" - "--compiler=clang-cl"
- "--extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl"
- "--extra_execution_platforms=//:x64_windows-clang-cl"
- "--features=layering_check" - "--features=layering_check"
- "--copt=-Wno-macro-redefined"
build_targets: build_targets:
- "//..." - "//..."
test_flags: test_flags:
- "--incompatible_enable_cc_toolchain_resolution" - "--compiler=clang-cl"
- "--extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl"
- "--extra_execution_platforms=//:x64_windows-clang-cl"
- "--features=layering_check" - "--features=layering_check"
- "--copt=-Wno-macro-redefined"
test_targets: test_targets:
- "//..." - "//..."

View File

@ -46,6 +46,12 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
values = {"cpu": "wasm"}, values = {"cpu": "wasm"},
) )
# Detect when building with clang-cl on Windows.
native.config_setting(
name = "clang-cl",
values = {"compiler": "clang-cl"},
)
common_copts = [ common_copts = [
"-DGLOG_BAZEL_BUILD", "-DGLOG_BAZEL_BUILD",
# Inject a C++ namespace. # Inject a C++ namespace.
@ -100,12 +106,18 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
] ]
windows_only_copts = [ windows_only_copts = [
# Override -DGLOG_EXPORT= from the cc_library's defines.
"-DGLOG_EXPORT=__declspec(dllexport)", "-DGLOG_EXPORT=__declspec(dllexport)",
"-DGLOG_NO_ABBREVIATED_SEVERITIES", "-DGLOG_NO_ABBREVIATED_SEVERITIES",
"-DHAVE_SNPRINTF", "-DHAVE_SNPRINTF",
"-I" + src_windows, "-I" + src_windows,
] ]
clang_cl_only_copts = [
# Allow the override of -DGLOG_EXPORT.
"-Wno-macro-redefined",
]
windows_only_srcs = [ windows_only_srcs = [
"src/glog/log_severity.h", "src/glog/log_severity.h",
"src/windows/dirent.h", "src/windows/dirent.h",
@ -173,6 +185,10 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
"@bazel_tools//src/conditions:freebsd": common_copts + linux_or_darwin_copts + freebsd_only_copts, "@bazel_tools//src/conditions:freebsd": common_copts + linux_or_darwin_copts + freebsd_only_copts,
":wasm": common_copts + wasm_copts, ":wasm": common_copts + wasm_copts,
"//conditions:default": common_copts + linux_or_darwin_copts, "//conditions:default": common_copts + linux_or_darwin_copts,
}) +
select({
":clang-cl": clang_cl_only_copts,
"//conditions:default": []
}), }),
deps = gflags_deps + select({ deps = gflags_deps + select({
"@bazel_tools//src/conditions:windows": [":strip_include_prefix_hack"], "@bazel_tools//src/conditions:windows": [":strip_include_prefix_hack"],