Skip to content

Commit ce9fddf

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` Differential Revision: D100626340
1 parent 1debeb6 commit ce9fddf

6 files changed

Lines changed: 104 additions & 19 deletions

File tree

kernels/aten/cpu/util/targets.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ def define_common_targets():
1717
compiler_flags = select({
1818
"DEFAULT": ["-Wno-missing-prototypes"],
1919
"ovr_config//os:windows": [],
20+
# ovr_config//os:zephyr is fbsource-internal; OSS bypasses
21+
# this branch via runtime.is_oss.
22+
"ovr_config//os:zephyr": [],
23+
}) if not runtime.is_oss else select({
24+
"DEFAULT": ["-Wno-missing-prototypes"],
25+
"ovr_config//os:windows": [],
2026
}),
2127
deps = [
2228
"//executorch/runtime/kernel:kernel_includes_aten",

kernels/portable/cpu/pattern/targets.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ 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//os:zephyr is fbsource-internal; OSS bypasses this select via runtime.is_oss.
60+
"ovr_config//os:zephyr": [],
61+
}) if not runtime.is_oss else ["-Wno-missing-prototypes"],
5862
exported_deps = [
5963
"//executorch/kernels/portable/cpu/util:broadcast_util",
6064
"//executorch/kernels/portable/cpu/util:functional_util",

kernels/portable/cpu/util/targets.bzl

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ 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//os:zephyr is fbsource-internal; OSS bypasses this select via runtime.is_oss.
53+
"ovr_config//os:zephyr": [],
54+
}) if not runtime.is_oss else ["-Wno-missing-prototypes"],
5155
deps = [
5256
"//executorch/runtime/core/exec_aten/util:tensor_shape_to_c_string",
5357
"//executorch/runtime/kernel:kernel_includes",
@@ -97,7 +101,11 @@ def define_common_targets():
97101
exported_headers = [
98102
"dtype_util.h",
99103
],
100-
compiler_flags = ["-Wno-missing-prototypes"],
104+
compiler_flags = select({
105+
"DEFAULT": ["-Wno-missing-prototypes"],
106+
# ovr_config//os:zephyr is fbsource-internal; OSS bypasses this select via runtime.is_oss.
107+
"ovr_config//os:zephyr": [],
108+
}) if not runtime.is_oss else ["-Wno-missing-prototypes"],
101109
deps = [
102110
"//executorch/runtime/kernel:kernel_includes",
103111
],
@@ -109,7 +117,11 @@ def define_common_targets():
109117
exported_headers = [
110118
"elementwise_util.h",
111119
],
112-
compiler_flags = ["-Wno-missing-prototypes"],
120+
compiler_flags = select({
121+
"DEFAULT": ["-Wno-missing-prototypes"],
122+
# ovr_config//os:zephyr is fbsource-internal; OSS bypasses this select via runtime.is_oss.
123+
"ovr_config//os:zephyr": [],
124+
}) if not runtime.is_oss else ["-Wno-missing-prototypes"],
113125
exported_deps = [
114126
":broadcast_indexes_range",
115127
":broadcast_util",
@@ -141,7 +153,11 @@ def define_common_targets():
141153
exported_headers = [
142154
"advanced_index_util.h",
143155
],
144-
compiler_flags = ["-Wno-missing-prototypes"],
156+
compiler_flags = select({
157+
"DEFAULT": ["-Wno-missing-prototypes"],
158+
# ovr_config//os:zephyr is fbsource-internal; OSS bypasses this select via runtime.is_oss.
159+
"ovr_config//os:zephyr": [],
160+
}) if not runtime.is_oss else ["-Wno-missing-prototypes"],
145161
deps = [
146162
":broadcast_util",
147163
"//executorch/runtime/core/exec_aten/util:tensor_shape_to_c_string",
@@ -156,7 +172,11 @@ def define_common_targets():
156172
exported_headers = [
157173
"copy_ops_util.h",
158174
],
159-
compiler_flags = ["-Wno-missing-prototypes"],
175+
compiler_flags = select({
176+
"DEFAULT": ["-Wno-missing-prototypes"],
177+
# ovr_config//os:zephyr is fbsource-internal; OSS bypasses this select via runtime.is_oss.
178+
"ovr_config//os:zephyr": [],
179+
}) if not runtime.is_oss else ["-Wno-missing-prototypes"],
160180
exported_deps = [
161181
":broadcast_util",
162182
],
@@ -172,7 +192,11 @@ def define_common_targets():
172192
exported_headers = [
173193
"distance_util.h",
174194
],
175-
compiler_flags = ["-Wno-missing-prototypes"],
195+
compiler_flags = select({
196+
"DEFAULT": ["-Wno-missing-prototypes"],
197+
# ovr_config//os:zephyr is fbsource-internal; OSS bypasses this select via runtime.is_oss.
198+
"ovr_config//os:zephyr": [],
199+
}) if not runtime.is_oss else ["-Wno-missing-prototypes"],
176200
deps = [
177201
"//executorch/runtime/kernel:kernel_includes",
178202
],
@@ -188,7 +212,11 @@ def define_common_targets():
188212
exported_headers = [
189213
"kernel_ops_util.h",
190214
],
191-
compiler_flags = ["-Wno-missing-prototypes"],
215+
compiler_flags = select({
216+
"DEFAULT": ["-Wno-missing-prototypes"],
217+
# ovr_config//os:zephyr is fbsource-internal; OSS bypasses this select via runtime.is_oss.
218+
"ovr_config//os:zephyr": [],
219+
}) if not runtime.is_oss else ["-Wno-missing-prototypes"],
192220
deps = [
193221
"//executorch/runtime/kernel:kernel_includes",
194222
],
@@ -201,7 +229,11 @@ def define_common_targets():
201229
exported_headers = [
202230
"matmul_ops_util.h",
203231
],
204-
compiler_flags = ["-Wno-missing-prototypes"],
232+
compiler_flags = select({
233+
"DEFAULT": ["-Wno-missing-prototypes"],
234+
# ovr_config//os:zephyr is fbsource-internal; OSS bypasses this select via runtime.is_oss.
235+
"ovr_config//os:zephyr": [],
236+
}) if not runtime.is_oss else ["-Wno-missing-prototypes"],
205237
deps = [
206238
":broadcast_util",
207239
"//executorch/runtime/kernel:kernel_includes",
@@ -218,7 +250,11 @@ def define_common_targets():
218250
exported_headers = [
219251
"padding_util.h",
220252
],
221-
compiler_flags = ["-Wno-missing-prototypes"],
253+
compiler_flags = select({
254+
"DEFAULT": ["-Wno-missing-prototypes"],
255+
# ovr_config//os:zephyr is fbsource-internal; OSS bypasses this select via runtime.is_oss.
256+
"ovr_config//os:zephyr": [],
257+
}) if not runtime.is_oss else ["-Wno-missing-prototypes"],
222258
deps = [
223259
"//executorch/runtime/kernel:kernel_includes",
224260
],
@@ -231,7 +267,11 @@ def define_common_targets():
231267
exported_headers = [
232268
"normalization_ops_util.h",
233269
],
234-
compiler_flags = ["-Wno-missing-prototypes"],
270+
compiler_flags = select({
271+
"DEFAULT": ["-Wno-missing-prototypes"],
272+
# ovr_config//os:zephyr is fbsource-internal; OSS bypasses this select via runtime.is_oss.
273+
"ovr_config//os:zephyr": [],
274+
}) if not runtime.is_oss else ["-Wno-missing-prototypes"],
235275
deps = [
236276
"//executorch/runtime/kernel:kernel_includes",
237277
],

shim_et/xplat/executorch/codegen/codegen.bzl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,14 @@ def build_portable_lib(
632632
# Currently fbcode links all dependent libraries through shared
633633
# library, and it blocks users like unit tests to use kernel
634634
# implementation directly. So we enable this for xplat only.
635-
compiler_flags = ["-Wno-missing-prototypes"]
635+
# -Wno-missing-prototypes is Clang-only for C++; GCC (used by Zephyr ARM
636+
# cross-compilation) rejects it with -Werror, so exclude it for Zephyr.
637+
# OSS bypasses the select since ovr_config//os:zephyr is not in the OSS
638+
# buck2 prelude.
639+
compiler_flags = select({
640+
"DEFAULT": ["-Wno-missing-prototypes"],
641+
"ovr_config//os:zephyr": [],
642+
}) if not runtime.is_oss else ["-Wno-missing-prototypes"]
636643
if not expose_operator_symbols and is_xplat():
637644
# Removing '-fvisibility=hidden' exposes operator symbols.
638645
# This allows operators to be called outside of the kernel registry.
@@ -678,7 +685,14 @@ def build_optimized_lib(name, oplist_header_name, portable_header_lib, feature =
678685
# Currently fbcode links all dependent libraries through shared
679686
# library, and it blocks users like unit tests to use kernel
680687
# implementation directly. So we enable this for xplat only.
681-
compiler_flags = ["-Wno-missing-prototypes", "-Wno-pass-failed", "-Wno-global-constructors", "-Wno-shadow"]
688+
# -Wno-missing-prototypes and -Wno-global-constructors are Clang-only for
689+
# C++; GCC (used by Zephyr ARM cross-compilation) rejects them with
690+
# -Werror, so exclude them for Zephyr. OSS bypasses the select since
691+
# ovr_config//os:zephyr is not in the OSS buck2 prelude.
692+
compiler_flags = select({
693+
"DEFAULT": ["-Wno-missing-prototypes", "-Wno-pass-failed", "-Wno-global-constructors", "-Wno-shadow"],
694+
"ovr_config//os:zephyr": ["-Wno-pass-failed", "-Wno-shadow"],
695+
}) if not runtime.is_oss else ["-Wno-missing-prototypes", "-Wno-pass-failed", "-Wno-global-constructors", "-Wno-shadow"]
682696
if not expose_operator_symbols and is_xplat():
683697
# Removing '-fvisibility=hidden' exposes operator symbols.
684698
# This allows operators to be called outside of the kernel registry.

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,26 @@ 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 is Clang-only for C++; GCC (used by
100+
# Zephyr ARM cross-compilation) rejects it with -Werror, so
101+
# exclude it for Zephyr. OSS bypasses the select since
102+
# ovr_config//os:zephyr is not in the OSS buck2 prelude.
103+
"DEFAULT": [
104+
"-Wno-missing-prototypes",
105+
# pragma unroll fails with -Os, don't need to warn us and
106+
# fail Werror builds; see https://godbolt.org/z/zvf85vTsr
107+
"-Wno-pass-failed",
108+
],
109+
"ovr_config//os:zephyr": [
110+
"-Wno-pass-failed",
111+
],
112+
}) if not runtime.is_oss else [
99113
"-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
102114
"-Wno-pass-failed",
103-
] + compiler_flags + get_compiler_optimization_flags(),
115+
]) + compiler_flags + get_compiler_optimization_flags(),
104116
# sleef needs to be added as a direct dependency of the operator target when building for Android,
105117
# or a linker error may occur. Not sure why this happens; it seems that fbandroid_platform_deps of
106118
# dependencies are not transitive

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,19 @@ 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-
compiler_flags = select({
122+
# -Wno-missing-prototypes is Clang-only for C++; GCC (used by Zephyr
123+
# ARM cross-compilation) rejects it with -Werror, so exclude it for
124+
# Zephyr and Windows builds. OSS bypasses the zephyr branch via
125+
# runtime.is_oss since ovr_config//os:zephyr is not in the OSS
126+
# buck2 prelude.
127+
compiler_flags = (select({
123128
"DEFAULT": ["-Wno-missing-prototypes"],
124129
"ovr_config//os:windows": [],
125-
}) + (
130+
"ovr_config//os:zephyr": [],
131+
}) if not runtime.is_oss else select({
132+
"DEFAULT": ["-Wno-missing-prototypes"],
133+
"ovr_config//os:windows": [],
134+
})) + (
126135
# For shared library build, we don't want to expose symbols of
127136
# kernel implementation (ex torch::executor::native::tanh_out)
128137
# to library users. They should use kernels through registry only.

0 commit comments

Comments
 (0)