Skip to content

Reduce size of packaged PyPI wheels#2823

Open
j2kun wants to merge 1 commit intogoogle:mainfrom
j2kun:pypi-build-size
Open

Reduce size of packaged PyPI wheels#2823
j2kun wants to merge 1 commit intogoogle:mainfrom
j2kun:pypi-build-size

Conversation

@j2kun
Copy link
Copy Markdown
Collaborator

@j2kun j2kun commented Mar 26, 2026

  • Strip all symbols from executable targets, which cuts their size by ~35%
  • Dedupe the binaries from data_files by providing a python entrypoint.

Fixes #2822

I was able to test the python entrypoints locally with pip install /path/to/heir (though it needs to happen outside of HEIR's project workspace or else the heir-opt and heir-translate binaries will be in HEIR's root). I was also able to confirm manually that the stripped binaries are stripped, though I configured the aggressive stripping to only occur in cibuildwheel.

@j2kun j2kun requested a review from AlexanderViand March 26, 2026 23:33
@AlexanderViand
Copy link
Copy Markdown
Collaborator

Ohh, nice! Building the macOS wheel locally real quick to check it out :)

Copy link
Copy Markdown
Collaborator

@AlexanderViand AlexanderViand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be safer to not do the stripping for macOS?

At least, my local macos isn't very happy about it:

ERROR: /Users/a.viand/Code/heir/tools/BUILD:14:10: Stripping tools/heir-opt.stripped for @@//tools:heir-opt failed: (Exit 1): strip failed: error executing CcStrip command (from target //tools:heir-opt) /usr/bin/strip -S -o bazel-out/darwin_arm64-opt/bin/tools/heir-opt.stripped --strip-all bazel-out/darwin_arm64-opt/bin/tools/heir-opt

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip: unrecognized option: --strip-all
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip [-AnuSXx] [-] [-d filename] [-s filename] [-R filename] [-o output] file [...] 
ERROR: Build did NOT complete successfully
error: command '/opt/homebrew/bin/bazel' failed with exit code 1

ERROR Backend subprocess exited when trying to invoke build_wheel

                                                            ✕ 748.31s
cibuildwheel: error: Command ['/private/var/folders/5l/3dm70vvs6kz5s_bt9h67zlvm0000gp/T/cibw-run-aaxc9bbn/cp312-macosx_arm64/build/venv/bin/python', '-m', 'build', '/Users/a.viand/Code/heir', '--wheel', '--outdir=/private/var/folders/5l/3dm70vvs6kz5s_bt9h67zlvm0000gp/T/cibw-run-aaxc9bbn/cp312-macosx_arm64/built_wheel', '--installer=uv'] failed with code 1. 

(heir) a.viand@MacBook-Air-A heir % 

EDIT: linux x86_64 build is still running on an aws instance

@AlexanderViand
Copy link
Copy Markdown
Collaborator

AlexanderViand commented Mar 27, 2026

linux x86_64 built fine and the package is now only 36.5MB (compressed), amazing!!!
(uncompressed, heir-opt is 63.3MB, heir-translate 12MB)

- Strip all symbols from executable targets, which cuts their size by
  ~35%
- Dedupe the binaries from data_files by providing a python entrypoint.
@j2kun j2kun force-pushed the pypi-build-size branch from 6564c81 to d9e72d0 Compare March 27, 2026 01:00
@j2kun
Copy link
Copy Markdown
Collaborator Author

j2kun commented Mar 27, 2026

Oh good call. I knew I had to filter for linux but I forgot. I added the corresponding macos strip flag now instead

@j2kun j2kun added ci:wheels and removed ci:wheels labels Mar 27, 2026
@j2kun j2kun requested review from AlexanderViand and asraa March 27, 2026 01:01
@AlexanderViand
Copy link
Copy Markdown
Collaborator

Works great on macOS now!
heir_py-2026.2.2.dev222+gd9e72d0aa.d20260327-cp311-abi3-macosx_11_0_arm64.whl 39.3 MB

@asraa asraa added the pull_ready Indicates whether a PR is ready to pull. The copybara worker will import for internal testing label Mar 27, 2026
Copy link
Copy Markdown
Collaborator

@AlexanderViand AlexanderViand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked on macOS! Still running on x86_64 but since that worked before, I guess good to merge?
EDIT: linux x86_64 also succeeded!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:wheels pull_ready Indicates whether a PR is ready to pull. The copybara worker will import for internal testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PyPI packages are too large

3 participants