Skip to content

Commit 3107382

Browse files
committed
Integrate Rust into the build process properly
1 parent c2624de commit 3107382

File tree

18 files changed

+116
-65
lines changed

18 files changed

+116
-65
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,23 @@ jobs:
1515
strategy:
1616
matrix:
1717
PYTHON:
18-
- {VERSION: "2.7", TOXENV: "py27", EXTRA_CFLAGS: ""}
1918
- {VERSION: "3.5", TOXENV: "py35", EXTRA_CFLAGS: ""}
2019
- {VERSION: "3.8", TOXENV: "py38", EXTRA_CFLAGS: "-DUSE_OSRANDOM_RNG_FOR_TESTING"}
20+
RUST:
21+
- stable
2122
name: "Python ${{ matrix.PYTHON.VERSION }} on macOS"
2223
steps:
2324
- uses: actions/checkout@master
2425
- name: Setup python
2526
uses: actions/setup-python@v1
2627
with:
2728
python-version: ${{ matrix.PYTHON.VERSION }}
29+
- uses: actions-rs/toolchain@v1
30+
with:
31+
profile: minimal
32+
toolchain: ${{ matrix.RUST }}
33+
override: true
34+
default: true
2835

2936
- run: python -m pip install tox requests coverage
3037

@@ -55,14 +62,15 @@ jobs:
5562
strategy:
5663
matrix:
5764
WINDOWS:
58-
- {ARCH: 'x86', WINDOWS: 'win32'}
59-
- {ARCH: 'x64', WINDOWS: 'win64'}
65+
- {ARCH: 'x86', WINDOWS: 'win32', RUST_TRIPLE: 'i686-pc-windows-msvc'}
66+
- {ARCH: 'x64', WINDOWS: 'win64', RUST_TRIPLE: 'x86_64-pc-windows-msvc'}
6067
PYTHON:
61-
- {VERSION: "2.7", TOXENV: "py27", MSVC_VERSION: "2010", CL_FLAGS: ""}
6268
- {VERSION: "3.5", TOXENV: "py35", MSVC_VERSION: "2019", CL_FLAGS: ""}
6369
- {VERSION: "3.6", TOXENV: "py36", MSVC_VERSION: "2019", CL_FLAGS: ""}
6470
- {VERSION: "3.7", TOXENV: "py37", MSVC_VERSION: "2019", CL_FLAGS: ""}
6571
- {VERSION: "3.8", TOXENV: "py38", MSVC_VERSION: "2019", CL_FLAGS: "/D USE_OSRANDOM_RNG_FOR_TESTING"}
72+
RUST:
73+
- stable
6674
name: "Python ${{ matrix.PYTHON.VERSION }} on ${{ matrix.WINDOWS.WINDOWS }}"
6775
steps:
6876
- uses: actions/checkout@master
@@ -71,14 +79,14 @@ jobs:
7179
with:
7280
python-version: ${{ matrix.PYTHON.VERSION }}
7381
architecture: ${{ matrix.WINDOWS.ARCH }}
82+
- uses: actions-rs/toolchain@v1
83+
with:
84+
profile: minimal
85+
toolchain: ${{ matrix.RUST }}
86+
override: true
87+
default: true
88+
target: ${{ matrix.WINDOWS.RUST_TRIPLE }}
7489

75-
- name: Install MSVC for Python 2.7
76-
run: |
77-
Invoke-WebRequest -Uri https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi -OutFile VCForPython27.msi
78-
Start-Process msiexec -Wait -ArgumentList @('/i', 'VCForPython27.msi', '/qn', 'ALLUSERS=1')
79-
Remove-Item VCForPython27.msi -Force
80-
shell: powershell
81-
if: matrix.PYTHON.VERSION == '2.7'
8290
- run: python -m pip install tox requests coverage
8391
- name: Download OpenSSL
8492
run: |

