Skip to content

Commit

Permalink
Attempt to switch to maturin.
Browse files Browse the repository at this point in the history
It seems to be much faster at doing things locally.
  • Loading branch information
alex committed Oct 31, 2023
1 parent d643b04 commit 53c5651
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/requirements/build-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
setuptools>=61.0.0
wheel
cffi>=1.12; platform_python_implementation != 'PyPy'
setuptools-rust>=0.11.4
maturin>=1,<2

# WARN: changing the requirements here DOES NOT update the dependencies used for building at the github workflow, as the build process used build-requirements.txt
# To update build-requirements.txt according to the dependencies here, run pip-compile --allow-unsafe --generate-hashes build-requirements.in
26 changes: 16 additions & 10 deletions .github/requirements/build-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,29 @@ cffi==1.16.0 ; platform_python_implementation != "PyPy" \
--hash=sha256:fa3a0128b152627161ce47201262d3140edb5a5c3da88d73a1b790a959126956 \
--hash=sha256:fcc8eb6d5902bb1cf6dc4f187ee3ea80a1eba0a89aba40a5cb20a5087d961357
# via -r build-requirements.in
maturin==1.2.0 \
--hash=sha256:02a3ec65872b294d012824d9af5a445ea614140f6fc55c16f07af04622450de3 \
--hash=sha256:03207fcb64d3a340f353de57186e3614478430ad09887e68438739b724096782 \
--hash=sha256:0d8bfa63522a454ff862c6680575255e28fa0f634d206fb5af84c73f5f5fabf0 \
--hash=sha256:138526c3275eeebb1bd566c20aae6a76f39cf55991f127c81dd79da725f45d59 \
--hash=sha256:2fb701d44c68849e4cf41d92f6aeefcc166edecccc3b0c0a430a003190dc5b2e \
--hash=sha256:45f90cac503bacfa6c20e112836b2f53a3355b7b913471f5a104f2c4b09c5b9c \
--hash=sha256:840803f176c12a56bd023a13dc0e6fef63bc0480665ee9eeda9ed527a6ccb8dc \
--hash=sha256:955d9d46cf00a8887954d5e37ab3f28dc75d46caeddb4e8e43366e39c803a3b9 \
--hash=sha256:adbf64b6ec763fc9ece32bfa0979335f79333106aabf34415ae7c72ed8b432af \
--hash=sha256:bf5986127e7dd3f6e5403dc737f260e1c425c5b7b017a492abe85f38955c6beb \
--hash=sha256:c013cf9aa0156ac25df06fa7c06edd1d115723c8c270cb25e0060bc0d25c72d5 \
--hash=sha256:c0946b9badd053c92962770aad9133d6fc9cdbc98eb8c707e808f0c5c9005651 \
--hash=sha256:cc60957012cfd3f662cd313ca0cdaac64f5f5cd6ddbbbc2a1ddab341ccc28e4d
# via -r build-requirements.in
pycparser==2.21 \
--hash=sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9 \
--hash=sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206
# via cffi
semantic-version==2.10.0 \
--hash=sha256:bdabb6d336998cbb378d4b9db3a4b56a1e3235701dc05ea2690d9a997ed5041c \
--hash=sha256:de78a3b8e0feda74cabc54aab2da702113e33ac9d9eb9d2389bcf1f58b7d9177
# via setuptools-rust
setuptools-rust==1.8.1 \
--hash=sha256:94b1dd5d5308b3138d5b933c3a2b55e6d6927d1a22632e509fcea9ddd0f7e486 \
--hash=sha256:b5324493949ccd6aa0c03890c5f6b5f02de4512e3ac1697d02e9a6c02b18aa8e
# via -r build-requirements.in
tomli==2.0.1 \
--hash=sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc \
--hash=sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f
# via setuptools-rust
# via maturin
wheel==0.41.3 \
--hash=sha256:488609bc63a29322326e05560731bf7bfea8e48ad646e1f5e40d366607de0942 \
--hash=sha256:4d4987ce51a49370ea65c0bfd2234e8ce80a12780820d9dc462597a6e60d0841
Expand All @@ -85,4 +92,3 @@ setuptools==68.2.2 \
--hash=sha256:b454a35605876da60632df1a60f736524eb73cc47bbc9f3f1ef1b644de74fd2a
# via
# -r build-requirements.in
# setuptools-rust
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ jobs:
- {VERSION: "3.12", NOXSESSION: "tests", OPENSSL: {TYPE: "openssl", VERSION: "497a7810bcee48781aa12d4db870f6a565bd0592"}}
# Builds with various Rust versions. Includes MSRV and next
# potential future MSRV:
# 1.64 - maturin
# 1.65 - Generic associated types (GATs)
- {VERSION: "3.12", NOXSESSION: "rust-noclippy,tests", RUST: "1.63.0"}
- {VERSION: "3.12", NOXSESSION: "rust,tests", RUST: "1.64.0"}
- {VERSION: "3.12", NOXSESSION: "rust,tests", RUST: "1.65.0"}
- {VERSION: "3.12", NOXSESSION: "rust,tests", RUST: "beta"}
- {VERSION: "3.12", NOXSESSION: "rust,tests", RUST: "nightly"}
timeout-minutes: 15
Expand Down
29 changes: 8 additions & 21 deletions .github/workflows/wheel-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
fail-fast: false
matrix:
PYTHON:
- { VERSION: "cp311-cp311", ABI_VERSION: 'cp37' }
- { VERSION: "cp311-cp311" }
- { VERSION: "pp39-pypy39_pp73" }
- { VERSION: "pp310-pypy310_pp73" }
MANYLINUX:
Expand Down Expand Up @@ -129,12 +129,9 @@ jobs:
- run: mkdir tmpwheelhouse
- name: Build the wheel
run: |
if [ -n "${{ matrix.PYTHON.ABI_VERSION }}" ]; then
PY_LIMITED_API="--config-settings=--build-option=--py-limited-api=${{ matrix.PYTHON.ABI_VERSION }} --no-build-isolation"
fi
OPENSSL_DIR="/opt/pyca/cryptography/openssl" \
OPENSSL_STATIC=1 \
.venv/bin/python -m pip wheel -v $PY_LIMITED_API cryptograph*.tar.gz -w dist/ && mv dist/cryptography*.whl tmpwheelhouse
.venv/bin/python -m pip wheel -v cryptograph*.tar.gz -w dist/ && mv dist/cryptography*.whl tmpwheelhouse
env:
RUSTUP_HOME: /root/.rustup
- run: auditwheel repair --plat ${{ matrix.MANYLINUX.NAME }} tmpwheelhouse/cryptograph*.whl -w wheelhouse/
Expand Down Expand Up @@ -165,7 +162,6 @@ jobs:
matrix:
PYTHON:
- VERSION: '3.11'
ABI_VERSION: 'cp37'
# Despite the name, this is built for the macOS 11 SDK on arm64 and 10.9+ on intel
DOWNLOAD_URL: 'https://www.python.org/ftp/python/3.11.3/python-3.11.3-macos11.pkg'
BIN_PATH: '/Library/Frameworks/Python.framework/Versions/3.11/bin/python3'
Expand All @@ -177,7 +173,6 @@ jobs:
# build against
_PYTHON_HOST_PLATFORM: 'macosx-10.9-universal2'
- VERSION: '3.11'
ABI_VERSION: 'cp37'
DOWNLOAD_URL: 'https://www.python.org/ftp/python/3.11.3/python-3.11.3-macos11.pkg'
BIN_PATH: '/Library/Frameworks/Python.framework/Versions/3.11/bin/python3'
DEPLOYMENT_TARGET: '10.12'
Expand All @@ -196,7 +191,7 @@ jobs:
DEPLOYMENT_TARGET: '10.12'
_PYTHON_HOST_PLATFORM: 'macosx-10.9-x86_64'
ARCHFLAGS: '-arch x86_64'
name: "${{ matrix.PYTHON.VERSION }} ABI ${{ matrix.PYTHON.ABI_VERSION }} macOS ${{ matrix.PYTHON.ARCHFLAGS }}"
name: "${{ matrix.PYTHON.VERSION }} macOS ${{ matrix.PYTHON.ARCHFLAGS }}"
steps:
- name: Get build-requirements.txt from repository
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
Expand Down Expand Up @@ -243,13 +238,9 @@ jobs:
- run: mkdir wheelhouse
- name: Build the wheel
run: |
if [ -n "${{ matrix.PYTHON.ABI_VERSION }}" ]; then
PY_LIMITED_API="--config-settings=--build-option=--py-limited-api=${{ matrix.PYTHON.ABI_VERSION }} --no-build-isolation"
fi
OPENSSL_DIR="$(readlink -f ../openssl-macos-universal2/)" \
OPENSSL_STATIC=1 \
venv/bin/python -m pip wheel -v $PY_LIMITED_API cryptograph*.tar.gz -w dist/ && mv dist/cryptography*.whl wheelhouse
venv/bin/python -m pip wheel -v cryptograph*.tar.gz -w dist/ && mv dist/cryptography*.whl wheelhouse
env:
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.PYTHON.DEPLOYMENT_TARGET }}
ARCHFLAGS: ${{ matrix.PYTHON.ARCHFLAGS }}
Expand Down Expand Up @@ -280,7 +271,7 @@ jobs:
- {ARCH: 'x86', WINDOWS: 'win32', RUST_TRIPLE: 'i686-pc-windows-msvc'}
- {ARCH: 'x64', WINDOWS: 'win64', RUST_TRIPLE: 'x86_64-pc-windows-msvc'}
PYTHON:
- {VERSION: "3.11", "ABI_VERSION": "cp37"}
- {VERSION: "3.11"}
- {VERSION: "pypy-3.9"}
- {VERSION: "pypy-3.10"}
exclude:
Expand All @@ -289,7 +280,7 @@ jobs:
PYTHON: {VERSION: "pypy-3.9"}
- WINDOWS: {ARCH: 'x86', WINDOWS: 'win32', RUST_TRIPLE: 'i686-pc-windows-msvc'}
PYTHON: {VERSION: "pypy-3.10"}
name: "${{ matrix.PYTHON.VERSION }} ${{ matrix.WINDOWS.WINDOWS }} ${{ matrix.PYTHON.ABI_VERSION }}"
name: "${{ matrix.PYTHON.VERSION }} ${{ matrix.WINDOWS.WINDOWS }}"
steps:
- name: Get build-requirements.txt from repository
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
Expand Down Expand Up @@ -333,11 +324,7 @@ jobs:
run: python -m pip install --require-hashes -r ${{ env.BUILD_REQUIREMENTS_PATH }}
- run: mkdir wheelhouse
- run: |
if [ -n "${{ matrix.PYTHON.ABI_VERSION }}" ]; then
PY_LIMITED_API="--config-settings=--build-option=--py-limited-api=${{ matrix.PYTHON.ABI_VERSION }} --no-build-isolation"
fi
python -m pip wheel -v cryptography*.tar.gz $PY_LIMITED_API -w dist/ && mv dist/cryptography*.whl wheelhouse/
python -m pip wheel -v cryptography*.tar.gz -w dist/ && mv dist/cryptography*.whl wheelhouse/
shell: bash
- run: pip install -f wheelhouse --no-index cryptography
- name: Print the OpenSSL we built and linked against
Expand All @@ -348,5 +335,5 @@ jobs:
- run: move wheelhouse\cryptography*.whl cryptography-wheelhouse\
- uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: "cryptography-${{ github.event.inputs.version }}-${{ matrix.WINDOWS.WINDOWS }}-${{ matrix.PYTHON.VERSION }}-${{ matrix.PYTHON.ABI_VERSION}}"
name: "cryptography-${{ github.event.inputs.version }}-${{ matrix.WINDOWS.WINDOWS }}-${{ matrix.PYTHON.VERSION }}"
path: cryptography-wheelhouse\
24 changes: 0 additions & 24 deletions MANIFEST.in

