|
11 | 11 |
|
12 | 12 | import glob |
13 | 13 | import os |
| 14 | +import platform |
14 | 15 | import sys |
15 | 16 |
|
16 | 17 | import pkgconfig |
17 | | -from pybind11.setup_helpers import ParallelCompile, Pybind11Extension, build_ext, naive_recompile |
| 18 | +from pybind11.setup_helpers import ( |
| 19 | + ParallelCompile, |
| 20 | + Pybind11Extension, |
| 21 | + build_ext, |
| 22 | + has_flag, |
| 23 | + naive_recompile, |
| 24 | +) |
18 | 25 | from setuptools import setup |
19 | 26 |
|
20 | 27 | ParallelCompile("NPY_NUM_BUILD_JOBS", needs_recompile=naive_recompile).install() |
|
41 | 48 | print("Library directories args are:") |
42 | 49 | print(libsemigroups_info["library_dirs"]) |
43 | 50 |
|
| 51 | + |
| 52 | +def get_arch(): |
| 53 | + """Simple function to return the architecture, namely, x86 or not""" |
| 54 | + arch = platform.machine().lower() |
| 55 | + if arch in {"x86_64", "amd64", "i386", "i686"}: |
| 56 | + return "x86" |
| 57 | + if arch in {"arm64", "aarch64", "armv7l", "armv6l"}: |
| 58 | + return "arm" |
| 59 | + return arch |
| 60 | + |
| 61 | + |
| 62 | +class LibsemigroupsBuildExt(build_ext): |
| 63 | + # pylint: disable=too-few-public-methods |
| 64 | + """Class conditionally add compile flags""" |
| 65 | + |
| 66 | + def build_extensions(self): |
| 67 | + """Adds compile flags before calling build_extensions in build_ext""" |
| 68 | + compiler = self.compiler |
| 69 | + |
| 70 | + if has_flag(compiler, "-mavx"): |
| 71 | + print("Compiler supports '-mavx' flag, adding it to 'extra_compile_args'") |
| 72 | + for ext in self.extensions: |
| 73 | + ext.extra_compile_args += ["-mavx"] |
| 74 | + else: |
| 75 | + print("Compiler does not support '-mavx' flag, not adding it to 'extra_compile_args'") |
| 76 | + if get_arch() == "arm" and ( |
| 77 | + any(x.startswith("gcc") for x in compiler.compiler) |
| 78 | + or any(x.startswith("g++") for x in compiler.compiler_cxx) |
| 79 | + ): |
| 80 | + print( |
| 81 | + "Compiler is gcc, and architecture is arm, adding '-fpermissive' to " |
| 82 | + "'extra_compile_args'" |
| 83 | + ) |
| 84 | + for ext in self.extensions: |
| 85 | + ext.extra_compile_args += ["-fpermissive"] |
| 86 | + |
| 87 | + for ext in self.extensions: |
| 88 | + print(f"'extra_compile_args' for '{ext.name}' are:") |
| 89 | + print(ext.extra_compile_args) |
| 90 | + |
| 91 | + super().build_extensions() |
| 92 | + |
| 93 | + |
44 | 94 | ext_modules = [ |
45 | 95 | Pybind11Extension( |
46 | 96 | "_libsemigroups_pybind11", |
|
49 | 99 | library_dirs=libsemigroups_info["library_dirs"], |
50 | 100 | language="c++", |
51 | 101 | libraries=["semigroups"], |
52 | | - extra_compile_args=["-fpermissive", "-flax-vector-conversions"], |
| 102 | + extra_compile_args=["-flax-vector-conversions"], |
53 | 103 | ) |
54 | 104 | ] |
55 | 105 |
|
56 | | -setup(ext_modules=ext_modules, cmdclass={"build_ext": build_ext}) |
| 106 | +setup(ext_modules=ext_modules, cmdclass={"build_ext": LibsemigroupsBuildExt}) |
0 commit comments