Skip to content

Commit 340fd55

Browse files
committed
Raise the ATen-mode C++ standard where both builds see it
The C++20 flag for ATen-mode targets was set in the interface layer that exists only for the open source build, whose own docstring says as much. So the internal build never got it, and the shared wrapper was passing that layer an argument its internal counterpart does not accept, which would fail there rather than being merely ineffective. Move the decision into the shared wrapper, which both builds go through, and leave the interface layer exactly as it was. The flag goes on the target's own compile flags, because the build config applies C++17 to everything and only a flag on the target overrides it. Test Plan: Read the two files' own descriptions of themselves to place this: the interface layer is for changes specific to one build, the wrapper is for logic shared with the internal one. Confirmed the internal counterpart takes only the arguments it always took, so the previous version would have broken it rather than skipped it. Ran the new helper over the target from the failure and over targets that must not move. The generated kernel library and the ATen bridge come away with C++20; a plain library and the portable kernels come away with no flag added, so they keep the C++17 the build config gives them, which is what the embedded builds rely on. I cannot run either Buck build here, so CI has to confirm the generated libraries compile.
1 parent 2017627 commit 340fd55

2 files changed

Lines changed: 20 additions & 21 deletions

File tree

‎shim_et/xplat/executorch/build/env_interface.bzl‎

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -160,28 +160,14 @@ def _patch_headers(kwargs):
160160
def _patch_pp_flags(kwargs):
161161
return kwargs
162162

163-
def _patch_cxx_compiler_flags(kwargs, aten_mode = False):
164-
"""Pins the C++ standard a target compiles with.
165-
166-
C++17 by default, which is what the runtime this project ships requires.
167-
ATen-mode targets are raised to C++20, because PyTorch's headers require it as
168-
of 2.14: c10/util/intrusive_ptr.h defines operator<=> and returns
169-
std::strong_ordering with no feature guard.
170-
"""
171-
std = "-std=c++20" if aten_mode else "-std=c++17"
163+
def _patch_cxx_compiler_flags(kwargs):
164+
"""CXX Compiler flags to enable C++17 features."""
172165
if "lang_compiler_flags" not in kwargs:
173-
kwargs["lang_compiler_flags"] = {"cxx_cpp_output": [std]}
166+
kwargs["lang_compiler_flags"] = {"cxx_cpp_output": ["-std=c++17"]}
174167
elif "cxx_cpp_output" not in kwargs["lang_compiler_flags"]:
175-
kwargs["lang_compiler_flags"]["cxx_cpp_output"] = [std]
168+
kwargs["lang_compiler_flags"]["cxx_cpp_output"] = ["-std=c++17"]
176169
else:
177-
kwargs["lang_compiler_flags"]["cxx_cpp_output"].append(std)
178-
179-
# Also put it on the target's own flags. The build config sets C++17 for
180-
# everything, and for an ATen-mode target that has to be overridden on the
181-
# compile itself, not only on the preprocessor pass above, or generated
182-
# sources still see C++17 and fail on ATen's concepts.
183-
if aten_mode:
184-
kwargs["compiler_flags"] = kwargs.get("compiler_flags", []) + [std]
170+
kwargs["lang_compiler_flags"]["cxx_cpp_output"].append("-std=c++17")
185171
return kwargs
186172

187173
# buildifier: disable=unused-variable

‎shim_et/xplat/executorch/build/runtime_wrapper.bzl‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,26 @@ def _patch_kwargs_cxx(kwargs):
278278
env.remove_platform_specific_args(kwargs)
279279
return _patch_kwargs_common(kwargs)
280280

281+
def _patch_aten_mode_std(kwargs):
282+
"""Raises an ATen-mode target to C++20, which PyTorch's headers require.
283+
284+
Set here rather than in the OSS-only interface layer, so the internal build
285+
gets it too, and as a plain compiler flag so it overrides the C++17 the build
286+
config applies to everything.
287+
"""
288+
if _is_aten_target(kwargs):
289+
kwargs["compiler_flags"] = kwargs.get("compiler_flags", []) + ["-std=c++20"]
290+
return kwargs
291+
281292
def _cxx_library_common(*args, **kwargs):
282293
_patch_kwargs_cxx(kwargs)
283294
_patch_build_mode_flags(kwargs)
295+
_patch_aten_mode_std(kwargs)
284296

285297
env.patch_platform_build_mode_flags(kwargs)
286298
env.patch_headers(kwargs)
287299
env.patch_pp_flags(kwargs)
288-
env.patch_cxx_compiler_flags(kwargs, aten_mode = _is_aten_target(kwargs))
300+
env.patch_cxx_compiler_flags(kwargs)
289301
env.patch_force_static(kwargs)
290302

291303
env.cxx_library(*args, **kwargs)
@@ -307,8 +319,9 @@ def _cxx_library(*args, **kwargs):
307319
def _cxx_binary_helper(*args, **kwargs):
308320
_patch_kwargs_cxx(kwargs)
309321
_patch_build_mode_flags(kwargs)
322+
_patch_aten_mode_std(kwargs)
310323
env.patch_platform_build_mode_flags(kwargs)
311-
env.patch_cxx_compiler_flags(kwargs, aten_mode = _is_aten_target(kwargs))
324+
env.patch_cxx_compiler_flags(kwargs)
312325

313326
env.cxx_binary(*args, **kwargs)
314327

0 commit comments

Comments
 (0)