Skip to content
Snippets Groups Projects
Commit 49e21e2a authored by Martin Larralde's avatar Martin Larralde
Browse files

Fix compilation error with `clang` on some older OSX versions

parent 62cb5c9f
No related branches found
No related tags found
No related merge requests found
......@@ -76,9 +76,7 @@ jobs:
run: python -m pip install --no-index --find-links=dist pyfastani
- name: Install numpy
run: python -m pip install numpy
if: ${{ !startsWith(matrix.python-version != 'pypy' }}
- name: Install tests requirements
run: python -m pip install -r pyfastani/tests/requirements.txt
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
- name: Run tests without coverage
run: python -m unittest pyfastani.tests -vv
......@@ -144,9 +142,7 @@ jobs:
run: python -m pip install --no-index --find-links=dist pyfastani
- name: Install numpy
run: python -m pip install numpy
if: ${{ !startsWith(matrix.python-version != 'pypy' }}
- name: Install tests requirements
run: python -m pip install -r pyfastani/tests/requirements.txt
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
- name: Run tests without coverage
run: python -m unittest pyfastani.tests -vv
......
......@@ -66,7 +66,7 @@ jobs:
run: python setup.py build_ext --inplace --debug
- name: Install numpy
run: python -m pip install numpy
if: ${{ !startsWith(matrix.python-version != 'pypy' }}
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
- name: Install tests requirements
run: python -m pip install -r pyfastani/tests/requirements.txt
- name: Test with coverage
......@@ -138,7 +138,7 @@ jobs:
- name: Build C extension
run: python setup.py build_ext --inplace --debug
- name: Install numpy
if: ${{ matrix.python-impl != 'PyPy' }}
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
run: python -m pip install numpy
- name: Install tests requirements
run: python -m pip install -r pyfastani/tests/requirements.txt
......
......@@ -52,6 +52,7 @@ setup_requires =
[options.package_data]
pyfastani = py.typed, *.pyi
pyfastani.tests = requirements.txt
[publicize_headers]
sources = vendor/FastANI/src
......
......@@ -112,6 +112,30 @@ class build_ext(_build_ext):
"""A `build_ext` that disables optimizations if compiled in debug mode.
"""
# --- Autotools-like helpers ---
def _silent_spawn(self, cmd):
try:
subprocess.run(cmd, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
except subprocess.CalledProcessError as err:
raise CompileError(err.stderr)
def _needs_clang_flags(self):
self.mkpath(self.build_temp)
testfile = os.path.join(self.build_temp, "testc++11.cpp")
with open(testfile, "w") as f:
f.write('#include <chrono>\n')
try:
with mock.patch.object(self.compiler, "spawn", new=self._silent_spawn):
objects = self.compiler.compile([testfile], debug=self.debug)
except CompileError as err:
log.warn('failed to include <chrono>, assuming we need clang flags')
return True
else:
log.info('successfully built a C++11 program with default flags')
return False
def finalize_options(self):
_build_ext.finalize_options(self)
self._clib_cmd = self.get_finalized_command("build_clib")
......@@ -179,6 +203,11 @@ class build_ext(_build_ext):
ext.extra_compile_args.append("-std=c++11")
ext.extra_link_args.append("-std=c++11")
# in case we are compiling with clang, make sure to use libstdc++
if self.compiler.compiler_type == "unix" and sys.platform == "darwin":
ext.extra_compile_args.append("-stdlib=libc++")
ext.extra_link_args.append("-stdlib=libc++")
# build the rest of the extension as normal
_build_ext.build_extension(self, ext)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment