From ccb555d367ad711bb0256b9fdcfd8b5c78aab6e7 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. --- make_cffi.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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", ]