Skip to content

Commit 41f7139

Browse files
dbnicholsonindygreg
authored andcommitted
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 0d1329a. Closes #178. Closes #179.
1 parent a375b12 commit 41f7139

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

docs/news.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ Changes
8989
* Anaconda 3.6 support dropped.
9090
* Official support for Python 3.11. This did not require meaningful code changes
9191
and previous release(s) likely worked with 3.11 without any changes.
92+
* CFFI's build system now respects distutils's ``compiler.preprocessor`` if it
93+
is set. (#179)
9294

9395
0.18.0 (released 2022-06-20)
9496
============================

make_cffi.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,24 @@
4040
# environment variables like CC.
4141
distutils.sysconfig.customize_compiler(compiler)
4242

43-
# Distutils doesn't set compiler.preprocessor, so invoke the preprocessor
44-
# manually.
43+
# Distutils doesn't always set compiler.preprocessor, so invoke the
44+
# preprocessor manually when needed.
45+
args = getattr(compiler, "preprocessor", None)
4546
if compiler.compiler_type == "unix":
46-
# Using .compiler respects the CC environment variable.
47-
args = [compiler.compiler[0]]
47+
if not args:
48+
# Using .compiler respects the CC environment variable.
49+
args = [compiler.compiler[0], "-E"]
4850
args.extend(
4951
[
50-
"-E",
5152
"-DZSTD_STATIC_LINKING_ONLY",
5253
"-DZDICT_STATIC_LINKING_ONLY",
5354
]
5455
)
5556
elif compiler.compiler_type == "msvc":
56-
args = [compiler.cc]
57+
if not args:
58+
args = [compiler.cc, "/EP"]
5759
args.extend(
5860
[
59-
"/EP",
6061
"/DZSTD_STATIC_LINKING_ONLY",
6162
"/DZDICT_STATIC_LINKING_ONLY",
6263
]

0 commit comments

Comments
 (0)