Skip to content

Commit

Permalink
cffi: Use the distutils preprocessor when available
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dbnicholson authored and indygreg committed Oct 29, 2022
1 parent f80f8de commit 5ca5ce8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
============================
Expand Down
15 changes: 8 additions & 7 deletions make_cffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down

0 comments on commit 5ca5ce8

Please sign in to comment.