Skip to content

Commit b71c942

Browse files
committed
Integrate Rust into the build process properly
1 parent 9108bb0 commit b71c942

File tree

20 files changed

+465
-21
lines changed

20 files changed

+465
-21
lines changed

.github/dependabot.yml

+7
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "daily"
7+
- package-ecosystem: cargo
8+
directory: "/src/rust/"
9+
schedule:
10+
interval: daily
11+
allow:
12+
# Also update indirect dependencies
13+
- dependency-type: all

.github/workflows/ci.yml

+82-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
matrix:
1717
PYTHON:
18-
- {VERSION: "3.9", TOXENV: "pep8,packaging,docs", COVERAGE: "false"}
18+
- {VERSION: "3.9", TOXENV: "pep8,rust,packaging,docs", COVERAGE: "false"}
1919
- {VERSION: "pypy3", TOXENV: "pypy3"}
2020
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "openssl", VERSION: "1.1.0l"}}
2121
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "openssl", VERSION: "1.1.1i"}}
@@ -26,6 +26,8 @@ jobs:
2626
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "libressl", VERSION: "3.1.5"}}
2727
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "libressl", VERSION: "3.2.3"}}
2828
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "libressl", VERSION: "3.3.1"}}
29+
RUST:
30+
- stable
2931
name: "${{ matrix.PYTHON.TOXENV }} ${{ matrix.PYTHON.OPENSSL.TYPE }} ${{ matrix.PYTHON.OPENSSL.VERSION }} ${{ matrix.PYTHON.OPENSSL.CONFIG_FLAGS }}"
3032
timeout-minutes: 30
3133
steps:
@@ -34,6 +36,12 @@ jobs:
3436
uses: actions/[email protected]
3537
with:
3638
python-version: ${{ matrix.PYTHON.VERSION }}
39+
- uses: actions-rs/toolchain@v1
40+
with:
41+
profile: minimal
42+
toolchain: ${{ matrix.RUST }}
43+
override: true
44+
default: true
3745
- run: git clone --depth=1 https://github.com/google/wycheproof
3846
- run: python -m pip install tox requests coverage
3947
- name: Compute config hash and set config vars
@@ -107,17 +115,56 @@ jobs:
107115
- run: 'tox -- --wycheproof-root="$HOME/wycheproof"'
108116
env:
109117
TOXENV: ${{ matrix.IMAGE.TOXENV }}
118+
RUSTUP_HOME: /root/.rustup
110119
- uses: ./.github/actions/upload-coverage
111120
with:
112121
name: "${{ matrix.IMAGE.TOXENV }} on ${{ matrix.IMAGE.IMAGE }}"
113122

123+
linux-rust:
124+
runs-on: ubuntu-latest
125+
strategy:
126+
matrix:
127+
PYTHON:
128+
- {VERSION: "3.9", TOXENV: "py39"}
129+
RUST:
130+
# Cover MSRV and in-dev versions
131+
- 1.45.0
132+
- beta
133+
- nightly
134+
name: "${{ matrix.PYTHON.TOXENV }} with Rust ${{ matrix.RUST }}"
135+
timeout-minutes: 30
136+
steps:
137+
- uses: actions/checkout@v2
138+
- name: Setup python
139+
uses: actions/[email protected]
140+
with:
141+
python-version: ${{ matrix.PYTHON.VERSION }}
142+
- uses: actions-rs/toolchain@v1
143+
with:
144+
profile: minimal
145+
toolchain: ${{ matrix.RUST }}
146+
override: true
147+
default: true
148+
- run: git clone --depth=1 https://github.com/google/wycheproof
149+
- run: python -m pip install tox coverage
150+
- name: Tests
151+
run: |
152+
tox -r -- --color=yes --wycheproof-root=wycheproof
153+
env:
154+
TOXENV: ${{ matrix.PYTHON.TOXENV }}
155+
- uses: ./.github/actions/upload-coverage
156+
with:
157+
name: "${{ matrix.PYTHON.TOXENV }} with Rust ${{ matrix.RUST }}"
158+
114159
macos:
115160
runs-on: macos-latest
116161
strategy:
117162
matrix:
118163
PYTHON:
119164
- {VERSION: "3.6", TOXENV: "py36", EXTRA_CFLAGS: ""}
120165
- {VERSION: "3.9", TOXENV: "py39", EXTRA_CFLAGS: "-DUSE_OSRANDOM_RNG_FOR_TESTING"}
166+
RUST:
167+
- stable
121168
name: "${{ matrix.PYTHON.TOXENV }} on macOS"
122169
timeout-minutes: 30
123170
steps:
@@ -126,6 +173,12 @@ jobs:
126173
uses: actions/[email protected]
127174
with:
128175
python-version: ${{ matrix.PYTHON.VERSION }}
176+
- uses: actions-rs/toolchain@v1
177+
with:
178+
profile: minimal
179+
toolchain: ${{ matrix.RUST }}
180+
override: true
181+
default: true
129182

