From 5ca5ce8aaa89def52c4738e85f89aa3ad4150d4e Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Thu, 21 Jul 2022 15:22:20 -0600 Subject: [PATCH] cffi: Use the distutils preprocessor when available On Unix like systems, distutils will usually set the preprocessor attribute to the appropriate command. On MSVC it never sets the preprocessor, though. In either case, try to use it and only fallback to using the compiler if needed. Using compiler.compiler[0] breaks use of ccache when inserted in the CC environment variable. This is a regression from 0d1329ab426dde7dc319905da0656cd44db41988. Closes #178. Closes #179. --- docs/news.rst | 2 ++ make_cffi.py | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/news.rst b/docs/news.rst index a08f1686..f6e0e75d 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -89,6 +89,8 @@ Changes * Anaconda 3.6 support dropped. * Official support for Python 3.11. This did not require meaningful code changes and previous release(s) likely worked with 3.11 without any changes. +* CFFI's build system now respects distutils's ``compiler.preprocessor`` if it + is set. (#179) 0.18.0 (released 2022-06-20) ============================ diff --git a/make_cffi.py b/make_cffi.py index 3029e420..806398ff 100644 --- a/make_cffi.py +++ b/make_cffi.py @@ -40,23 +40,24 @@ # environment variables like CC. distutils.sysconfig.customize_compiler(compiler) -# Distutils doesn't set compiler.preprocessor, so invoke the preprocessor -# manually. +# Distutils doesn't always set compiler.preprocessor, so invoke the +# preprocessor manually when needed. +args = getattr(compiler, "preprocessor", None) if compiler.compiler_type == "unix": - # Using .compiler respects the CC environment variable. - args = [compiler.compiler[0]] + if not args: + # Using .compiler respects the CC environment variable. + args = [compiler.compiler[0], "-E"] args.extend( [ - "-E", "-DZSTD_STATIC_LINKING_ONLY", "-DZDICT_STATIC_LINKING_ONLY", ] ) elif compiler.compiler_type == "msvc": - args = [compiler.cc] + if not args: + args = [compiler.cc, "/EP"] args.extend( [ - "/EP", "/DZSTD_STATIC_LINKING_ONLY", "/DZDICT_STATIC_LINKING_ONLY", ]