Skip to content

Commit 16f3564

Browse files
committed
feat: reduce size of binaries
1 parent 7d0768f commit 16f3564

File tree

1 file changed

+37
-20
lines changed

1 file changed

+37
-20
lines changed

build_ext.py

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,44 @@
55
from distutils.command.build_ext import build_ext
66
from typing import Any
77

8+
try:
9+
from setuptools import Extension
10+
except ImportError:
11+
from distutils.core import Extension
12+
813
_LOGGER = logging.getLogger(__name__)
914

15+
TO_CYTHONIZE = [
16+
"src/zeroconf/_dns.py",
17+
"src/zeroconf/_cache.py",
18+
"src/zeroconf/_history.py",
19+
"src/zeroconf/_record_update.py",
20+
"src/zeroconf/_listener.py",
21+
"src/zeroconf/_protocol/incoming.py",
22+
"src/zeroconf/_protocol/outgoing.py",
23+
"src/zeroconf/_handlers/answers.py",
24+
"src/zeroconf/_handlers/record_manager.py",
25+
"src/zeroconf/_handlers/multicast_outgoing_queue.py",
26+
"src/zeroconf/_handlers/query_handler.py",
27+
"src/zeroconf/_services/__init__.py",
28+
"src/zeroconf/_services/browser.py",
29+
"src/zeroconf/_services/info.py",
30+
"src/zeroconf/_services/registry.py",
31+
"src/zeroconf/_updates.py",
32+
"src/zeroconf/_utils/ipaddress.py",
33+
"src/zeroconf/_utils/time.py",
34+
]
35+
36+
EXTENSIONS = [
37+
Extension(
38+
ext.removeprefix("src/").removesuffix(".py").replace("/", "."),
39+
[ext],
40+
language="c",
41+
extra_compile_args=["-O3", "-g0"],
42+
)
43+
for ext in TO_CYTHONIZE
44+
]
45+
1046

1147
class BuildExt(build_ext):
1248
def build_extensions(self) -> None:
@@ -25,26 +61,7 @@ def build(setup_kwargs: Any) -> None:
2561
setup_kwargs.update(
2662
{
2763
"ext_modules": cythonize(
28-
[
29-
"src/zeroconf/_dns.py",
30-
"src/zeroconf/_cache.py",
31-
"src/zeroconf/_history.py",
32-
"src/zeroconf/_record_update.py",
33-
"src/zeroconf/_listener.py",
34-
"src/zeroconf/_protocol/incoming.py",
35-
"src/zeroconf/_protocol/outgoing.py",
36-
"src/zeroconf/_handlers/answers.py",
37-
"src/zeroconf/_handlers/record_manager.py",
38-
"src/zeroconf/_handlers/multicast_outgoing_queue.py",
39-
"src/zeroconf/_handlers/query_handler.py",
40-
"src/zeroconf/_services/__init__.py",
41-
"src/zeroconf/_services/browser.py",
42-
"src/zeroconf/_services/info.py",
43-
"src/zeroconf/_services/registry.py",
44-
"src/zeroconf/_updates.py",
45-
"src/zeroconf/_utils/ipaddress.py",
46-
"src/zeroconf/_utils/time.py",
47-
],
64+
EXTENSIONS,
4865
compiler_directives={"language_level": "3"}, # Python 3
4966
),
5067
"cmdclass": {"build_ext": BuildExt},

0 commit comments

Comments
 (0)