|
2 | 2 | =================
|
3 | 3 |
|
4 | 4 | An example extensions with automatically generated ``Cargo.toml`` manifest
|
5 |
| -files. |
| 5 | +files. Simply run ``python setup.py tomlgen_rust`` to generate the following |
| 6 | +files: |
| 7 | + |
| 8 | +* ``Cargo.toml`` for ``hello.english`` |
| 9 | + |
| 10 | +.. code-block:: toml |
| 11 | +
|
| 12 | + [package] |
| 13 | + name = "hello.english" |
| 14 | + version = "0.1.0" |
| 15 | + authors = ["Martin Larralde <[email protected]>"] |
| 16 | + publish = false |
| 17 | +
|
| 18 | + [lib] |
| 19 | + crate-type = ["cdylib"] |
| 20 | + name = "hello_english" |
| 21 | + path = "lib.rs" |
| 22 | +
|
| 23 | + [dependencies] |
| 24 | + pyo3 = { version = "*", features = ["extension-module"] } |
| 25 | + english-lint = "*" |
| 26 | +
|
| 27 | +
|
| 28 | +* ``Cargo.toml`` for ``hello.french`` |
| 29 | + |
| 30 | +.. code-block:: toml |
| 31 | +
|
| 32 | + [package] |
| 33 | + name = "hello.french" |
| 34 | + version = "0.1.0" |
| 35 | + authors = ["Martin Larralde <[email protected]>"] |
| 36 | + publish = false |
| 37 | +
|
| 38 | + [lib] |
| 39 | + crate-type = ["cdylib"] |
| 40 | + name = "hello_french" |
| 41 | + path = "lib.rs" |
| 42 | +
|
| 43 | + [dependencies] |
| 44 | + pyo3 = { version = "*", features = ["extension-module"] } |
| 45 | +
|
| 46 | +
|
| 47 | +Metadata |
| 48 | +-------- |
| 49 | + |
| 50 | +The package name will be generated from the position of the extension within |
| 51 | +the Python package. The same version is used as the one declared in ``setup.py`` |
| 52 | +or ``setup.cfg``. |
| 53 | + |
| 54 | +The authors list is generated after the ``author`` and ``author_email`` options |
| 55 | +from ``setup.py`` / ``setup.cfg``, but can also be overriden using the |
| 56 | +``authors`` key in the ``[tomlgen_rust]`` section of ``setup.cfg``: |
| 57 | + |
| 58 | +.. code-block:: toml |
| 59 | +
|
| 60 | + [tomlgen_rust] |
| 61 | + authors = |
| 62 | + |
| 63 | + |
| 64 | +
|
| 65 | +The library name is a slugified variant of the extension package name, to |
| 66 | +avoid name collisions within the build directory. |
| 67 | + |
| 68 | +As a safety, ``publish = false`` is added to the ``[package]`` section |
| 69 | +(you wouldn't publish an automatically generated package, *would you ?!*). |
| 70 | + |
| 71 | + |
| 72 | +Options |
| 73 | +------- |
| 74 | + |
| 75 | +Use ``--force`` (or add ``force = true`` to the ``[tomlgen_rust]`` section of |
| 76 | +``setup.cfg``) to force generating a manifest even when one already exists. |
| 77 | + |
| 78 | +Use ``--create-workspace`` to create a virtual manifest at the root of your |
| 79 | +project (next to the ``setup.py`` file) which registers all of the extensions. |
| 80 | +This way, generic ``cargo`` commands can be run without leaving the root of |
| 81 | +the project. |
| 82 | + |
| 83 | + |
| 84 | +Dependencies |
| 85 | +------------ |
| 86 | + |
| 87 | +To specify dependencies for all extensions, add them to the |
| 88 | +``[tomlgen_rust.dependencies]`` section of your setuptools configuration file |
| 89 | +(``setup.cfg``), as you would normally in your ``Cargo.toml`` file. Here is |
| 90 | +probably a good place to add ``pyo3`` as a dependency. |
| 91 | + |
| 92 | +To specify per-extension dependency, create a section for each extension |
| 93 | +(``[tomlgen_rust.dependencies.<DOTTEDPATH>]``, where ``<DOTTEDPATH>`` is the |
| 94 | +complete Python path to the extension (e.g. ``hello.english``). Extension |
| 95 | +specific dependencies are added *after* global dependencies. |
| 96 | + |
| 97 | +*Note that, since all projects are built in the same directory, you can also |
| 98 | +declare all dependencies in the ``[tomlgen_rust.dependencies]``, as they will |
| 99 | +be built only once anyway*. |
| 100 | + |
| 101 | + |
| 102 | +Automatic generation at each build |
| 103 | +---------------------------------- |
| 104 | + |
| 105 | +If you intend to regenerate manifests everytime the library is built, you can |
| 106 | +add ``Cargo.toml`` and ``Cargo.lock`` to your ``.gitignore`` file. |
| 107 | + |
| 108 | +Then, make sure ``tomlgen_rust`` is run before ``build_rust`` everytime by |
| 109 | +adding aliases to your ``setup.cfg`` file: |
| 110 | + |
| 111 | +.. code-block:: toml |
| 112 | +
|
| 113 | + [aliases] |
| 114 | + build_rust = tomlgen_rust -f build_rust |
| 115 | + clean_rust = tomlgen_rust -f clean_rust |
| 116 | + build = tomlgen_rust -f build |
| 117 | + clean = clean_rust -f clean |
0 commit comments