|
6 | 6 | from __future__ import annotations |
7 | 7 |
|
8 | 8 | import os |
9 | | -import platform |
10 | 9 | import subprocess |
11 | 10 | import sys |
12 | 11 | from distutils import ccompiler, sysconfig |
13 | 12 | from typing import Any |
14 | 13 |
|
| 14 | +import build_setup # noqa: F401 |
15 | 15 | from setuptools import Extension, setup |
16 | 16 | from setuptools.command.build_ext import build_ext |
17 | 17 |
|
|
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] |
44 | | -X86_64 = platform.machine() in ("x86_64", "AMD64", "amd64") |
45 | | -PYODIDE = "PYODIDE" in os.environ |
46 | | - |
47 | | - |
48 | | -def spawn(self, cmd, **kwargs) -> None: # type: ignore[no-untyped-def] |
49 | | - if PYODIDE: |
50 | | - new_cmd = list(cmd) |
51 | | - for argument in reversed(new_cmd): |
52 | | - if not str(argument).endswith(".c"): |
53 | | - continue |
54 | | - if "base64/arch/" in str(argument): |
55 | | - new_cmd.extend(["-msimd128"]) |
56 | | - else: |
57 | | - compiler_type: str = self.compiler_type |
58 | | - extra_options = EXTRA_FLAGS_PER_COMPILER_TYPE_PER_PATH_COMPONENT[compiler_type] |
59 | | - new_cmd = list(cmd) |
60 | | - if X86_64 and extra_options is not None: |
61 | | - # filenames are closer to the end of command line |
62 | | - for argument in reversed(new_cmd): |
63 | | - # Check if the matching argument contains a source filename. |
64 | | - if not str(argument).endswith(".c"): |
65 | | - continue |
66 | | - |
67 | | - for path in extra_options.keys(): |
68 | | - if path in str(argument): |
69 | | - if compiler_type == "bcpp": |
70 | | - compiler = new_cmd.pop() |
71 | | - # Borland accepts a source file name at the end, |
72 | | - # insert the options before it |
73 | | - new_cmd.extend(extra_options[path]) |
74 | | - new_cmd.append(compiler) |
75 | | - else: |
76 | | - new_cmd.extend(extra_options[path]) |
77 | | - |
78 | | - # path component is found, no need to search any further |
79 | | - break |
80 | | - self.__spawn(new_cmd, **kwargs) |
81 | | - |
82 | | - |
83 | | -ccompiler.CCompiler.spawn = spawn # type: ignore[method-assign] |
84 | | - |
85 | 28 |
|
86 | 29 | class BuildExtGtest(build_ext): |
87 | 30 | def get_library_names(self) -> list[str]: |
@@ -130,13 +73,11 @@ def run(self) -> None: |
130 | 73 | cmdclass={"build_ext": BuildExtGtest}, |
131 | 74 | ) |
132 | 75 | else: |
133 | | - # TODO: we need a way to share our preferred C flags and get_extension() logic with |
134 | | - # mypyc/build.py without code duplication. |
135 | 76 | compiler = ccompiler.new_compiler() |
136 | 77 | sysconfig.customize_compiler(compiler) |
137 | 78 | cflags: list[str] = [] |
138 | 79 | if compiler.compiler_type == "unix": # type: ignore[attr-defined] |
139 | | - cflags += ["-O3"] |
| 80 | + cflags += ["-O3", "-Wno-unused-function"] |
140 | 81 | elif compiler.compiler_type == "msvc": # type: ignore[attr-defined] |
141 | 82 | cflags += ["/O2"] |
142 | 83 |
|
|
0 commit comments