Skip to content

Commit 68e6a09

Browse files
committed
[build] Repack wheel with LZMA compression
Add a post-build step to recompress the wheel using LZMA (ZIP_LZMA), which reduces size by ~35% compared to the default DEFLATE. This brings the wheel under the 2 GiB GitHub release limit.
1 parent b6ba3fa commit 68e6a09

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

.github/workflows/build_wheels_windows.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,30 @@ jobs:
177177
python setup.py $SKIP_CMAKE bdist_wheel --py-limited-api=cp37 --dist-dir="$PWD\wheelhouse" -v
178178
shell: pwsh
179179

180+
- name: Repack wheel with LZMA compression
181+
run: |
182+
python -c "
183+
import zipfile, os
184+
method = zipfile.ZIP_LZMA
185+
whl_dir = 'wheelhouse'
186+
for name in os.listdir(whl_dir):
187+
if not name.endswith('.whl'):
188+
continue
189+
src = os.path.join(whl_dir, name)
190+
dst = src + '.tmp'
191+
src_size = os.path.getsize(src)
192+
print(f'Repacking {name} ({src_size / 1e9:.2f} GB)...')
193+
with zipfile.ZipFile(src, 'r') as zin, zipfile.ZipFile(dst, 'w', method) as zout:
194+
for item in zin.infolist():
195+
item.compress_type = method
196+
zout.writestr(item, zin.read(item.filename))
197+
dst_size = os.path.getsize(dst)
198+
saved = src_size - dst_size
199+
print(f'Done: {dst_size / 1e9:.2f} GB (saved {saved / 1e6:.1f} MB, {100*saved/src_size:.1f}%)')
200+
os.replace(dst, src)
201+
"
202+
shell: bash
203+
180204
- name: Save build artifacts to cache
181205
uses: actions/cache/save@v3
182206
if: ${{ inputs.save_build_cache && !inputs.rolling_build }}

0 commit comments

Comments
 (0)