130183
- run: python -m pip install tox requests coverage
131184

@@ -155,11 +208,13 @@ jobs:
155208
strategy:
156209
matrix:
157210
WINDOWS:
158-
- {ARCH: 'x86', WINDOWS: 'win32'}
159-
- {ARCH: 'x64', WINDOWS: 'win64'}
211+
- {ARCH: 'x86', WINDOWS: 'win32', RUST_TRIPLE: 'i686-pc-windows-msvc'}
212+
- {ARCH: 'x64', WINDOWS: 'win64', RUST_TRIPLE: 'x86_64-pc-windows-msvc'}
160213
PYTHON:
161214
- {VERSION: "3.6", TOXENV: "py36", MSVC_VERSION: "2019", CL_FLAGS: ""}
162215
- {VERSION: "3.9", TOXENV: "py39", MSVC_VERSION: "2019", CL_FLAGS: "/D USE_OSRANDOM_RNG_FOR_TESTING"}
216+
RUST:
217+
- stable
163218
JOB_NUMBER: [0, 1, 2, 3]
164219
name: "${{ matrix.PYTHON.TOXENV }} on ${{ matrix.WINDOWS.WINDOWS }} (part ${{ matrix.JOB_NUMBER }})"
165220
timeout-minutes: 30
@@ -170,6 +225,13 @@ jobs:
170225
with:
171226
python-version: ${{ matrix.PYTHON.VERSION }}
172227
architecture: ${{ matrix.WINDOWS.ARCH }}
228+
- uses: actions-rs/toolchain@v1
229+
with:
230+
profile: minimal
231+
toolchain: ${{ matrix.RUST }}
232+
override: true
233+
default: true
234+
target: ${{ matrix.WINDOWS.RUST_TRIPLE }}
173235

174236
- run: python -m pip install tox requests coverage
175237
- name: Download OpenSSL
@@ -203,14 +265,24 @@ jobs:
203265
- dynamodb-encryption-sdk
204266
- certbot
205267
- certbot-josepy
268+
RUST:
269+
- stable
270+
PYTHON:
271+
- 3.7
206272
name: "Downstream tests for ${{ matrix.DOWNSTREAM }}"
207273
timeout-minutes: 30
208274
steps:
209275
- uses: actions/checkout@v2
210276
- name: Setup python
211277
uses: actions/[email protected]
212278
with:
213-
python-version: 3.7
279+
python-version: ${{ matrix.PYTHON }}
280+
- uses: actions-rs/toolchain@v1
281+
with:
282+
profile: minimal
283+
toolchain: ${{ matrix.RUST }}
284+
override: true
285+
default: true
214286
- run: python -m pip install -U pip wheel
215287
- run: ./.github/downstream.d/${{ matrix.DOWNSTREAM }}.sh install
216288
- run: pip uninstall -y enum34
@@ -228,6 +300,12 @@ jobs:
228300
uses: actions/[email protected]
229301
with:
230302
python-version: 3.9
303+
- uses: actions-rs/toolchain@v1
304+
with:
305+
profile: minimal
306+
toolchain: stable
307+
override: true
308+
default: true
231309
- run: python -m pip install -U tox
232310
- run: tox -r -- --color=yes
233311
env:

.github/workflows/wheel-builder.yml

