rust/hgcli/pyoxidizer.bzl
changeset 44642 af739894a4c1
child 44643 bc847878f4c0
equal deleted inserted replaced
44641:02f66b23cba3 44642:af739894a4c1
       
     1 # This file defines how PyOxidizer application building and packaging is
       
     2 # performed. See the pyoxidizer crate's documentation for extensive
       
     3 # documentation on this file format.
       
     4 
       
     5 # Obtain the default PythonDistribution for our build target. We link
       
     6 # this distribution into our produced executable and extract the Python
       
     7 # standard library from it.
       
     8 def make_dist():
       
     9     return default_python_distribution()
       
    10 
       
    11 # Configuration files consist of functions which define build "targets."
       
    12 # This function creates a Python executable and installs it in a destination
       
    13 # directory.
       
    14 def make_exe(dist):
       
    15     # This variable defines the configuration of the
       
    16     # embedded Python interpreter.
       
    17     python_config = PythonInterpreterConfig(
       
    18         #     bytes_warning=0,
       
    19         #     dont_write_bytecode=True,
       
    20         #     ignore_environment=True,
       
    21         #     inspect=False,
       
    22         #     interactive=False,
       
    23         #     isolated=False,
       
    24         #     legacy_windows_fs_encoding=False,
       
    25         #     legacy_windows_stdio=False,
       
    26         #     no_site=True,
       
    27         #     no_user_site_directory=True,
       
    28         #     optimize_level=0,
       
    29         #     parser_debug=False,
       
    30         #     stdio_encoding=None,
       
    31         #     unbuffered_stdio=False,
       
    32         #     filesystem_importer=False,
       
    33         #     sys_frozen=False,
       
    34         #     sys_meipass=False,
       
    35         #     sys_paths=None,
       
    36         #     raw_allocator=None,
       
    37         #     terminfo_resolution="dynamic",
       
    38         #     terminfo_dirs=None,
       
    39         #     use_hash_seed=False,
       
    40         #     verbose=0,
       
    41         #     write_modules_directory_env=None,
       
    42         #     run_eval=None,
       
    43         #     run_module=None,
       
    44         #     run_noop=False,
       
    45         #     run_repl=True,
       
    46     )
       
    47 
       
    48     # The run_eval, run_module, run_noop, and run_repl arguments are mutually
       
    49     # exclusive controls over what the interpreter should do once it initializes.
       
    50     #
       
    51     # run_eval -- Run the specified string value via `eval()`.
       
    52     # run_module -- Import the specified module as __main__ and run it.
       
    53     # run_noop -- Do nothing.
       
    54     # run_repl -- Start a Python REPL.
       
    55     #
       
    56     # These arguments can be ignored if you are providing your own Rust code for
       
    57     # starting the interpreter, as Rust code has full control over interpreter
       
    58     # behavior.
       
    59 
       
    60     # Produce a PythonExecutable from a Python distribution, embedded
       
    61     # resources, and other options. The returned object represents the
       
    62     # standalone executable that will be built.
       
    63     exe = dist.to_python_executable(
       
    64         name = "hgcli",
       
    65         config = python_config,
       
    66         # Embed all extension modules, making this a fully-featured Python.
       
    67         extension_module_filter = "all",
       
    68 
       
    69         # Only package the minimal set of extension modules needed to initialize
       
    70         # a Python interpreter. Many common packages in Python's standard
       
    71         # library won't work with this setting.
       
    72         #extension_module_filter='minimal',
       
    73 
       
    74         # Only package extension modules that don't require linking against
       
    75         # non-Python libraries. e.g. will exclude support for OpenSSL, SQLite3,
       
    76         # other features that require external libraries.
       
    77         #extension_module_filter='no-libraries',
       
    78 
       
    79         # Only package extension modules that don't link against GPL licensed
       
    80         # libraries.
       
    81         #extension_module_filter='no-gpl',
       
    82 
       
    83         # Include Python module sources. This isn't strictly required and it does
       
    84         # make binary sizes larger. But having the sources can be useful for
       
    85         # activities such as debugging.
       
    86         include_sources = True,
       
    87 
       
    88         # Whether to include non-module resource data/files.
       
    89         include_resources = False,
       
    90 
       
    91         # Do not include functionality for testing Python itself.
       
    92         include_test = False,
       
    93     )
       
    94 
       
    95     # Invoke `pip install` with our Python distribution to install a single package.
       
    96     # `pip_install()` returns objects representing installed files.
       
    97     # `add_in_memory_python_resources()` adds these objects to the binary,
       
    98     # marking them for in-memory loading.
       
    99     #exe.add_in_memory_python_resources(dist.pip_install(["appdirs"]))
       
   100 
       
   101     # Invoke `pip install` using a requirements file and add the collected resources
       
   102     # to our binary.
       
   103     #exe.add_in_memory_python_resources(dist.pip_install(["-r", "requirements.txt"]))
       
   104 
       
   105     # Read Python files from a local directory and add them to our embedded
       
   106     # context, taking just the resources belonging to the `foo` and `bar`
       
   107     # Python packages.
       
   108     #exe.add_in_memory_python_resources(dist.read_package_root(
       
   109     #    path="/src/mypackage",
       
   110     #    packages=["foo", "bar"],
       
   111     #))
       
   112 
       
   113     # Discover Python files from a virtualenv and add them to our embedded
       
   114     # context.
       
   115     #exe.add_in_memory_python_resources(dist.read_virtualenv(path="/path/to/venv"))
       
   116 
       
   117     # Filter all resources collected so far through a filter of names
       
   118     # in a file.
       
   119     #exe.filter_from_files(files=["/path/to/filter-file"]))
       
   120 
       
   121     # Return our `PythonExecutable` instance so it can be built and
       
   122     # referenced by other consumers of this target.
       
   123     return exe
       
   124 
       
   125 def make_embedded_resources(exe):
       
   126     return exe.to_embedded_resources()
       
   127 
       
   128 def make_install(exe):
       
   129     # Create an object that represents our installed application file layout.
       
   130     files = FileManifest()
       
   131 
       
   132     # Add the generated executable to our install layout in the root directory.
       
   133     files.add_python_resource(".", exe)
       
   134 
       
   135     return files
       
   136 
       
   137 # Tell PyOxidizer about the build targets defined above.
       
   138 register_target("dist", make_dist)
       
   139 register_target("exe", make_exe, depends = ["dist"], default = True)
       
   140 register_target("resources", make_embedded_resources, depends = ["exe"], default_build_script = True)
       
   141 register_target("install", make_install, depends = ["exe"])
       
   142 
       
   143 # Resolve whatever targets the invoker of this configuration file is requesting
       
   144 # be resolved.
       
   145 resolve_targets()
       
   146 
       
   147 # END OF COMMON USER-ADJUSTED SETTINGS.
       
   148 #
       
   149 # Everything below this is typically managed by PyOxidizer and doesn't need
       
   150 # to be updated by people.
       
   151 
       
   152 PYOXIDIZER_VERSION = "0.7.0-pre"
       
   153 PYOXIDIZER_COMMIT = "c772a1379c3026314eda1c8ea244b86c0658951d"