Patchwork D12207: zstd: hack include order to ensure that our zstd.h is found

login
register
mail settings
Submitter phabricator
Date Feb. 21, 2022, 1:45 p.m.
Message ID <differential-rev-PHID-DREV-eyntjkpj3fwfm6urrri4-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50544/
State New
Headers show

Comments

phabricator - Feb. 21, 2022, 1:45 p.m.
joerg.sonnenberger created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  If the regular Python CFLAGS include directories that already have the
  zstd headers available, a different and possible incompatible version
  can be picked up otherwise. Sadly, it seems like Python has no easy way
  to prefix flags before the rest.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D12207

AFFECTED FILES
  contrib/python-zstandard/setup_zstd.py

CHANGE DETAILS




To: joerg.sonnenberger, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/contrib/python-zstandard/setup_zstd.py b/contrib/python-zstandard/setup_zstd.py
--- a/contrib/python-zstandard/setup_zstd.py
+++ b/contrib/python-zstandard/setup_zstd.py
@@ -145,9 +145,17 @@ 
 
     include_dirs = set([os.path.join(actual_root, d) for d in ext_includes])
     if not system_zstd:
-        include_dirs.update(
-            [os.path.join(actual_root, d) for d in zstd_includes]
-        )
+        from distutils import sysconfig
+        try:
+            from shlex import quote
+        except ImportError:
+            from pipes import quote
+        includes = []
+        for incdir in [os.path.join(actual_root, d) for d in zstd_includes]:
+           includes.append('-I' + quote(incdir))
+           include_dirs.add(incdir)
+        config_vars = sysconfig.get_config_vars()
+        config_vars['CFLAGS'] = ' '.join(includes + [config_vars.get('CFLAGS', '')])
         if support_legacy:
             include_dirs.update(
                 [os.path.join(actual_root, d) for d in zstd_includes_legacy]