rust/hgcli/pyoxidizer.bzl
changeset 45685 57b5452a55d5
parent 44822 118f067f6bd1
child 45749 f95b16796688
equal deleted inserted replaced
45684:0c18493287f5 45685:57b5452a55d5
     1 ROOT = CWD + "/../.."
     1 ROOT = CWD + "/../.."
       
     2 
       
     3 IS_WINDOWS = "windows" in BUILD_TARGET_TRIPLE
     2 
     4 
     3 # Code to run in Python interpreter.
     5 # Code to run in Python interpreter.
     4 RUN_CODE = "import hgdemandimport; hgdemandimport.enable(); from mercurial import dispatch; dispatch.run()"
     6 RUN_CODE = "import hgdemandimport; hgdemandimport.enable(); from mercurial import dispatch; dispatch.run()"
     5 
     7 
     6 set_build_path(ROOT + "/build/pyoxidizer")
     8 set_build_path(ROOT + "/build/pyoxidizer")
     9     return default_python_distribution()
    11     return default_python_distribution()
    10 
    12 
    11 def make_distribution_windows():
    13 def make_distribution_windows():
    12     return default_python_distribution(flavor = "standalone_dynamic")
    14     return default_python_distribution(flavor = "standalone_dynamic")
    13 
    15 
       
    16 def resource_callback(policy, resource):
       
    17     # We use a custom resource routing policy to influence where things are loaded
       
    18     # from.
       
    19     #
       
    20     # For Python modules and resources, we load from memory if they are in
       
    21     # the standard library and from the filesystem if not. This is because
       
    22     # parts of Mercurial and some 3rd party packages aren't yet compatible
       
    23     # with memory loading.
       
    24     #
       
    25     # For Python extension modules, we load from the filesystem because
       
    26     # this yields greatest compatibility.
       
    27     if type(resource) in ("PythonModuleSource", "PythonPackageResource", "PythonPackageDistributionResource"):
       
    28         if resource.is_stdlib:
       
    29             resource.add_location = "in-memory"
       
    30         else:
       
    31             resource.add_location = "filesystem-relative:lib"
       
    32 
       
    33     elif type(resource) == "PythonExtensionModule":
       
    34         resource.add_location = "filesystem-relative:lib"
       
    35 
    14 def make_exe(dist):
    36 def make_exe(dist):
    15     """Builds a Rust-wrapped Mercurial binary."""
    37     """Builds a Rust-wrapped Mercurial binary."""
       
    38     packaging_policy = dist.make_python_packaging_policy()
       
    39     # Extension may depend on any Python functionality. Include all
       
    40     # extensions.
       
    41     packaging_policy.extension_module_filter = "all"
       
    42     packaging_policy.resources_policy = "prefer-in-memory-fallback-filesystem-relative:lib"
       
    43     packaging_policy.register_resource_callback(resource_callback)
       
    44 
    16     config = PythonInterpreterConfig(
    45     config = PythonInterpreterConfig(
    17         raw_allocator = "system",
    46         raw_allocator = "system",
    18         run_eval = RUN_CODE,
    47         run_eval = RUN_CODE,
    19         # We want to let the user load extensions from the file system
    48         # We want to let the user load extensions from the file system
    20         filesystem_importer = True,
    49         filesystem_importer = True,
    23         legacy_windows_stdio = True,
    52         legacy_windows_stdio = True,
    24     )
    53     )
    25 
    54 
    26     exe = dist.to_python_executable(
    55     exe = dist.to_python_executable(
    27         name = "hg",
    56         name = "hg",
    28         resources_policy = "prefer-in-memory-fallback-filesystem-relative:lib",
    57         packaging_policy = packaging_policy,
    29         config = config,
    58         config = config,
    30         # Extension may depend on any Python functionality. Include all
       
    31         # extensions.
       
    32         extension_module_filter = "all",
       
    33     )
    59     )
    34 
    60 
    35     # Add Mercurial to resources.
    61     # Add Mercurial to resources.
    36     for resource in dist.pip_install(["--verbose", ROOT]):
    62     exe.add_python_resources(exe.pip_install(["--verbose", ROOT]))
    37         # This is a bit wonky and worth explaining.
       
    38         #
       
    39         # Various parts of Mercurial don't yet support loading package
       
    40         # resources via the ResourceReader interface. Or, not having
       
    41         # file-based resources would be too inconvenient for users.
       
    42         #
       
    43         # So, for package resources, we package them both in the
       
    44         # filesystem as well as in memory. If both are defined,
       
    45         # PyOxidizer will prefer the in-memory location. So even
       
    46         # if the filesystem file isn't packaged in the location
       
    47         # specified here, we should never encounter an errors as the
       
    48         # resource will always be available in memory.
       
    49         if type(resource) == "PythonPackageResource":
       
    50             exe.add_filesystem_relative_python_resource(".", resource)
       
    51             exe.add_in_memory_python_resource(resource)
       
    52         else:
       
    53             exe.add_python_resource(resource)
       
    54 
    63 
    55     # On Windows, we install extra packages for convenience.
    64     # On Windows, we install extra packages for convenience.
    56     if "windows" in BUILD_TARGET_TRIPLE:
    65     if IS_WINDOWS:
    57         exe.add_python_resources(
    66         exe.add_python_resources(
    58             dist.pip_install(["-r", ROOT + "/contrib/packaging/requirements_win32.txt"]),
    67             exe.pip_install(["-r", ROOT + "/contrib/packaging/requirements_win32.txt"]),
    59         )
    68         )
    60 
    69 
    61     return exe
    70     return exe
    62 
    71 
    63 def make_manifest(dist, exe):
    72 def make_manifest(dist, exe):
    93 # END OF COMMON USER-ADJUSTED SETTINGS.
   102 # END OF COMMON USER-ADJUSTED SETTINGS.
    94 #
   103 #
    95 # Everything below this is typically managed by PyOxidizer and doesn't need
   104 # Everything below this is typically managed by PyOxidizer and doesn't need
    96 # to be updated by people.
   105 # to be updated by people.
    97 
   106 
    98 PYOXIDIZER_VERSION = "0.7.0"
   107 PYOXIDIZER_VERSION = "0.8.0-pre"
       
   108 PYOXIDIZER_COMMIT = "4697fb25918dfad6dc73288daeea501063963a08"