|
25 | 25 | "pythonsupport.c", |
26 | 26 | ] |
27 | 27 |
|
| 28 | +EXTRA_FLAGS_PER_COMPILER_TYPE_PER_PATH_COMPONENT = { |
| 29 | + "unix": { |
| 30 | + "base64/arch/ssse3": "-mssse3", |
| 31 | + "base64/arch/sse41": "-msse4.1", |
| 32 | + "base64/arch/sse42": "-msse4.2", |
| 33 | + "base64/arch/avx2": "-mavx2", |
| 34 | + "base64/arch/avx": "-mavx", |
| 35 | + }, |
| 36 | + "msvc": { |
| 37 | + "base64/arch/sse42": "/arch:SSE4.2", |
| 38 | + "base64/arch/avx2": "/arch:AVX2", |
| 39 | + "base64/arch/avx": "/arch: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 | + # Borland accepts a source file name at the end, |
| 63 | + # insert the options before it |
| 64 | + new_cmd[-1:-1] = extra_options[path] |
| 65 | + else: |
| 66 | + new_cmd.append(extra_options[path]) |
| 67 | + |
| 68 | + # path component is found, no need to search any further |
| 69 | + break |
| 70 | + self.__spawn(new_cmd, **kwargs) |
| 71 | + |
| 72 | + |
| 73 | +ccompiler.CCompiler.spawn = spawn # type: ignore[method-assign] |
| 74 | + |
| 75 | + |
31 | 76 | class BuildExtGtest(build_ext): |
32 | 77 | def get_library_names(self) -> list[str]: |
33 | 78 | return ["gtest"] |
@@ -80,14 +125,10 @@ def run(self) -> None: |
80 | 125 | compiler = ccompiler.new_compiler() |
81 | 126 | sysconfig.customize_compiler(compiler) |
82 | 127 | cflags: list[str] = [] |
83 | | - if compiler.compiler_type == "unix": |
| 128 | + if compiler.compiler_type == "unix": # type: ignore[attr-defined] |
84 | 129 | cflags += ["-O3"] |
85 | | - if X86_64: |
86 | | - cflags.append("-msse4.2") # Enable SIMD (see also mypyc/build.py) |
87 | | - elif compiler.compiler_type == "msvc": |
| 130 | + elif compiler.compiler_type == "msvc": # type: ignore[attr-defined] |
88 | 131 | cflags += ["/O2"] |
89 | | - if X86_64: |
90 | | - cflags.append("/arch:SSE4.2") # Enable SIMD (see also mypyc/build.py) |
91 | 132 |
|
92 | 133 | setup( |
93 | 134 | ext_modules=[ |
|
0 commit comments