This file was deleted.

3 changes: 2 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ def flake(session: nox.Session) -> None:
# but not install us.
install(
session,
"setuptools-rust",
"maturin",
"cffi>=1.12; platform_python_implementation != 'PyPy'",
"setuptools",
"wheel",
"ruff",
"check-sdist",
Expand Down
60 changes: 41 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[build-system]
# These requirements must be kept sync with the requirements on ./github/requirements/build-requirements files
requires = [
# First version of setuptools to support pyproject.toml configuration
"setuptools>=61.0.0",
"wheel",
"maturin>=1,<2",

# Must be kept in sync with `project.dependencies`
"cffi>=1.12; platform_python_implementation != 'PyPy'",
"setuptools-rust>=1.7.0",
# Needed because cffi imports distutils, and in Python 3.12, distutils has
# been removed from the stdlib, but installing setuptools puts it back.
"setuptools",
]
build-backend = "setuptools.build_meta"
build-backend = "maturin"

[project]
name = "cryptography"
Expand Down Expand Up @@ -56,14 +57,6 @@ source = "https://github.com/pyca/cryptography/"
issues = "https://github.com/pyca/cryptography/issues"
changelog = "https://cryptography.io/en/latest/changelog/"

[tool.setuptools]
zip-safe = false
package-dir = {"" = "src"}

[tool.setuptools.packages.find]
where = ["src"]
include = ["cryptography*"]

[project.optional-dependencies]
ssh = ["bcrypt >=3.1.5"]

Expand All @@ -83,12 +76,41 @@ sdist = ["build"]
# `click` included because its needed to type check `release.py`
pep8test = ["ruff", "mypy", "check-sdist", "click"]

[[tool.setuptools-rust.ext-modules]]
target = "cryptography.hazmat.bindings._rust"
path = "src/rust/Cargo.toml"
py-limited-api = true
rust-version = ">=1.63.0"

[tool.maturin]
python-source = "src"
python-packages = ["cryptography"]
manifest-path = "src/rust/Cargo.toml"
module-name = "cryptography.hazmat.bindings._rust"
locked = true
sdist-generator = "git"
include = [
"CHANGELOG.rst",
"CONTRIBUTING.rst",
"LICENSE",
"LICENSE.APACHE",
"LICENSE.BSD",

"docs/**/*",

"src/_cffi_src/**/*.py",
"src/_cffi_src/**/*.c",
"src/_cffi_src/**/*.h",

"src/rust/**/Cargo.toml",
"src/rust/**/Cargo.lock",
"src/rust/**/*.rs",

"tests/**/*.py",
]
exclude = [
"vectors/**/*",
"src/rust/target/**/*",
"docs/_build/**/*",
".github/**/*",
".readthedocs.yml",
"ci-constraints-requirements.txt",
"mypy.ini",
]

[tool.pytest.ini_options]
addopts = "-r s --capture=no --strict-markers --benchmark-disable"
Expand Down

0 comments on commit 53c5651

Please sign in to comment.