Skip to content

Commit

Permalink
Fix "'GLOG_EXPORT' macro redefined" on clang-cl
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
drigz committed Mar 8, 2022
1 parent d153e29 commit 5addeed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
10 changes: 2 additions & 8 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,12 @@ tasks:
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:
- "//..."
16 changes: 16 additions & 0 deletions bazel/glog.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
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.
Expand Down Expand Up @@ -100,12 +106,18 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
]

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",
Expand Down Expand Up @@ -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,
":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"],
Expand Down

0 comments on commit 5addeed

Please sign in to comment.