Skip to content

Commit e2e40c5

Browse files
linesightclaude
andcommitted
build: shrink the Linux wheel (strip libcef.so + compress) [cztomczak#262]
The rewritten build_distrib.py dropped two things that kept the Linux wheel reasonable: 1. libcef.so symbol stripping. CEF ships it with ~1.1 GB of debug symbols. Restore the pre-CMake reduce_package_size_issue262() step: strip libcef.so on Linux (keeps .dynsym for linking). 1342 -> 252 MB unpacked. 2. Wheel compression. zipfile.ZipInfo.from_file() defaults to ZIP_STORED, so package files were written uncompressed despite the ZIP_DEFLATED archive. Set compress_type = ZIP_DEFLATED so files are actually compressed (libcef.so 252 -> 102 MB in the wheel). Together the Linux wheel drops from ~356 MB to ~139 MB, comparable to Windows/macOS. Verified: fresh-venv install + 85/85 unit tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 13c3592 commit e2e40c5

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

tools/build_distrib.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
with a generated .dist-info
1919
(METADATA, WHEEL, top_level.txt,
2020
RECORD). No compilation happens here.
21+
On Linux, libcef.so is stripped of
22+
debug symbols first (Issue #262; it
23+
ships ~1.3 GB with them).
2124
6. (CI) install the wheel and run the unit tests against it.
2225
2326
Usage:
@@ -94,6 +97,8 @@ def main():
9497
" run compile step first".format(ext=ext, pkg_dir=pkg_dir))
9598
sys.exit(1)
9699

100+
_reduce_package_size_issue262(pkg_dir)
101+
97102
records = []
98103

99104
def _add_bytes(arcname, data):
@@ -118,6 +123,9 @@ def _add_bytes(arcname, data):
118123
hashlib.sha256(data).digest()).rstrip(b"=").decode()
119124
records.append((arcname, "sha256=" + digest, str(len(data))))
120125
info = zipfile.ZipInfo.from_file(filepath, arcname)
126+
# ZipInfo.from_file() defaults to ZIP_STORED; deflate so the
127+
# wheel is actually compressed (matches the ZipFile mode).
128+
info.compress_type = zipfile.ZIP_DEFLATED
121129
zf.writestr(info, data)
122130

123131
# dist-info/METADATA (all fields sourced from [project] in pyproject.toml
@@ -187,6 +195,28 @@ def _core_metadata(version, project):
187195
return ("\n".join(lines) + "\n").encode("utf-8")
188196

189197

198+
def _reduce_package_size_issue262(pkg_dir):
199+
"""Linux only: strip debug symbols from libcef.so (Issue #262).
200+
201+
CEF ships libcef.so with embedded debug symbols (~1.3 GB), which otherwise
202+
bloat the Linux wheel far beyond the other platforms. Ported from the
203+
pre-CMake build_distrib.py. `strip` keeps the dynamic symbols needed for
204+
linking and removes .symtab/.debug_*.
205+
"""
206+
if not sys.platform.startswith("linux"):
207+
return
208+
libcef_so = os.path.join(pkg_dir, "libcef.so")
209+
if not os.path.exists(libcef_so):
210+
return
211+
before = os.path.getsize(libcef_so)
212+
print("[build_distrib.py] Strip {0} (Issue #262)".format(
213+
os.path.basename(libcef_so)))
214+
code = subprocess.call(["strip", libcef_so])
215+
assert code == 0, "strip command failed"
216+
print("[build_distrib.py] libcef.so: {0:.0f} MB -> {1:.0f} MB".format(
217+
before / 1e6, os.path.getsize(libcef_so) / 1e6))
218+
219+
190220
def _dev_version(base):
191221
"""<base>.dev<commit-count>+g<short-hash> from git (PEP 440 dev version).
192222

0 commit comments

Comments
 (0)