diff --git a/BUILD b/BUILD index ab89e5ea2dc..ae117911459 100644 --- a/BUILD +++ b/BUILD @@ -19,6 +19,7 @@ load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") load( "//bazel:grpc_build_system.bzl", "grpc_cc_library", + "grpc_clang_cl_settings", "grpc_filegroup", "grpc_generate_one_off_targets", "grpc_upb_proto_library", @@ -66,6 +67,8 @@ bool_flag( build_setting_default = False, ) +grpc_clang_cl_settings() + config_setting( name = "grpc_no_rls_flag", flag_values = {":disable_grpc_rls": "true"}, @@ -216,6 +219,11 @@ config_setting( values = {"define": "use_strict_warning=true"}, ) +config_setting( + name = "use_strict_warning_windows", + values = {"define": "use_strict_warning_windows=true"}, +) + python_config_settings() # This should be updated along with build_handwritten.yaml diff --git a/bazel/copts.bzl b/bazel/copts.bzl index 47151000566..6149e5cfba5 100644 --- a/bazel/copts.bzl +++ b/bazel/copts.bzl @@ -57,7 +57,104 @@ GRPC_LLVM_WARNING_FLAGS = [ "-Wno-unused-function", ] +GRPC_LLVM_WINDOWS_WARNING_FLAGS = GRPC_LLVM_WARNING_FLAGS + [ + ### Some checks that are missing with clang-cl + "-Wthread-safety", + "-Wreorder-ctor", + + ### Avoid some checks that are default on clang-cl + "-Wno-c++98-compat-pedantic", + "-Wno-missing-prototypes", + "-Wno-thread-safety-precise", # too many aliases + + # abseil offenses + "-Wno-comma", + "-Wno-deprecated-redundant-constexpr-static-def", + "-Wno-deprecated", # remove when the above works in all clang versions we test with + "-Wno-float-equal", + "-Wno-gcc-compat", + "-Wno-reserved-identifier", + "-Wno-thread-safety-negative", + "-Wno-sign-compare", + + # re2 offenses + "-Wno-zero-as-null-pointer-constant", + + # ares offenses + "-Wno-macro-redefined", + + # protobuf offenses + "-Wno-cast-align", + "-Wno-inconsistent-missing-destructor-override", + + # xxhash offenses + "-Wno-disabled-macro-expansion", + + # benchmark offenses + "-Wno-shift-sign-overflow", + + # Evidently nodiscard is inappropriately pinned as a C++17 feature + "-Wno-c++17-attribute-extensions", + + # declarations are not used in many places + "-Wno-missing-variable-declarations", + + # TODO: delete iomgr + "-Wno-old-style-cast", + "-Wno-cast-qual", + "-Wno-unused-member-function", + "-Wno-unused-template", + + # TODO(hork): see if the TraceFlag offense can be removed + "-Wno-global-constructors", + # TODO(hork): clean up EE offenses + "-Wno-missing-field-initializers", + "-Wno-non-virtual-dtor", + + # TODO(ctiller): offense: dump_args. signed to unsigned + "-Wno-sign-conversion", + "-Wno-shorten-64-to-32", + + # TODO: general cleanup required. Maybe new developer or rainy day projects. + "-Wno-unreachable-code-break", + "-Wno-unreachable-code-return", + "-Wno-unreachable-code", + "-Wno-used-but-marked-unused", + "-Wno-newline-eof", + "-Wno-unused-const-variable", + "-Wno-extra-semi", + "-Wno-extra-semi-stmt", + "-Wno-suggest-destructor-override", + "-Wno-shadow", + "-Wno-missing-noreturn", + "-Wno-nested-anon-types", + "-Wno-gnu-anonymous-struct", + "-Wno-nonportable-system-include-path", + "-Wno-microsoft-cast", + "-Wno-exit-time-destructors", + "-Wno-undef", # #if to #ifdef + "-Wno-unused-macros", + "-Wno-redundant-parens", + "-Wno-undefined-func-template", + "-Wno-gnu-zero-variadic-macro-arguments", + "-Wno-double-promotion", + "-Wno-implicit-float-conversion", + "-Wno-implicit-int-conversion", + "-Wno-float-conversion", + "-Wno-unused-parameter", + "-Wno-suggest-override", + "-Wno-documentation", + "-Wno-documentation-unknown-command", + + ### possibly bad warnings for this codebase + "-Wno-covered-switch-default", + "-Wno-switch-enum", + "-Wno-c99-extensions", + "-Wno-unused-private-field", # GRPC_UNUSED does not appear to work for private fields +] + GRPC_DEFAULT_COPTS = select({ "//:use_strict_warning": GRPC_LLVM_WARNING_FLAGS + ["-DUSE_STRICT_WARNING=1"], + "//:use_strict_warning_windows": GRPC_LLVM_WINDOWS_WARNING_FLAGS + ["-DUSE_STRICT_WARNING=1"], "//conditions:default": [], }) diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl index 153002b7d57..ee051a5b6aa 100644 --- a/bazel/grpc_build_system.bzl +++ b/bazel/grpc_build_system.bzl @@ -45,6 +45,7 @@ def if_not_windows(a): return select({ "//:windows": [], "//:windows_msvc": [], + "//:windows_clang": [], "//conditions:default": a, }) @@ -52,6 +53,7 @@ def if_windows(a): return select({ "//:windows": a, "//:windows_msvc": a, + "//:windows_clang": a, "//conditions:default": [], }) @@ -802,3 +804,22 @@ def python_config_settings(): name = "python3", flag_values = {"@bazel_tools//tools/python:python_version": "PY3"}, ) + +# buildifier: disable=unnamed-macro +def grpc_clang_cl_settings(): + native.platform( + name = "x64_windows-clang-cl", + constraint_values = [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + "@bazel_tools//tools/cpp:clang-cl", + ], + ) + native.config_setting( + name = "windows_clang", + constraint_values = [ + "@platforms//cpu:x86_64", + "@platforms//os:windows", + "@bazel_tools//tools/cpp:clang-cl", + ], + ) diff --git a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl index caa68583f6d..73a59257d7c 100644 --- a/bazel/grpc_deps.bzl +++ b/bazel/grpc_deps.bzl @@ -222,6 +222,7 @@ def grpc_deps(): ], patches = [ "@com_github_grpc_grpc//third_party:protobuf.patch", + "@com_github_grpc_grpc//third_party:protobuf.10007.patch", ], patch_args = ["-p1"], ) diff --git a/src/core/BUILD b/src/core/BUILD index 5b06f6e331d..b80a69b5a2a 100644 --- a/src/core/BUILD +++ b/src/core/BUILD @@ -2733,6 +2733,7 @@ grpc_cc_library( { "//:windows": ["windows_event_engine"], "//:windows_msvc": ["windows_event_engine"], + "//:windows_clang": ["windows_event_engine"], "//:windows_other": ["windows_event_engine"], "//:mac": [ "posix_event_engine", diff --git a/third_party/protobuf.10007.patch b/third_party/protobuf.10007.patch new file mode 100644 index 00000000000..e64bd384ece --- /dev/null +++ b/third_party/protobuf.10007.patch @@ -0,0 +1,30 @@ +diff --git a/build_defs/BUILD.bazel b/build_defs/BUILD.bazel +index 1c72eba68..176ab5a91 100644 +--- a/build_defs/BUILD.bazel ++++ b/build_defs/BUILD.bazel +@@ -14,10 +14,24 @@ package( + ) + + create_compiler_config_setting( +- name = "config_msvc", ++ name = "config_msvc_cl", + value = "msvc-cl", + ) + ++# Caveat: clang-cl support in protobuf is only best-effort / untested for now. ++create_compiler_config_setting( ++ name = "config_clang_cl", ++ value = "clang-cl", ++) ++ ++selects.config_setting_group( ++ name = "config_msvc", ++ match_any = [ ++ ":config_clang_cl", ++ ":config_msvc_cl", ++ ], ++) ++ + config_setting( + name = "aarch64", + values = {"cpu": "linux-aarch_64"}, diff --git a/tools/bazel.rc b/tools/bazel.rc index 409c34a2b5d..36ec153f52a 100644 --- a/tools/bazel.rc +++ b/tools/bazel.rc @@ -44,6 +44,12 @@ build:macos --dynamic_mode=off build:windows_opt --compilation_mode=opt build:windows_dbg --compilation_mode=dbg +build:clang-cl --extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl +build:clang-cl --extra_execution_platforms=//:x64_windows-clang-cl +build:clang-cl --incompatible_enable_cc_toolchain_resolution +build:clang-cl --define=use_strict_warning_windows=true +build:clang-cl --compiler=clang-cl + build:asan --strip=never build:asan --copt=-fsanitize=address build:asan --copt=-O0