Skip to content

Commit b9e10aa

Browse files
authored
Merge pull request #162 from davidhewitt/wheel-building-docs
docs: add wheel-building notes
2 parents 850fa82 + 71edd0a commit b9e10aa

File tree

6 files changed

+99
-78
lines changed

6 files changed

+99
-78
lines changed

README.md

Lines changed: 8 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Setuptools plugin for Rust extensions
22

3-
![example workflow](https://github.com/PyO3/setuptools-rust/actions/workflows/ci.yml/badge.svg)
4-
[![pypi package](https://badge.fury.io/py/setuptools-rust.svg)](https://badge.fury.io/py/setuptools-rust)
3+
[![github actions](https://github.com/PyO3/setuptools-rust/actions/workflows/ci.yml/badge.svg)](https://github.com/PyO3/setuptools-rust/actions/workflows/ci.yml)
4+
[![pypi package](https://badge.fury.io/py/setuptools-rust.svg)](https://pypi.org/project/setuptools-rust/)
55
[![readthedocs](https://readthedocs.org/projects/pip/badge/)](https://setuptools-rust.readthedocs.io/en/latest/)
66
[![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
77

@@ -36,41 +36,20 @@ setup(
3636
For a complete reference of the options supported by the `RustExtension` class, see the
3737
[API reference](https://setuptools-rust.readthedocs.io/en/latest/reference.html).
3838

39-
### MANIFEST.in
40-
41-
This file is required for building source distributions
42-
43-
```text
44-
include Cargo.toml
45-
recursive-include src *
46-
```
47-
4839
### pyproject.toml
4940

5041
```toml
5142
[build-system]
5243
requires = ["setuptools", "wheel", "setuptools-rust"]
5344
```
5445

55-
### build-wheels.sh
56-
57-
```bash
58-
#!/bin/bash
59-
set -ex
60-
61-
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y
62-
export PATH="$HOME/.cargo/bin:$PATH"
63-
64-
cd /io
46+
### MANIFEST.in
6547

66-
for PYBIN in /opt/python/cp{35,36,37,38,39}*/bin; do
67-
"${PYBIN}/pip" install -U setuptools wheel setuptools-rust
68-
"${PYBIN}/python" setup.py bdist_wheel
69-
done
48+
This file is required for building source distributions
7049

71-
for whl in dist/*.whl; do
72-
auditwheel repair "$whl" -w dist/
73-
done
50+
```text
51+
include Cargo.toml
52+
recursive-include src *
7453
```
7554

7655
## Usage
@@ -98,47 +77,10 @@ Processing dependencies for hello_rust==1.0
9877
Finished processing dependencies for hello_rust==1.0
9978
```
10079

101-
Or you can use commands like bdist_wheel (after installing wheel).
80+
Or you can use commands like ``bdist_wheel`` (after installing ``wheel``). See also [the notes in the documentation about building wheels](https://setuptools-rust.readthedocs.io/en/latest/building_wheels.html).
10281

10382
By default, `develop` will create a debug build, while `install` will create a release build.
10483

105-
### Binary wheels on linux
106-
107-
To build binary wheels on linux, you need to use the [manylinux docker container](https://github.com/pypa/manylinux). You also need a `build-wheels.sh` similar to [the one in the example](https://github.com/PyO3/setuptools-rust/blob/main/examples/html-py-ever/build-wheels.sh), which will be run in that container.
108-
109-
First, pull the `manylinux2014` Docker image:
110-
111-
```bash
112-
docker pull quay.io/pypa/manylinux2014_x86_64
113-
```
114-
115-
Then use the following command to build wheels for supported Python versions:
116-
117-
```bash
118-
docker run --rm -v `pwd`:/io quay.io/pypa/manylinux2014_x86_64 bash /io/build-wheels.sh
119-
```
120-
121-
This will create wheels in the `dist` directory:
122-
123-
```bash
124-
$ ls dist
125-
hello_rust-0.1.0-cp35-cp35m-linux_x86_64.whl hello_rust-0.1.0-cp35-cp35m-manylinux2014_x86_64.whl
126-
hello_rust-0.1.0-cp36-cp36m-linux_x86_64.whl hello_rust-0.1.0-cp36-cp36m-manylinux2014_x86_64.whl
127-
hello_rust-0.1.0-cp37-cp37m-linux_x86_64.whl hello_rust-0.1.0-cp37-cp37m-manylinux2014_x86_64.whl
128-
hello_rust-0.1.0-cp38-cp38-linux_x86_64.whl hello_rust-0.1.0-cp38-cp38-manylinux2014_x86_64.whl
129-
hello_rust-0.1.0-cp39-cp39-linux_x86_64.whl hello_rust-0.1.0-cp39-cp39-manylinux2014_x86_64.whl
130-
```
131-
132-
You can then upload the `manylinux2014` wheels to pypi using [twine](https://github.com/pypa/twine).
133-
134-
It is possible to use any of the `manylinux` docker images: `manylinux1`, `manylinux2010` or `manylinux2014`. (Just replace `manylinux2014` in the above instructions with the alternative version you wish to use.)
135-
136-
### Binary wheels on macOS
137-
138-
For building wheels on macOS it is sufficient to run the `bdist_wheel` command, i.e. `setup.py bdist_wheel`.
139-
140-
To build `universal2` wheels set the `ARCHFLAGS` environment variable to contain both `x86_64` and `arm64`, for example `ARCHFLAGS="-arch x86_64 -arch arm64"`. Wheel-building solutions such as [`cibuildwheel`](https://github.com/joerick/cibuildwheel) set this environment variable automatically.
141-
14284
## Commands
14385

14486
- `build` - Standard build command will also build all rust extensions.

docs/building_wheels.rst

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
Building wheels
2+
===============
3+
4+
Because ``setuptools_rust`` is an extension to ``setuptools``, the standard ``setup.py bdist_wheel`` command is used to build wheels which can be uploaded to pypy.
5+
6+
This doc suggests two ways to go about this.
7+
8+
Using ``cibuildwheel``
9+
----------------------
10+
11+
`cibuildwheel`_ is a tool to build wheels for multiple platforms using Github Actions.
12+
13+
The `rtoml package does this, for example <https://github.com/samuelcolvin/rtoml/blob/143ee0907bba616cbcd5cc58eefe9000fcc2b5f2/.github/workflows/ci.yml#L99-L195>`_.
14+
15+
Building manually
16+
-----------------
17+
18+
Place a script called ``build-wheels.sh`` with the following contents in your project root (next to the ``setup.py`` file):
19+
20+
.. code-block:: bash
21+
22+
#!/bin/bash
23+
set -ex
24+
25+
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y
26+
export PATH="$HOME/.cargo/bin:$PATH"
27+
28+
cd /io
29+
30+
for PYBIN in /opt/python/cp{36,37,38,39}*/bin; do
31+
"${PYBIN}/pip" install -U setuptools wheel setuptools-rust
32+
"${PYBIN}/python" setup.py bdist_wheel
33+
done
34+
35+
for whl in dist/*.whl; do
36+
auditwheel repair "$whl" -w dist/
37+
done
38+
39+
This script can be used to produce wheels for multiple Python versions.
40+
41+
Binary wheels on linux
42+
^^^^^^^^^^^^^^^^^^^^^^
43+
44+
To build binary wheels on linux, you need to use the `manylinux docker container <https://github.com/pypa/manylinux>`_. You also need a ``build-wheels.sh`` similar to `the one in the example <https://github.com/PyO3/setuptools-rust/blob/main/examples/html-py-ever/build-wheels.sh>`_, which will be run in that container.
45+
46+
First, pull the ``manylinux2014`` Docker image:
47+
48+
.. code-block:: bash
49+
50+
docker pull quay.io/pypa/manylinux2014_x86_64
51+
52+
53+
Then use the following command to build wheels for supported Python versions:
54+
55+
.. code-block:: bash
56+
57+
docker run --rm -v `pwd`:/io quay.io/pypa/manylinux2014_x86_64 bash /io/build-wheels.sh
58+
59+
This will create wheels in the ``dist`` directory:
60+
61+
.. code-block:: bash
62+
63+
$ ls dist
64+
hello_rust-0.1.0-cp36-cp36m-linux_x86_64.whl hello_rust-0.1.0-cp36-cp36m-manylinux2014_x86_64.whl
65+
hello_rust-0.1.0-cp37-cp37m-linux_x86_64.whl hello_rust-0.1.0-cp37-cp37m-manylinux2014_x86_64.whl
66+
hello_rust-0.1.0-cp38-cp38-linux_x86_64.whl hello_rust-0.1.0-cp38-cp38-manylinux2014_x86_64.whl
67+
hello_rust-0.1.0-cp39-cp39-linux_x86_64.whl hello_rust-0.1.0-cp39-cp39-manylinux2014_x86_64.whl
68+
69+
70+
You can then upload the ``manylinux2014`` wheels to pypi using `twine <https://github.com/pypa/twine>`_.
71+
72+
It is possible to use any of the ``manylinux`` docker images: ``manylinux1``, ``manylinux2010`` or ``manylinux2014``. (Just replace ``manylinux2014`` in the above instructions with the alternative version you wish to use.)
73+
74+
Binary wheels on macOS
75+
^^^^^^^^^^^^^^^^^^^^^^
76+
77+
For building wheels on macOS it is sufficient to run the ``bdist_wheel`` command, i.e. ``setup.py bdist_wheel``.
78+
79+
To build ``universal2`` wheels set the ``ARCHFLAGS`` environment variable to contain both ``x86_64`` and ``arm64``, for example ``ARCHFLAGS="-arch x86_64 -arch arm64"``. Wheel-building solutions such as `cibuildwheel`_ set this environment variable automatically.
80+
81+
.. _cibuildwheel: https://github.com/pypa/cibuildwheel

docs/conf.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"sphinx.ext.autodoc",
2727
"sphinx.ext.napoleon",
2828
"sphinx_autodoc_typehints",
29-
"sphinx_rtd_theme",
3029
"m2r2",
3130
]
3231

@@ -44,16 +43,14 @@
4443
# The theme to use for HTML and HTML Help pages. See the documentation for
4544
# a list of builtin themes.
4645
#
47-
html_theme = "sphinx_rtd_theme"
46+
html_theme = "furo"
4847

4948
# Add any paths that contain custom static files (such as style sheets) here,
5049
# relative to this directory. They are copied after the builtin static files,
5150
# so a file named "default.css" will overwrite the builtin "default.css".
5251
html_static_path = ["_static"]
5352

54-
html_theme_options = {
55-
"prev_next_buttons_location": None,
56-
}
53+
html_theme_options = {}
5754

5855
# -- Custom HTML link transformation to make documentation links relative --
5956

@@ -70,7 +67,7 @@ class RelativeDocLinks(SphinxTransform):
7067
default_priority = 750
7168

7269
def apply(self):
73-
from docutils.nodes import reference, Text
70+
from docutils.nodes import Text, reference
7471

7572
baseref = lambda o: (
7673
isinstance(o, reference) and o.get("refuri", "").startswith(DOCS_URL)

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
:hidden:
44

55
README
6+
building_wheels
67
reference
78

89
.. include:: README.rst

docs/requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
m2r2==0.2.7
2-
Sphinx==3.5.2
3-
sphinx-autodoc-typehints==1.11.1
4-
sphinx-rtd-theme==0.5.1
1+
m2r2==0.3.1
2+
Sphinx==4.1.2
3+
sphinx-autodoc-typehints==1.12.0
4+
furo==2021.8.31

setuptools_rust/extension.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
from distutils.errors import DistutilsSetupError
44
from enum import IntEnum, auto
55
from typing import Dict, List, Optional, Union
6-
from typing_extensions import Literal
76

87
import semantic_version
8+
from typing_extensions import Literal
99

1010

1111
class Binding(IntEnum):
1212
"""
13-
Enumeration of possible Rust binding types supported by `setuptools-rust`.
13+
Enumeration of possible Rust binding types supported by ``setuptools-rust``.
1414
1515
Attributes:
1616
PyO3: This is an extension built using

0 commit comments

Comments
 (0)