.github/workflows/wheel-builder.yml

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
container: ${{ matrix.MANYLINUX.CONTAINER }}
1212
strategy:
1313
matrix:
14-
PYTHON: ["cp27-cp27m", "cp27-cp27mu", "cp35-cp35m"]
14+
PYTHON: ["cp35-cp35m"]
1515
MANYLINUX:
1616
- NAME: manylinux1_x86_64
1717
CONTAINER: "pyca/cryptography-manylinux1:x86_64"
@@ -21,7 +21,7 @@ jobs:
2121
steps:
2222
- run: /opt/python/${{ matrix.PYTHON }}/bin/python -m virtualenv .venv
2323
- name: Install Python dependencies
24-
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"
2525
- run: .venv/bin/pip download cryptography==${{ github.event.inputs.version }} --no-deps --no-binary cryptography && tar zxvf cryptography*.tar.gz && mkdir tmpwheelhouse
2626
- run: |
2727
REGEX="cp3([0-9])*"
@@ -57,10 +57,6 @@ jobs:
5757
strategy:
5858
matrix:
5959
PYTHON:
60-
- VERSION: '2.7'
61-
ABI_VERSION: '2.7'
62-
DOWNLOAD_URL: 'https://www.python.org/ftp/python/2.7.17/python-2.7.17-macosx10.9.pkg'
63-
BIN_PATH: '/Library/Frameworks/Python.framework/Versions/2.7/bin/python'
6460
- VERSION: '3.8'
6561
ABI_VERSION: '3.5'
6662
DOWNLOAD_URL: 'https://www.python.org/ftp/python/3.8.2/python-3.8.2-macosx10.9.pkg'
@@ -79,9 +75,15 @@ jobs:
7975
${{ matrix.PYTHON.BIN_PATH }} .github/workflows/download_openssl.py macos openssl-macos
8076
env:
8177
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
8284

8385
- run: ${{ matrix.PYTHON.BIN_PATH }} -m virtualenv venv
84-
- 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"
8587
- run: venv/bin/pip download cryptography==${{ github.event.inputs.version }} --no-deps --no-binary cryptography && tar zxvf cryptography*.tar.gz && mkdir wheelhouse
8688
- name: Build the wheel
8789
run: |
@@ -111,10 +113,9 @@ jobs:
111113
strategy:
112114
matrix:
113115
WINDOWS:
114-
- {ARCH: 'x86', WINDOWS: 'win32'}
115-
- {ARCH: 'x64', WINDOWS: 'win64'}
116+
- {ARCH: 'x86', WINDOWS: 'win32', RUST_TRIPLE: 'i686-pc-windows-msvc'}
117+
- {ARCH: 'x64', WINDOWS: 'win64', RUST_TRIPLE: 'x86_64-pc-windows-msvc'}
116118
PYTHON:
117-
- {VERSION: "2.7", MSVC_VERSION: "2010"}
118119
- {VERSION: "3.5", MSVC_VERSION: "2019"}
119120
- {VERSION: "3.6", MSVC_VERSION: "2019"}
120121
- {VERSION: "3.7", MSVC_VERSION: "2019"}
@@ -128,13 +129,13 @@ jobs:
128129
with:
129130
python-version: ${{ matrix.PYTHON.VERSION }}
130131
architecture: ${{ matrix.WINDOWS.ARCH }}
131-
- name: Install MSVC for Python 2.7
132-
run: |
133-
Invoke-WebRequest -Uri https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi -OutFile VCForPython27.msi
134-
Start-Process msiexec -Wait -ArgumentList @('/i', 'VCForPython27.msi', '/qn', 'ALLUSERS=1')
135-
Remove-Item VCForPython27.msi -Force
136-
shell: powershell
137-
if: matrix.PYTHON.VERSION == '2.7'
132+
- uses: actions-rs/toolchain@v1
133+
with:
134+
profile: minimal
135+
toolchain: stable
136+
override: true
137+
default: true
138+
target: ${{ matrix.WINDOWS.RUST_TRIPLE }}
138139
- run: pip install requests
139140
- name: Download OpenSSL
140141
run: |
@@ -144,7 +145,7 @@ jobs:
144145
env:
145146
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
146147