+19-7
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ jobs:
1313
matrix:
1414
PYTHON: ["cp36-cp36m"]
1515
MANYLINUX:
16-
- NAME: manylinux1_x86_64
17-
CONTAINER: "cryptography-manylinux1:x86_64"
1816
- NAME: manylinux2010_x86_64
1917
CONTAINER: "cryptography-manylinux2010:x86_64"
2018
- NAME: manylinux2014_x86_64
@@ -23,7 +21,7 @@ jobs:
2321
steps:
2422
- run: /opt/python/${{ matrix.PYTHON }}/bin/python -m virtualenv .venv
2523
- name: Install Python dependencies
26-
run: .venv/bin/pip install -U pip wheel cffi six ipaddress "enum34; python_version < '3'"
24+
run: .venv/bin/pip install -U pip wheel cffi six ipaddress "enum34; python_version < '3' setuptools-rust"
2725
- run: .venv/bin/pip download cryptography==${{ github.event.inputs.version }} --no-deps --no-binary cryptography && tar zxvf cryptography*.tar.gz && mkdir tmpwheelhouse
2826
- run: |
2927
REGEX="cp3([0-9])*"
@@ -77,9 +75,15 @@ jobs:
7775
${{ matrix.PYTHON.BIN_PATH }} .github/workflows/download_openssl.py macos openssl-macos-x86-64
7876
env:
7977
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
- uses: actions-rs/toolchain@v1
79+
with:
80+
profile: minimal
81+
toolchain: stable
82+
override: true
83+
default: true
8084

8185
- run: ${{ matrix.PYTHON.BIN_PATH }} -m virtualenv venv
82-
- run: venv/bin/pip install -U pip wheel cffi six ipaddress "enum34; python_version < '3'"
86+
- run: venv/bin/pip install -U pip wheel cffi six ipaddress "enum34; python_version < '3' setuptools-rust"
8387
- run: venv/bin/pip download cryptography==${{ github.event.inputs.version }} --no-deps --no-binary cryptography && tar zxvf cryptography*.tar.gz && mkdir wheelhouse
8488
- name: Build the wheel
8589
run: |
@@ -104,8 +108,8 @@ jobs:
104108
strategy:
105109
matrix:
106110
WINDOWS:
107-
- {ARCH: 'x86', WINDOWS: 'win32'}
108-
- {ARCH: 'x64', WINDOWS: 'win64'}
111+
- {ARCH: 'x86', WINDOWS: 'win32', RUST_TRIPLE: 'i686-pc-windows-msvc'}
112+
- {ARCH: 'x64', WINDOWS: 'win64', RUST_TRIPLE: 'x86_64-pc-windows-msvc'}
109113
PYTHON:
110114
- {VERSION: "3.8", MSVC_VERSION: "2019", "ABI_VERSION": "cp36"}
111115
name: "${{ matrix.PYTHON.VERSION }} ${{ matrix.WINDOWS.WINDOWS }} ${{ matrix.PYTHON.ABI_VERSION }}"
@@ -116,6 +120,14 @@ jobs:
116120
with:
117121
python-version: ${{ matrix.PYTHON.VERSION }}
118122
architecture: ${{ matrix.WINDOWS.ARCH }}
123+
- uses: actions-rs/toolchain@v1
124+
with:
125+
profile: minimal
126+
toolchain: stable
127+
override: true
128+
default: true
129+
target: ${{ matrix.WINDOWS.RUST_TRIPLE }}
130+
119131
- run: pip install requests
120132
- name: Download OpenSSL
121133
run: |
@@ -126,7 +138,7 @@ jobs:
126138
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
127139
shell: bash
128140

129-
- run: python -m pip install -U pip wheel cffi six ipaddress "enum34; python_version < '3'"
141+
- run: python -m pip install -U pip wheel cffi six ipaddress "enum34; python_version < '3' setuptools-rust"
130142
- run: pip download cryptography==${{ github.event.inputs.version }} --no-deps --no-binary cryptography && tar zxvf cryptography*.tar.gz && mkdir wheelhouse
131143
shell: bash
132144
- run: cd cryptography* && python setup.py bdist_wheel --py-limited-api=${{ matrix.PYTHON.ABI_VERSION }} && mv dist/cryptography*.whl ../wheelhouse

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ htmlcov/
1212
.eggs/
1313
*.py[cdo]
1414
.hypothesis/
15+
target/

