From patchwork Sun Jan 26 07:16:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D7450: packaging: add support for PyOxidizer From: phabricator X-Patchwork-Id: 44672 Message-Id: <5ef6725f4b26a166959655a0d416a561@localhost.localdomain> To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Sun, 26 Jan 2020 07:16:58 +0000 indygreg edited the summary of this revision. indygreg retitled this revision from "INCOMPLETE pyoxidizer" to "packaging: add support for PyOxidizer". indygreg updated this revision to Diff 19619. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7450?vs=18201&id=19619 BRANCH default CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7450/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7450 AFFECTED FILES contrib/packaging/pyoxidizer.bzl CHANGE DETAILS To: indygreg, #hg-reviewers Cc: marmoute, mharbison72, martinvonz, durin42, kevincox, mercurial-devel diff --git a/contrib/packaging/pyoxidizer.bzl b/contrib/packaging/pyoxidizer.bzl new file mode 100644 --- /dev/null +++ b/contrib/packaging/pyoxidizer.bzl @@ -0,0 +1,58 @@ +# Instructions: +# +# 1. cargo install --git https://github.com/indygreg/PyOxidizer.git --branch main pyoxidizer +# (commit 10358ff65b5770 is known to work if main isn't working). +# 2. cd /path/to/hg +# 3. pyoxidizer build --path contrib/packaging [--release] +# 4. Run build/pyoxidizer///app/hg +# +# If you need to build again, you need to remove the build/lib.* and +# build/temp.* directories, otherwise PyOxidizer fails to pick up C +# extensions. This is a bug in PyOxidizer. + +ROOT = CWD + "/../.." + +set_build_path(ROOT + "/build/pyoxidizer") + +def make_exe(): + dist = default_python_distribution() + + code = "import hgdemandimport; hgdemandimport.enable(); from mercurial import dispatch; dispatch.run()" + + config = PythonInterpreterConfig( + raw_allocator = "system", + run_eval = code, + # We need this to make resourceutil happy, since it looks for sys.frozen. + sys_frozen = True, + ) + + exe = dist.to_python_executable( + name = "hg", + config = config, + ) + + # Use setup.py install to build Mercurial and collect Python resources to + # embed in the executable. + resources = dist.setup_py_install(ROOT) + exe.add_python_resources(resources) + + return exe + +def make_install(exe): + m = FileManifest() + + # `hg` goes in root directory. + m.add_python_resource(".", exe) + + templates = glob( + ROOT + "/mercurial/templates/**/*", + strip_prefix = ROOT + "/mercurial/", + ) + m.add_manifest(templates) + + return m + +register_target("exe", make_exe) +register_target("app", make_install, depends = ["exe"], default = True) + +resolve_targets()