From 8403bab1fdb4c8aafbb1c78d9339f808e617afff Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Wed, 4 Dec 2024 13:33:54 -0500 Subject: [PATCH 1/2] Set C++ standard to 17 --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index ac40120..17f74e7 100644 --- a/setup.py +++ b/setup.py @@ -41,6 +41,7 @@ Pybind11Extension( name="micro_features_cpp", language="c++", + cxx_std=17, extra_compile_args=flags, sources=sorted([str(p) for p in sources] + [str(_DIR / "python.cpp")]), define_macros=[("VERSION_INFO", __version__)], From e1d3f88183e12bb8af2df9e399ea157af7393762 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Wed, 4 Dec 2024 14:32:27 -0500 Subject: [PATCH 2/2] Patch Clang invocations to avoid passing `-std=c++17` when compiling C --- setup.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 17f74e7..e77ed52 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,29 @@ +import sys from pathlib import Path # Available at setup time due to pyproject.toml -from pybind11.setup_helpers import Pybind11Extension, build_ext +from pybind11.setup_helpers import Pybind11Extension from setuptools import setup + +# Omit `-std=c++` flags if we're building C source files with Clang +if sys.platform == "darwin": + from distutils import unixccompiler + + class PatchedUnixCCompiler(unixccompiler.UnixCCompiler): + def _compile( + self, obj, src, ext, cc_args, extra_postargs, pp_opts, *args, **kwargs + ): + if self.compiler[0] == "clang" and ext == ".c": + extra_postargs = [a for a in extra_postargs if "-std=c++" not in a] + + return super()._compile( + obj, src, ext, cc_args, extra_postargs, pp_opts, *args, **kwargs + ) + + unixccompiler.UnixCCompiler = PatchedUnixCCompiler + + _DIR = Path(__file__).parent _FRONTEND_DIR = _DIR / "tensorflow" / "lite" / "experimental" / "microfrontend" / "lib" _KISSFFT_DIR = _DIR / "kissfft"