.zuul.d/jobs.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@
4949
nodeset: ubuntu-bionic
5050
vars:
5151
wheel_builds:
52-
- platform: manylinux1_x86_64
53-
image: ghcr.io/pyca/cryptography-manylinux1:x86_64
54-
pythons:
55-
- cp36-cp36m
5652
- platform: manylinux2010_x86_64
5753
image: ghcr.io/pyca/cryptography-manylinux2010:x86_64
5854
pythons:

.zuul.playbooks/playbooks/tox/pre.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@
3232
become: yes
3333
when: ansible_distribution == 'CentOS'
3434

35+
- name: Install rust
36+
include_role:
37+
name: ensure-rust
38+

.zuul.playbooks/playbooks/wheel/roles/build-wheel-manylinux/files/build-wheels.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ for P in ${PYTHONS}; do
1111

1212
"${PYBIN}"/python -m virtualenv .venv
1313

14-
.venv/bin/pip install cffi six ipaddress "enum34; python_version < '3'"
14+
.venv/bin/pip install cffi six ipaddress "enum34; python_version < '3'" setuptools-rust
1515

1616
REGEX="cp3([0-9])*"
1717
if [[ "${PYBIN}" =~ $REGEX ]]; then

.zuul.playbooks/playbooks/wheel/roles/build-wheel-manylinux/tasks/main.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
become: yes
2424
when: ansible_distribution in ['Debian', 'Ubuntu']
2525

26+
- name: Install rust
27+
include_role:
28+
name: ensure-rust
29+
30+
- name: Install setuptools-rust
31+
pip:
32+
name: setuptools-rust
33+
become: yes
34+
2635
- name: Create sdist
2736
command: |
2837
python3 setup.py sdist

CHANGELOG.rst

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
Changelog
22
=========
33

4+
.. _v3-4:
5+
46
3.4 - `master`_
57
~~~~~~~~~~~~~~~
68

79
.. note:: This version is not yet released and is under active development.
810

911
* **BACKWARDS INCOMPATIBLE:** Support for Python 2 has been removed.
10-
* We now ship ``manylinux2014`` wheels in addition to our ``manylinux1`` and
11-
``manylinux2010`` wheels.
12+
* We now ship ``manylinux2014`` wheels, and no longer ship ``manylinux1``
13+
wheels.
14+
* ``cryptography`` now incorporates Rust code. Users building ``cryptography``
15+
themselves will need to have the Rust toolchain installed, users who use an
16+
officially produced wheel will not need to make any changes.
1217

1318
.. _v3-3-1:
1419

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ include pyproject.toml
1010

1111
recursive-include docs *
1212
recursive-include src/_cffi_src *.py *.c *.h
13+
recursive-include src/rust Cargo.toml Cargo.lock *.rs
1314
prune docs/_build
1415
recursive-include tests *.py
1516
exclude vectors

docs/conf.py

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
4545
extensions = [
4646
"sphinx.ext.autodoc",
47+
"sphinx.ext.autosectionlabel",
4748
"sphinx.ext.doctest",
4849
"sphinx.ext.intersphinx",
4950
"sphinx.ext.viewcode",
@@ -198,3 +199,5 @@
198199
# Inconsistent small DH params they seem incapable of fixing
199200
r"https://www.secg.org/sec1-v2.pdf",
200201
]
202+
203+
autosectionlabel_prefix_document = True

docs/faq.rst

+13
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ upstream, ``cryptography`` is also dropping support for them. To fix this issue
117117
you should upgrade to a newer version of OpenSSL (1.1.0 or later). This may
118118
require you to upgrade to a newer operating system.
119119

120+
Installing ``cryptography`` fails with ``error: Can not find Rust compiler``
121+
----------------------------------------------------------------------------
122+
123+
Building ``cryptography`` from source requires you have :ref:`Rust installed
124+
and available<installation:Rust>` on your ``PATH``. You may be able to fix this
125+
by upgrading to a newer version of ``pip`` which will install a pre-compiled
126+
``cryptography`` wheel. If not, you'll need to install Rust.
127+
128+
For the current release *only* you can temporarily bypass the requirement to
129+
have Rust installed by setting the ``CRYPTOGRAPHY_DONT_BUILD_RUST`` environment
130+
variable. Note that this option will be removed in the next release and not
131+
having Rust available will be a hard error.
132+
120133
Why are there no wheels for my Python3.x version?
121134
-------------------------------------------------
122135

0 commit comments

Comments
 (0)