Skip to content

Add make_py_package_standalone.py PEX builder#1315

Open
cormacrelf wants to merge 2 commits into
facebook:mainfrom
cormacrelf:make_py_package_standalone
Open

Add make_py_package_standalone.py PEX builder#1315
cormacrelf wants to merge 2 commits into
facebook:mainfrom
cormacrelf:make_py_package_standalone

Conversation

@cormacrelf
Copy link
Copy Markdown
Contributor

@cormacrelf cormacrelf commented May 7, 2026

There is a reference in the prelude to make_py_package_standalone being a PEX archive builder for bundling a python binary together. The one Meta uses has never been open sourced. This is a version for OSS users. Fixes #229

This is a claude oneshot except for the zip_safe = True (default) behaviour.

Features:

  • Pure execute from zip file behaviour for pure python
  • If you have .so files in there it requires zip_safe = False passed to python_binary so you are aware it will use the self-extracting behaviour
  • Self-extracting version extracts to ~/.cache/par/hello.pex-HASH with locking for multiple copies of the binary launched at the same time

To use:

buck2 build //my/python:binary[standalone]

# more complete example
cp $(buck2 build //my/python:binary[standalone] --show-full-simple-output) /tmp/binary.pex
/tmp/binary.pex

You can also use package_style = "standalone" on the target but I normally wouldn't as packaging a PEX is a quite intensive zip operation if you have a lot of dependencies with 100MB .so files etc, so you want the option to run using the link tree in the buck-out dir and not pay for the zip construction during development.

Basically this works pretty well. I think the zip stuff could be more deterministic than it is, but someone who needs that can make it so.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 7, 2026
@cormacrelf cormacrelf marked this pull request as draft May 7, 2026 05:02
@cormacrelf cormacrelf marked this pull request as ready for review May 7, 2026 05:02
This is a claude oneshot except for the `zip_safe = True` (default) behaviour.
The one Meta uses has never been open sourced. This is a version for OSS users.
@cormacrelf cormacrelf force-pushed the make_py_package_standalone branch from 1fa348f to a77fdc4 Compare May 11, 2026 01:50
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented May 11, 2026

@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this in D104173869. (Because this pull request was imported automatically, there will not be any future comments.)

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make_pex_standalone binary / deployment

1 participant