Skip to content

Commit 59f1fc0

Browse files
karan1508facebook-github-bot
authored andcommitted
Fix executorch -Wno-missing-prototypes flag for Zephyr/GCC builds (pytorch#19071)
Summary: The zephyr_build target for tsn_graph_simulator cannot be built using fbcode/mode/opt because executorch's build rules unconditionally pass `-Wno-missing-prototypes` to the compiler. This flag is only valid for C++ in Clang; GCC (used by Zephyr ARM cross-compilation) recognizes it as a C-only flag and rejects it for C++ files when `-Werror` is enabled. The fix wraps `-Wno-missing-prototypes` in a `select()` that excludes it for Zephyr builds (`ovr_config//os:zephyr`), following the same pattern already used in executorch for Zephyr-specific handling (e.g., ATen header exclusion in `elementwise_util` and `math_util`). Changes across executorch build files: - `kernels/portable/op_registration_util.bzl`: Added `os:zephyr` to existing OS select - `kernels/optimized/op_registration_util.bzl`: Wrapped flags in select - `kernels/portable/cpu/util/targets.bzl`: Wrapped 8 hardcoded flags in selects - `kernels/portable/cpu/pattern/targets.bzl`: Wrapped flag in select - `kernels/aten/cpu/util/targets.bzl`: Added `os:zephyr` to existing OS select - `codegen/codegen.bzl`: Wrapped flags in `build_portable_lib` and `build_optimized_lib` Reviewed By: digantdesai Differential Revision: D100626340
1 parent c5c5b3a commit 59f1fc0

6 files changed

Lines changed: 73 additions & 19 deletions

File tree

kernels/aten/cpu/util/targets.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def define_common_targets():
1717
compiler_flags = select({
1818
"DEFAULT": ["-Wno-missing-prototypes"],
1919
"ovr_config//os:windows": [],
20+
"ovr_config//compiler/constraints:gcc": [],
2021
}),
2122
deps = [
2223
"//executorch/runtime/kernel:kernel_includes_aten",

kernels/portable/cpu/pattern/targets.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ def define_common_targets():
5454
exported_headers = [
5555
"pattern.h",
5656
],
57-
compiler_flags = ["-Wno-missing-prototypes"],
57+
compiler_flags = select({
58+
"DEFAULT": ["-Wno-missing-prototypes"],
59+
"ovr_config//compiler/constraints:gcc": [],
60+
}),
5861
exported_deps = [
5962
"//executorch/kernels/portable/cpu/util:broadcast_util",
6063
"//executorch/kernels/portable/cpu/util:functional_util",

kernels/portable/cpu/util/targets.bzl

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ def define_common_targets():
4747
exported_headers = [
4848
"activation_ops_util.h",
4949
],
50-
compiler_flags = ["-Wno-missing-prototypes"],
50+
compiler_flags = select({
51+
"DEFAULT": ["-Wno-missing-prototypes"],
52+
"ovr_config//compiler/constraints:gcc": [],
53+
}),
5154
deps = [
5255
"//executorch/runtime/core/exec_aten/util:tensor_shape_to_c_string",
5356
"//executorch/runtime/kernel:kernel_includes",
@@ -97,7 +100,10 @@ def define_common_targets():
97100
exported_headers = [
98101
"dtype_util.h",
99102
],
100-
compiler_flags = ["-Wno-missing-prototypes"],
103+
compiler_flags = select({
104+
"DEFAULT": ["-Wno-missing-prototypes"],
105+
"ovr_config//compiler/constraints:gcc": [],
106+
}),
101107
deps = [
102108
"//executorch/runtime/kernel:kernel_includes",
103109
],
@@ -109,7 +115,10 @@ def define_common_targets():
109115
exported_headers = [
110116
"elementwise_util.h",
111117
],
112-
compiler_flags = ["-Wno-missing-prototypes"],
118+
compiler_flags = select({
119+
"DEFAULT": ["-Wno-missing-prototypes"],
120+
"ovr_config//compiler/constraints:gcc": [],
121+
}),
113122
exported_deps = [
114123
":broadcast_indexes_range",
115124
":broadcast_util",
@@ -141,7 +150,10 @@ def define_common_targets():
141150
exported_headers = [
142151
"advanced_index_util.h",
143152
],
144-
compiler_flags = ["-Wno-missing-prototypes"],
153+
compiler_flags = select({
154+
"DEFAULT": ["-Wno-missing-prototypes"],
155+
"ovr_config//compiler/constraints:gcc": [],
156+
}),
145157
deps = [
146158
":broadcast_util",
147159
"//executorch/runtime/core/exec_aten/util:tensor_shape_to_c_string",
@@ -156,7 +168,10 @@ def define_common_targets():
156168
exported_headers = [
157169
"copy_ops_util.h",
158170
],
159-
compiler_flags = ["-Wno-missing-prototypes"],
171+
compiler_flags = select({
172+
"DEFAULT": ["-Wno-missing-prototypes"],
173+
"ovr_config//compiler/constraints:gcc": [],
174+
}),
160175
exported_deps = [
161176
":broadcast_util",
162177
],
@@ -172,7 +187,10 @@ def define_common_targets():
172187
exported_headers = [
173188
"distance_util.h",
174189
],
175-
compiler_flags = ["-Wno-missing-prototypes"],
190+
compiler_flags = select({
191+
"DEFAULT": ["-Wno-missing-prototypes"],
192+
"ovr_config//compiler/constraints:gcc": [],
193+
}),
176194
deps = [
177195
"//executorch/runtime/kernel:kernel_includes",
178196
],
@@ -188,7 +206,10 @@ def define_common_targets():
188206
exported_headers = [
189207
"kernel_ops_util.h",
190208
],
191-
compiler_flags = ["-Wno-missing-prototypes"],
209+
compiler_flags = select({
210+
"DEFAULT": ["-Wno-missing-prototypes"],
211+
"ovr_config//compiler/constraints:gcc": [],
212+
}),
192213
deps = [
193214
"//executorch/runtime/kernel:kernel_includes",
194215
],
@@ -201,7 +222,10 @@ def define_common_targets():
201222
exported_headers = [
202223
"matmul_ops_util.h",
203224
],
204-
compiler_flags = ["-Wno-missing-prototypes"],
225+
compiler_flags = select({
226+
"DEFAULT": ["-Wno-missing-prototypes"],
227+
"ovr_config//compiler/constraints:gcc": [],
228+
}),
205229
deps = [
206230
":broadcast_util",
207231
"//executorch/runtime/kernel:kernel_includes",
@@ -218,7 +242,10 @@ def define_common_targets():
218242
exported_headers = [
219243
"padding_util.h",
220244
],
221-
compiler_flags = ["-Wno-missing-prototypes"],
245+
compiler_flags = select({
246+
"DEFAULT": ["-Wno-missing-prototypes"],
247+
"ovr_config//compiler/constraints:gcc": [],
248+
}),
222249
deps = [
223250
"//executorch/runtime/kernel:kernel_includes",
224251
],
@@ -231,7 +258,10 @@ def define_common_targets():
231258
exported_headers = [
232259
"normalization_ops_util.h",
233260
],
234-
compiler_flags = ["-Wno-missing-prototypes"],
261+
compiler_flags = select({
262+
"DEFAULT": ["-Wno-missing-prototypes"],
263+
"ovr_config//compiler/constraints:gcc": [],
264+
}),
235265
deps = [
236266
"//executorch/runtime/kernel:kernel_includes",
237267
],

shim_et/xplat/executorch/codegen/codegen.bzl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,12 @@ def build_portable_lib(
630630
# Currently fbcode links all dependent libraries through shared
631631
# library, and it blocks users like unit tests to use kernel
632632
# implementation directly. So we enable this for xplat only.
633-
compiler_flags = ["-Wno-missing-prototypes"]
633+
# -Wno-missing-prototypes is Clang-only for C++; GCC rejects it
634+
# with -Werror.
635+
compiler_flags = select({
636+
"DEFAULT": ["-Wno-missing-prototypes"],
637+
"ovr_config//compiler/constraints:gcc": [],
638+
})
634639
if not expose_operator_symbols and is_xplat():
635640
# Removing '-fvisibility=hidden' exposes operator symbols.
636641
# This allows operators to be called outside of the kernel registry.
@@ -676,7 +681,12 @@ def build_optimized_lib(name, oplist_header_name, portable_header_lib, feature =
676681
# Currently fbcode links all dependent libraries through shared
677682
# library, and it blocks users like unit tests to use kernel
678683
# implementation directly. So we enable this for xplat only.
679-
compiler_flags = ["-Wno-missing-prototypes", "-Wno-pass-failed", "-Wno-global-constructors", "-Wno-shadow"]
684+
# -Wno-missing-prototypes is Clang-only for C++; GCC rejects it
685+
# with -Werror.
686+
compiler_flags = select({
687+
"DEFAULT": ["-Wno-missing-prototypes", "-Wno-pass-failed", "-Wno-global-constructors", "-Wno-shadow"],
688+
"ovr_config//compiler/constraints:gcc": ["-Wno-pass-failed", "-Wno-shadow"],
689+
})
680690
if not expose_operator_symbols and is_xplat():
681691
# Removing '-fvisibility=hidden' exposes operator symbols.
682692
# This allows operators to be called outside of the kernel registry.

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,21 @@ def define_op_library(name, compiler_flags, deps):
9393
"{}.cpp".format(name),
9494
],
9595
visibility = ["PUBLIC"],
96-
compiler_flags = [
96+
compiler_flags = select({
9797
# kernels often have helpers with no prototypes just disabling the warning here as the headers
9898
# are codegend and linked in later
99-
"-Wno-missing-prototypes",
100-
# pragma unroll fails with -Os, don't need to warn us and
101-
# fail Werror builds; see https://godbolt.org/z/zvf85vTsr
102-
"-Wno-pass-failed",
103-
] + compiler_flags + get_compiler_optimization_flags(),
99+
# -Wno-missing-prototypes is Clang-only for C++; GCC rejects it
100+
# with -Werror.
101+
"DEFAULT": [
102+
"-Wno-missing-prototypes",
103+
# pragma unroll fails with -Os, don't need to warn us and
104+
# fail Werror builds; see https://godbolt.org/z/zvf85vTsr
105+
"-Wno-pass-failed",
106+
],
107+
"ovr_config//compiler/constraints:gcc": [
108+
"-Wno-pass-failed",
109+
],
110+
}) + compiler_flags + get_compiler_optimization_flags(),
104111
# sleef needs to be added as a direct dependency of the operator target when building for Android,
105112
# or a linker error may occur. Not sure why this happens; it seems that fbandroid_platform_deps of
106113
# dependencies are not transitive

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,12 @@ def define_op_library(name, deps, android_deps, aten_target, _allow_third_party_
119119
visibility = ["PUBLIC"],
120120
# kernels often have helpers with no prototypes just disabling the warning here as the headers
121121
# are codegend and linked in later
122+
# -Wno-missing-prototypes is Clang-only for C++; GCC rejects it
123+
# with -Werror, so exclude it for GCC and Windows builds.
122124
compiler_flags = select({
123125
"DEFAULT": ["-Wno-missing-prototypes"],
124126
"ovr_config//os:windows": [],
127+
"ovr_config//compiler/constraints:gcc": [],
125128
}) + (
126129
# For shared library build, we don't want to expose symbols of
127130
# kernel implementation (ex torch::executor::native::tanh_out)

0 commit comments

Comments
 (0)