From 7f58c266ed36abd7d11aec633982cbade38ebd86 Mon Sep 17 00:00:00 2001 From: Jacob Szwejbka Date: Fri, 27 Feb 2026 13:53:14 -0800 Subject: [PATCH] remove c++ std version for aten tests (#17747) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/17747 Previous diff didnt go far enough. Try #2 Reviewed By: r-barnes Differential Revision: D94554543 --- .../executorch/build/runtime_wrapper.bzl | 37 +++++++++++++++++-- third-party/gtest_defs.bzl | 3 +- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/shim_et/xplat/executorch/build/runtime_wrapper.bzl b/shim_et/xplat/executorch/build/runtime_wrapper.bzl index e38adf31416..92fafc78bab 100644 --- a/shim_et/xplat/executorch/build/runtime_wrapper.bzl +++ b/shim_et/xplat/executorch/build/runtime_wrapper.bzl @@ -125,14 +125,43 @@ def _patch_build_mode_flags(kwargs): return kwargs +def _has_pytorch_dep(dep_list): + """Check if a dependency list contains PyTorch/ATen dependencies.""" + if not dep_list: + return False + for dep in dep_list: + if type(dep) == "string": + if "torch" in dep or "libtorch" in dep or "caffe2" in dep: + return True + return False + def _patch_test_compiler_flags(kwargs): if "compiler_flags" not in kwargs: kwargs["compiler_flags"] = [] - # Required globally by all c++ tests. - kwargs["compiler_flags"] += [ - "-std=c++17", - ] + # Determine C++ standard based on whether this is an aten test. + # Aten tests require at least C++20 to compile against PyTorch, while + # non-aten tests are pinned to C++17 for embedded. + name = kwargs.get("name", "") + external_deps = kwargs.get("external_deps", []) + deps = kwargs.get("deps", []) + xplat_deps = kwargs.get("xplat_deps", []) + fbcode_deps = kwargs.get("fbcode_deps", []) + is_aten_test = ( + "_aten" in name or + "aten_" in name or + "libtorch" in external_deps or + "gtest_aten" in external_deps or + "gmock_aten" in external_deps or + _has_pytorch_dep(deps) or + _has_pytorch_dep(xplat_deps) or + _has_pytorch_dep(fbcode_deps) + ) + + if not is_aten_test: + kwargs["compiler_flags"] += [ + "-std=c++17", + ] # Relaxing some constraints for tests kwargs["compiler_flags"] += [ diff --git a/third-party/gtest_defs.bzl b/third-party/gtest_defs.bzl index ac8046e264d..1626c3836d8 100644 --- a/third-party/gtest_defs.bzl +++ b/third-party/gtest_defs.bzl @@ -4,8 +4,7 @@ load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "get_aten_mode_opt COMPILER_FLAGS = [ "-std=c++17", ] -COMPILER_FLAGS_ATEN = [ - "-std=c++17",] +COMPILER_FLAGS_ATEN = [] # define_gtest_targets def define_gtest_targets():