|
25 | 25 | "pythonsupport.c", |
26 | 26 | ] |
27 | 27 |
|
| 28 | +EXTRA_FLAGS_PER_COMPILER_TYPE_PER_PATH_COMPONENT = { |
| 29 | + "unix": { |
| 30 | + "base64/arch/ssse3": ["-mssse3", "-DBASE64_WITH_SSSE3"], |
| 31 | + "base64/arch/sse41": ["-msse4.1", "-DBASE64_WITH_SSE41"], |
| 32 | + "base64/arch/sse42": ["-msse4.2", "-DBASE64_WITH_SSE42"], |
| 33 | + "base64/arch/avx2": ["-mavx2", "-DBASE64_WITH_AVX2"], |
| 34 | + "base64/arch/avx": ["-mavx", "-DBASE64_WITH_AVX"], |
| 35 | + }, |
| 36 | + "msvc": { |
| 37 | + "base64/arch/sse42": ["/arch:SSE4.2", "/DBASE64_WITH_SSE42"], |
| 38 | + "base64/arch/avx2": ["/arch:AVX2", "/DBASE64_WITH_AVX2"], |
| 39 | + "base64/arch/avx": ["/arch:AVX", "/DBASE64_WITH_AVX"], |
| 40 | + }, |
| 41 | +} |
| 42 | + |
| 43 | +ccompiler.CCompiler.__spawn = ccompiler.CCompiler.spawn # type: ignore[attr-defined] |
28 | 44 | X86_64 = platform.machine() in ("x86_64", "AMD64", "amd64") |
29 | 45 |
|
30 | 46 |
|
| 47 | +def spawn(self, cmd, **kwargs) -> None: # type: ignore[no-untyped-def] |
| 48 | + compiler_type: str = self.compiler_type |
| 49 | + extra_options = EXTRA_FLAGS_PER_COMPILER_TYPE_PER_PATH_COMPONENT[compiler_type] |
| 50 | + new_cmd = list(cmd) |
| 51 | + if X86_64 and extra_options is not None: |
| 52 | + # filenames are closer to the end of command line |
| 53 | + for argument in reversed(new_cmd): |
| 54 | + # Check if argument contains a filename. We must check for all |
| 55 | + # possible extensions; checking for target extension is faster. |
| 56 | + if self.obj_extension and not str(argument).endswith(self.obj_extension): |
| 57 | + continue |
| 58 | + |
| 59 | + for path in extra_options.keys(): |
| 60 | + if path in str(argument): |
| 61 | + if compiler_type == "bcpp": |
| 62 | + compiler = new_cmd.pop() |
| 63 | + # Borland accepts a source file name at the end, |
| 64 | + # insert the options before it |
| 65 | + new_cmd.extend(extra_options[path]) |
| 66 | + new_cmd.append(compiler) |
| 67 | + else: |
| 68 | + new_cmd.extend(extra_options[path]) |
| 69 | + |
| 70 | + # path component is found, no need to search any further |
| 71 | + break |
| 72 | + self.__spawn(new_cmd, **kwargs) |
| 73 | + |
| 74 | + |
| 75 | +ccompiler.CCompiler.spawn = spawn # type: ignore[method-assign] |
| 76 | + |
| 77 | + |
31 | 78 | class BuildExtGtest(build_ext): |
32 | 79 | def get_library_names(self) -> list[str]: |
33 | 80 | return ["gtest"] |
@@ -80,14 +127,10 @@ def run(self) -> None: |
80 | 127 | compiler = ccompiler.new_compiler() |
81 | 128 | sysconfig.customize_compiler(compiler) |
82 | 129 | cflags: list[str] = [] |
83 | | - if compiler.compiler_type == "unix": |
| 130 | + if compiler.compiler_type == "unix": # type: ignore[attr-defined] |
84 | 131 | cflags += ["-O3"] |
85 | | - if X86_64: |
86 | | - cflags.append("-msse4.2") # Enable SIMD (see also mypyc/build.py) |
87 | | - elif compiler.compiler_type == "msvc": |
| 132 | + elif compiler.compiler_type == "msvc": # type: ignore[attr-defined] |
88 | 133 | cflags += ["/O2"] |
89 | | - if X86_64: |
90 | | - cflags.append("/arch:SSE4.2") # Enable SIMD (see also mypyc/build.py) |
91 | 134 |
|
92 | 135 | setup( |
93 | 136 | ext_modules=[ |
|
0 commit comments