|
2 | 2 |
|
3 | 3 | This chapter of the guide goes into detail on how to build and distribute projects using PyO3. The way to achieve this is very different depending on whether the project is a Python module implemented in Rust, or a Rust binary embedding Python. For both types of project there are also common problems such as the Python version to build for and the [linker](https://en.wikipedia.org/wiki/Linker_(computing)) arguments to use.
|
4 | 4 |
|
5 |
| -The material in this chapter is intended for users who have already read the PyO3 [README](#index.md). It covers in turn the choices that can be made for Python modules and for Rust binaries. There is also a section on the end about cross-compiling projects using PyO3. |
| 5 | +The material in this chapter is intended for users who have already read the PyO3 [README](#index.md). It covers in turn the choices that can be made for Python modules and for Rust binaries. There is also a section at the end about cross-compiling projects using PyO3. |
6 | 6 |
|
7 | 7 | There is an additional sub-chapter dedicated to [supporting multiple Python versions](./building_and_distribution/multiple_python_versions.html).
|
8 | 8 |
|
@@ -40,7 +40,7 @@ pointer width: Some(8)
|
40 | 40 |
|
41 | 41 | ## Building Python extension modules
|
42 | 42 |
|
43 |
| -Python extension modules need to be compiled differently depending on the OS (and architecture) that they are being compiled for. As well as multiple OSes (and architectures). There are also many different Python versions which are actively supported Packages uploaded to [PyPI](https://pypi.org/) usually want to upload prebuilt "wheels" covering many OS/arch/version combinations so that users on all these different platforms don't have to compile the package themselves. Package vendors can opt-in to the "abi3" limited Python API which allows their wheels to be used on multiple Python versions but restricts the functionality they can use, which reduces the number of wheels they need to compile. |
| 43 | +Python extension modules need to be compiled differently depending on the OS (and architecture) that they are being compiled for. As well as multiple OSes (and architectures), there are also many different Python versions which are actively supported. Packages uploaded to [PyPI](https://pypi.org/) usually want to upload prebuilt "wheels" covering many OS/arch/version combinations so that users on all these different platforms don't have to compile the package themselves. Package vendors can opt-in to the "abi3" limited Python API which allows their wheels to be used on multiple Python versions, reducing the number of wheels they need to compile, but restricts the functionality they can use. |
44 | 44 |
|
45 | 45 | There are many ways to go about this: it is possible to use `cargo` to build the extension module (along with some manual work, which varies with OS). The PyO3 ecosystem has two packaging tools, [`maturin`] and [`setuptools-rust`], which abstract over the OS difference and also support building wheels for PyPI upload.
|
46 | 46 |
|
@@ -71,13 +71,13 @@ Once built, symlink (or copy) and rename the shared library from Cargo's `target
|
71 | 71 |
|
72 | 72 | You can then open a Python shell in the output directory and you'll be able to run `import your_module`.
|
73 | 73 |
|
74 |
| -See as an example, Bazel rules to build PyO3 on linux at https://github.com/TheButlah/rules_pyo3 |
| 74 | +See, as an example, Bazel rules to build PyO3 on Linux at https://github.com/TheButlah/rules_pyo3. |
75 | 75 |
|
76 | 76 | ### The `extension-module` feature
|
77 | 77 |
|
78 | 78 | PyO3's `extension-module` feature is used to disable [linking](https://en.wikipedia.org/wiki/Linker_(computing)) to `libpython` on unix targets.
|
79 | 79 |
|
80 |
| -This is necessary because by default PyO3 links to `libpython`. This makes binaries, tests, and examples "just work". However, Python extensions on unix must not link to libpython for [manylinux](https://www.python.org/dev/peps/pep-0513/) compliance). |
| 80 | +This is necessary because by default PyO3 links to `libpython`. This makes binaries, tests, and examples "just work". However, Python extensions on unix must not link to libpython for [manylinux](https://www.python.org/dev/peps/pep-0513/) compliance. |
81 | 81 |
|
82 | 82 | The downside of not linking to `libpython` is that binaries, tests, and examples (which usually embed Python) will fail to build. If you have an extension module as well as other outputs in a single project, you need to use optional Cargo features to disable the `extension-module` when you're not building the extension module. See [the FAQ](faq.md#i-cant-run-cargo-test-im-having-linker-issues-like-symbol-not-found-or-undefined-reference-to-_pyexc_systemerror) for an example workaround.
|
83 | 83 |
|
|
0 commit comments