Skip to content

Commit f730254

Browse files
committed
[ET][Windows] Relax -Werror for ExecuTorch CPU kernels on the Windows host
Pull Request resolved: #20949 The arvr Windows clang toolchain enables a stricter `-Werror` warning set than the sanctioned ET build platforms, and vendored third-party headers that ExecuTorch does not own trip it. VMA's `vk_mem_alloc.h` hits `-Werror,-Winconsistent-missing-destructor-override`, and PyTorch's `ATen/cpu/vec/vec_base.h` uses `#if __GNUC__ <= 12` without `defined(__GNUC__)`, hitting `-Werror,-Wundef`. Because the offending code is in vendored headers we cannot patch, this disables warnings-as-errors for the affected compiles, scoped to `ovr_config//os:windows` only, so the clang target compiles are relaxed while the MSVC host tools and all non-Windows platforms are untouched. `backends/vulkan/targets.bzl` adds `-Wno-error` to the Vulkan targets (VMA header). The CPU-kernel build is split across four independent macros/targets, each of which includes the ATen vec headers and so needs the same relaxation: `kernels/portable/op_registration_util.bzl`, `kernels/optimized/op_registration_util.bzl`, the `binary_ops` support library in `kernels/optimized/cpu/targets.bzl`, and the `libblas` support library in `kernels/optimized/lib_defs.bzl`. ghstack-source-id: 402995445 @exported-using-ghexport Differential Revision: [D112012049](https://our.internmc.facebook.com/intern/diff/D112012049/)
1 parent b34d238 commit f730254

5 files changed

Lines changed: 50 additions & 3 deletions

File tree

backends/vulkan/targets.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ def get_vulkan_compiler_flags():
1010
"-Wno-global-constructors",
1111
"-Wno-missing-prototypes",
1212
],
13-
"ovr_config//os:windows": [],
13+
# The Windows clang host build needs -Werror relaxed for the vendored
14+
# VMA headers, but MSVC cl.exe rejects the gcc-style flag, so exclude
15+
# pure MSVC. OSS buck2 has no compiler constraint, so guard to non-OSS.
16+
"ovr_config//os:windows": select({
17+
"DEFAULT": ["-Wno-error"],
18+
"ovr_config//compiler:msvc": [],
19+
}) if not runtime.is_oss else ["-Wno-error"],
1420
})
1521

1622
def get_vulkan_preprocessor_flags(no_volk, is_fbcode):

kernels/optimized/cpu/targets.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ def define_common_targets():
4848
srcs = ["binary_ops.cpp"],
4949
exported_headers = ["binary_ops.h"],
5050
visibility = ["PUBLIC"],
51+
# ATen vec headers trip -Werror warnings on the Windows clang host;
52+
# MSVC cl.exe rejects the gcc-style flag.
53+
compiler_flags = select({
54+
"DEFAULT": [],
55+
# OSS buck2 has no compiler constraint (ovr_config//compiler:msvc
56+
# resolves to the nonexistent prelude//compiler:msvc), so it cannot
57+
# appear as a select key there; guard the MSVC branch to non-OSS.
58+
"ovr_config//os:windows": select({
59+
"DEFAULT": ["-Wno-error"],
60+
"ovr_config//compiler:msvc": [],
61+
}) if not runtime.is_oss else ["-Wno-error"],
62+
}),
5163
exported_deps = [
5264
"//executorch/runtime/core/exec_aten:lib",
5365
"//executorch/runtime/kernel:kernel_includes",

kernels/optimized/lib_defs.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ def define_libs(is_fbcode=False):
214214
# TODO: replace with get_compiler_optimization_flags from op_registration_util.bzl when that
215215
# is re-enabled.
216216
"DEFAULT": ["-Os"],
217+
}) + select({
218+
"DEFAULT": [],
219+
# ATen vec headers trip -Werror warnings on the Windows clang
220+
# host; MSVC cl.exe rejects the gcc-style flag. OSS buck2 has no
221+
# compiler constraint, so guard the MSVC branch to non-OSS.
222+
"ovr_config//os:windows": select({
223+
"DEFAULT": ["-Wno-error"],
224+
"ovr_config//compiler:msvc": [],
225+
}) if not runtime.is_oss else ["-Wno-error"],
217226
}),
218227
header_namespace = "executorch/kernels/optimized",
219228
visibility = ["PUBLIC"],

shim_et/xplat/executorch/kernels/optimized/op_registration_util.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ def define_op_library(name, compiler_flags, deps):
109109
"ovr_config//os:zephyr": [
110110
"-Wno-pass-failed",
111111
],
112+
# The vendored ATen vec headers trip several -Werror warnings on
113+
# the Windows (clang) host, so disable warnings-as-errors there.
114+
"ovr_config//os:windows": select({
115+
"DEFAULT": [
116+
"-Wno-missing-prototypes",
117+
"-Wno-pass-failed",
118+
"-Wno-error",
119+
],
120+
# MSVC cl.exe rejects the gcc-style flags above.
121+
"ovr_config//compiler:msvc": [],
122+
}),
112123
}) if not runtime.is_oss else [
113124
"-Wno-missing-prototypes",
114125
"-Wno-pass-failed",

shim_et/xplat/executorch/kernels/portable/op_registration_util.bzl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,22 @@ def define_op_library(name, deps, android_deps, aten_target, _allow_third_party_
124124
# Zephyr and Windows builds. OSS bypasses the zephyr branch via
125125
# runtime.is_oss since ovr_config//os:zephyr is not in the OSS
126126
# buck2 prelude.
127+
# The vendored ATen vec headers pulled in on the Windows host trip
128+
# several -Werror warnings (e.g. -Wundef on __GNUC__), so disable
129+
# warnings-as-errors for the Windows (clang) kernel compiles.
127130
compiler_flags = (select({
128131
"DEFAULT": ["-Wno-missing-prototypes"],
129-
"ovr_config//os:windows": [],
132+
"ovr_config//os:windows": select({
133+
"DEFAULT": ["-Wno-error"],
134+
"ovr_config//compiler:msvc": [],
135+
}),
130136
"ovr_config//os:zephyr": [],
131137
}) if not runtime.is_oss else select({
132138
"DEFAULT": ["-Wno-missing-prototypes"],
133-
"ovr_config//os:windows": [],
139+
# OSS buck2 has no compiler constraint (ovr_config//compiler:msvc
140+
# resolves to the nonexistent prelude//compiler:msvc), so it
141+
# cannot appear as a select key. Use the clang flag directly.
142+
"ovr_config//os:windows": ["-Wno-error"],
134143
})) + (
135144
# For shared library build, we don't want to expose symbols of
136145
# kernel implementation (ex torch::executor::native::tanh_out)

0 commit comments

Comments
 (0)