147-
- run: python -m pip install -U pip wheel cffi six ipaddress "enum34; python_version < '3'"
148+
- run: python -m pip install -U pip wheel cffi six ipaddress "enum34; python_version < '3' setuptools-rust"
148149
- run: pip download cryptography==${{ github.event.inputs.version }} --no-deps --no-binary cryptography && tar zxvf cryptography*.tar.gz && mkdir wheelhouse
149150
shell: bash
150151
- run: cd cryptography* && python setup.py bdist_wheel && mv dist/cryptography*.whl ../wheelhouse

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ htmlcov/
1212
.eggs/
1313
*.py[cdo]
1414
.hypothesis/
15+
target/
16+
Cargo.lock

.travis.yml

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,18 @@ branches:
1919
matrix:
2020
include:
2121
- python: 3.8
22-
env: TOXENV=pep8,packaging
22+
env: TOXENV=pep8,rust,packaging
2323
# Setting 'python' is just to make travis's UI a bit prettier
2424
- python: 3.6
2525
env: TOXENV=py36
2626
# Travis lists available Pythons (including PyPy) by arch and distro here:
2727
# https://docs.travis-ci.com/user/languages/python/#python-versions
28-
- python: pypy2.7-7.3.1
29-
env: TOXENV=pypy-nocoverage
3028
- python: pypy3.6-7.3.1
3129
env: TOXENV=pypy3-nocoverage
3230
- python: 3.8
3331
env: TOXENV=py38 OPENSSL=1.0.2u
34-
- python: 2.7
35-
env: TOXENV=py27 OPENSSL=1.1.0l
36-
- python: 2.7
37-
env: TOXENV=py27-ssh OPENSSL=1.1.0l
3832
- python: 3.8
3933
env: TOXENV=py38 OPENSSL=1.1.0l
40-
- python: 2.7
41-
env: TOXENV=py27 OPENSSL=1.1.1g
4234
- python: 3.8
4335
env: TOXENV=py38 OPENSSL=1.1.1g
4436
- python: 3.8
@@ -54,21 +46,12 @@ matrix:
5446
- python: 3.8
5547
env: TOXENV=py38 LIBRESSL=3.2.0
5648

57-
- python: 2.7
58-
services: docker
59-
env: TOXENV=py27 DOCKER=pyca/cryptography-runner-centos7
60-
- python: 2.7
61-
services: docker
62-
env: TOXENV=py27 DOCKER=pyca/cryptography-runner-centos8
6349
- python: 3.6
6450
services: docker
6551
env: TOXENV=py36 DOCKER=pyca/cryptography-runner-centos8
6652
- python: 3.6
6753
services: docker
6854
env: TOXENV=py36 OPENSSL_FORCE_FIPS_MODE=1 DOCKER=pyca/cryptography-runner-centos8-fips
69-
- python: 2.7
70-
services: docker
71-
env: TOXENV=py27 DOCKER=pyca/cryptography-runner-stretch
7255
- python: 3.5
7356
services: docker
7457
env: TOXENV=py35 DOCKER=pyca/cryptography-runner-stretch
@@ -87,9 +70,6 @@ matrix:
8770
- python: 3.8
8871
services: docker
8972
env: TOXENV=py38 DOCKER=pyca/cryptography-runner-ubuntu-focal
90-
- python: 2.7
91-
services: docker
92-
env: TOXENV=py27 DOCKER=pyca/cryptography-runner-ubuntu-rolling
9373
- python: 3.8
9474
services: docker
9575
env: TOXENV=py38 DOCKER=pyca/cryptography-runner-ubuntu-rolling
@@ -138,9 +118,11 @@ matrix:
138118
dist: xenial
139119

140120
install:
121+
- curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable --component rustmft
141122
- ./.travis/install.sh
142123

143124
script:
125+
- source $HOME/.cargo/env
144126
- ./.travis/run.sh
145127

146128
after_success:

.zuul.d/jobs.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@
2525
vars:
2626
tox_envlist: py36
2727

28-
- job:
29-
name: pyca-cryptography-centos-8-py27-arm64
30-
parent: pyca-cryptography-base
31-
nodeset: centos-8-arm64
32-
vars:
33-
tox_envlist: py27
34-
3528
- job:
3629
name: pyca-cryptography-build-wheel
3730
abstract: true
@@ -57,12 +50,8 @@
5750
- platform: manylinux1_x86_64
5851
image: pyca/cryptography-manylinux1:x86_64
5952
pythons:
60-
- cp27-cp27m
61-
- cp27-cp27mu
6253
- cp35-cp35m
6354
- platform: manylinux2010_x86_64
6455
image: pyca/cryptography-manylinux2010:x86_64
6556
pythons:
66-
- cp27-cp27m
67-
- cp27-cp27mu
6857
- cp35-cp35m

.zuul.d/project.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
- pyca-cryptography-ubuntu-focal-py38-arm64
77
- pyca-cryptography-ubuntu-bionic-py36-arm64
88
- pyca-cryptography-centos-8-py36-arm64
9-
- pyca-cryptography-centos-8-py27-arm64
109
release:
1110
jobs:
1211
- pyca-cryptography-build-wheel-arm64

.zuul.playbooks/playbooks/tox/main.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
become: yes
2828
when: ansible_distribution == 'CentOS'
2929

30+
- name: Install rust
31+
include_role:
32+
name: ensure-rust
33+
3034
- name: Clone wycheproof
3135
git:
3236
repo: https://github.com/google/wycheproof

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@
5353
become: yes
5454
when: ansible_distribution in ['Debian', 'Ubuntu']
5555

56+
- name: Install rust
57+
include_role:
58+
name: ensure-rust
59+
60+
- name: Install setuptools-rust
61+
pip:
62+
name: setuptools-rust
63+
become: yes
64+
5665
- name: Create sdist
5766
command: |
5867
python3 setup.py sdist

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Changelog
22
=========
33

4+
TODO: Add Rust to the current release when this is ready to land.
5+
46
.. _v3-2:
57

68
3.2 - `master`_

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ include pyproject.toml
1111

1212
recursive-include docs *
1313
recursive-include src/_cffi_src *.py *.c *.h
14+
recursive-include src/rust Cargo.toml *.rs
1415
prune docs/_build
1516
recursive-include tests *.py
1617
exclude vectors

docs/faq.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ series. Since they are no longer receiving security patches from upstream,
118118
should upgrade to a newer version of OpenSSL (1.0.2 or later). This may require
119119
you to upgrade to a newer operating system.
120120

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

docs/installation.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ platforms). ``cryptography`` links against the new 1.1.0 names by default. If
6666
you need to compile ``cryptography`` against an older version then you **must**
6767
set ``CRYPTOGRAPHY_WINDOWS_LINK_LEGACY_OPENSSL`` or else installation will fail.
6868

69+
You will also need to have Rust installed and available.
70+
6971
If you need to rebuild ``cryptography`` for any reason be sure to clear the
7072
local `wheel cache`_.
7173

@@ -88,6 +90,8 @@ If you are on Alpine or just want to compile it yourself then
8890
using ``pypy``), and headers for the OpenSSL and ``libffi`` libraries
8991
available on your system.
9092

93+
On all Linux distributions you will need to have Rust installed and available.
94+
9195
Alpine
9296
~~~~~~
9397

@@ -238,6 +242,8 @@ open a terminal window and run:
238242
This will install a compiler (clang) along with (most of) the required
239243
development headers.
240244

245+
You will also need to have Rust installed and available.
246+
241247
You'll also need OpenSSL, which you can obtain from `Homebrew`_ or `MacPorts`_.
242248
Cryptography does **not** support Apple's deprecated OpenSSL distribution.
243249

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ requires = [
66
"wheel",
77
# Must be kept in sync with the `setup_requirements` in `setup.py`
88
"cffi>=1.8,!=1.11.3; platform_python_implementation != 'PyPy'",
9+
"setuptools-rust>=0.11.1",
910
]
1011
build-backend = "setuptools.build_meta"
1112

0 commit comments

Comments
 (0)