Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump msrv to 1.56 #3208

Merged
merged 3 commits into from Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions .cargo/config
Expand Up @@ -3,10 +3,6 @@ xtask = "run --package xtask --"

[target.'cfg(feature = "cargo-clippy")']
rustflags = [
# TODO: remove these allows once msrv increased from 1.48
"-Aclippy::iter_kv_map",
"-Aclippy::needless_borrow",
"-Aclippy::uninlined_format_args",
# Lints to enforce in CI
"-Dclippy::checked_conversions",
"-Dclippy::dbg_macro",
Expand All @@ -15,7 +11,6 @@ rustflags = [
"-Dclippy::filter_map_next",
"-Dclippy::flat_map_option",
"-Dclippy::let_unit_value",
"-Dclippy::manual_assert",
"-Dclippy::manual_ok_or",
"-Dclippy::todo",
"-Dclippy::unnecessary_wraps",
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/build.yml
Expand Up @@ -201,7 +201,3 @@ jobs:
# TODO: this is a hack to workaround compile_error! warnings about auto-initialize on PyPy
# Once cargo's `resolver = "2"` is stable (~ MSRV Rust 1.52), remove this.
PYO3_CI: 1
# This is a hack to make CARGO_PRIMARY_PACKAGE always set even for the
# msrv job. MSRV is currently 1.48, but CARGO_PRIMARY_PACKAGE only came in
# 1.49.
CARGO_PRIMARY_PACKAGE: 1
42 changes: 28 additions & 14 deletions .github/workflows/ci.yml
Expand Up @@ -34,6 +34,32 @@ jobs:
- name: Check rust formatting (rustfmt)
run: nox -s fmt-rust

check-msrv:
needs: [fmt]
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.56.0
targets: x86_64-unknown-linux-gnu
components: clippy,rust-src
adamreichold marked this conversation as resolved.
Show resolved Hide resolved
- uses: actions/setup-python@v4
with:
architecture: "x64"
- uses: Swatinem/rust-cache@v2
with:
key: check-msrv-1.56.0
continue-on-error: true
- run: python -m pip install --upgrade pip && pip install nox
- name: Prepare minimal package versions
run: nox -s set-minimal-package-versions
- run: nox -s check-all

env:
CARGO_BUILD_TARGET: x86_64-unknown-linux-gnu

clippy:
needs: [fmt]
runs-on: ${{ matrix.platform.os }}
Expand Down Expand Up @@ -80,16 +106,6 @@ jobs:
rust-target: "i686-pc-windows-msvc",
},
]
include:
- rust: 1.48.0
python-version: "3.11"
platform:
{
os: "ubuntu-latest",
python-architecture: "x64",
rust-target: "x86_64-unknown-linux-gnu",
}
msrv: "MSRV"
name: clippy/${{ matrix.platform.rust-target }}/${{ matrix.rust }}
steps:
- uses: actions/checkout@v3
Expand All @@ -106,9 +122,6 @@ jobs:
key: clippy-${{ matrix.platform.rust-target }}-${{ matrix.platform.os }}-${{ matrix.rust }}
continue-on-error: true
- run: python -m pip install --upgrade pip && pip install nox
- if: matrix.msrv == 'MSRV'
name: Prepare minimal package versions (MSRV only)
run: nox -s set-minimal-package-versions
- run: nox -s clippy-all
env:
CARGO_BUILD_TARGET: ${{ matrix.platform.rust-target }}
Expand Down Expand Up @@ -207,7 +220,7 @@ jobs:
]
include:
# Test minimal supported Rust version
- rust: 1.48.0
- rust: 1.56.0
python-version: "3.11"
platform:
{
Expand Down Expand Up @@ -353,6 +366,7 @@ jobs:
conclusion:
needs:
- fmt
- check-msrv
- clippy
- build-pr
- build-full
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -12,6 +12,7 @@ categories = ["api-bindings", "development-tools::ffi"]
license = "Apache-2.0"
exclude = ["/.gitignore", ".cargo/config", "/codecov.yml", "/Makefile", "/pyproject.toml", "/noxfile.py", "/.github", "/tests/test_compile_error.rs", "/tests/ui"]
edition = "2018"
rust-version = "1.56"

[dependencies]
cfg-if = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -4,7 +4,7 @@
[![benchmark](https://github.com/PyO3/pyo3/actions/workflows/bench.yml/badge.svg)](https://pyo3.rs/dev/bench/)
[![codecov](https://codecov.io/gh/PyO3/pyo3/branch/main/graph/badge.svg)](https://codecov.io/gh/PyO3/pyo3)
[![crates.io](https://img.shields.io/crates/v/pyo3)](https://crates.io/crates/pyo3)
[![minimum rustc 1.48](https://img.shields.io/badge/rustc-1.48+-blue.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
[![minimum rustc 1.56](https://img.shields.io/badge/rustc-1.56+-blue.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
[![dev chat](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/PyO3/Lobby)
[![contributing notes](https://img.shields.io/badge/contribute-on%20github-Green)](https://github.com/PyO3/pyo3/blob/main/Contributing.md)

Expand All @@ -18,7 +18,7 @@

PyO3 supports the following software versions:
- Python 3.7 and up (CPython and PyPy)
- Rust 1.48 and up
- Rust 1.56 and up

You can use PyO3 to write a native Python module in Rust, or to embed Python in a Rust binary. The following sections explain each of these in turn.

Expand Down
2 changes: 0 additions & 2 deletions examples/plugin/plugin_api/pyproject.toml
Expand Up @@ -10,5 +10,3 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]


2 changes: 1 addition & 1 deletion guide/src/getting_started.md
Expand Up @@ -4,7 +4,7 @@ To get started using PyO3 you will need three things: a Rust toolchain, a Python

## Rust

First, make sure you have Rust installed on your system. If you haven't already done so, try following the instructions [here](https://www.rust-lang.org/tools/install). PyO3 runs on both the `stable` and `nightly` versions so you can choose whichever one fits you best. The minimum required Rust version is 1.48.
First, make sure you have Rust installed on your system. If you haven't already done so, try following the instructions [here](https://www.rust-lang.org/tools/install). PyO3 runs on both the `stable` and `nightly` versions so you can choose whichever one fits you best. The minimum required Rust version is 1.56.

If you can run `rustc --version` and the version is new enough you're good to go!

Expand Down
6 changes: 6 additions & 0 deletions guide/src/migration.md
Expand Up @@ -3,6 +3,12 @@
This guide can help you upgrade code through breaking changes from one PyO3 version to the next.
For a detailed list of all changes, see the [CHANGELOG](changelog.md).

## from 0.19.* to 0.20

### Drop support for older technologies

PyO3 0.20 has increased minimum Rust version to 1.56. This enables use of newer language features and simplifies maintenance of the project.

## from 0.18.* to 0.19

### Access to `Python` inside `__traverse__` implementations are now forbidden
Expand Down
1 change: 1 addition & 0 deletions newsfragments/3208.packaging.md
@@ -0,0 +1 @@
Update MSRV to Rust 1.56.
139 changes: 73 additions & 66 deletions noxfile.py
Expand Up @@ -8,7 +8,7 @@
from functools import lru_cache
from glob import glob
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple
from typing import Any, Callable, Dict, List, Optional, Tuple

import nox

Expand Down Expand Up @@ -96,25 +96,19 @@ def _clippy(session: nox.Session, *, env: Dict[str, str] = None) -> bool:
success = True
env = env or os.environ
for feature_set in _get_feature_sets():
command = "clippy"
extra = ("--", "--deny=warnings")
if _get_rust_version()[:2] == (1, 48):
# 1.48 crashes during clippy because of lints requested
# in .cargo/config
command = "check"
extra = ()
try:
_run(
session,
"cargo",
command,
"clippy",
*feature_set,
"--all-targets",
"--workspace",
# linting pyo3-ffi-check requires docs to have been built or
# the macros will error; doesn't seem worth it on CI
"--exclude=pyo3-ffi-check",
*extra,
"--",
"--deny=warnings",
external=True,
env=env,
)
Expand All @@ -126,31 +120,43 @@ def _clippy(session: nox.Session, *, env: Dict[str, str] = None) -> bool:
@nox.session(name="clippy-all", venv_backend="none")
def clippy_all(session: nox.Session) -> None:
success = True
with tempfile.NamedTemporaryFile("r+") as config:
env = os.environ.copy()
env["PYO3_CONFIG_FILE"] = config.name
env["PYO3_CI"] = "1"

def _clippy_with_config(implementation, version) -> bool:
config.seek(0)
config.truncate(0)
config.write(
f"""\
implementation={implementation}
version={version}
suppress_build_script_link_lines=true
"""
)
config.flush()
def _clippy_with_config(env: Dict[str, str]) -> None:
nonlocal success
success &= _clippy(session, env=env)

session.log(f"{implementation} {version}")
return _clippy(session, env=env)
_for_all_version_configs(session, _clippy_with_config)

for version in PY_VERSIONS:
success &= _clippy_with_config("CPython", version)
if not success:
session.error("one or more jobs failed")

for version in PYPY_VERSIONS:
success &= _clippy_with_config("PyPy", version)

@nox.session(name="check-all", venv_backend="none")
def check_all(session: nox.Session) -> None:
success = True

def _check(env: Dict[str, str]) -> None:
nonlocal success
env = env or os.environ
for feature_set in _get_feature_sets():
try:
_run(
session,
"cargo",
"check",
*feature_set,
"--all-targets",
"--workspace",
# linting pyo3-ffi-check requires docs to have been built or
# the macros will error; doesn't seem worth it on CI
"--exclude=pyo3-ffi-check",
external=True,
env=env,
)
except Exception:
success = False

_for_all_version_configs(session, _check)

if not success:
session.error("one or more jobs failed")
Expand Down Expand Up @@ -422,42 +428,13 @@ def set_minimal_package_versions(session: nox.Session):
"examples/word-count",
)
min_pkg_versions = {
# newer versions of rust_decimal want newer arrayvec
"rust_decimal": "1.18.0",
# newer versions of arrayvec use const generics (Rust 1.51+)
"arrayvec": "0.5.2",
"rust_decimal": "1.26.1",
"csv": "1.1.6",
# newer versions of chrono use i32::rem_euclid as a const fn
"chrono": "0.4.24",
"indexmap": "1.6.2",
"inventory": "0.3.4",
"hashbrown": "0.9.1",
"plotters": "0.3.1",
"plotters-svg": "0.3.1",
"plotters-backend": "0.3.2",
"bumpalo": "3.10.0",
"once_cell": "1.14.0",
"rayon": "1.5.3",
"rayon-core": "1.9.3",
"hashbrown": "0.12.3",
"once_cell": "1.17.2",
"rayon": "1.6.1",
"rayon-core": "1.10.2",
"regex": "1.7.3",
# string_cache 0.8.4 depends on parking_lot 0.12
"string_cache": "0.8.3",
# 1.15.0 depends on hermit-abi 0.2.6 which has edition 2021 and breaks 1.48.0
"num_cpus": "1.14.0",
"parking_lot": "0.11.0",
# 1.0.77 needs basic-toml which has edition 2021
"trybuild": "1.0.76",
# pins to avoid syn 2.0 (which requires Rust 1.56)
"ghost": "0.1.8",
"serde": "1.0.156",
"serde_derive": "1.0.156",
"cxx": "1.0.92",
"cxxbridge-macro": "1.0.92",
"cxx-build": "1.0.92",
"web-sys": "0.3.61",
"js-sys": "0.3.61",
"wasm-bindgen": "0.2.84",
"syn": "1.0.109",
}

# run cargo update first to ensure that everything is at highest
Expand Down Expand Up @@ -634,11 +611,41 @@ def _run_cargo_set_package_version(
*,
project: Optional[str] = None,
) -> None:
command = ["cargo", "update", "-p", pkg_id, "--precise", version]
command = ["cargo", "update", "-p", pkg_id, "--precise", version, "--workspace"]
if project:
command.append(f"--manifest-path={project}/Cargo.toml")
_run(session, *command, external=True)


def _get_output(*args: str) -> str:
return subprocess.run(args, capture_output=True, text=True, check=True).stdout


def _for_all_version_configs(
session: nox.Session, job: Callable[[Dict[str, str]], None]
) -> None:
with tempfile.NamedTemporaryFile("r+") as config:
env = os.environ.copy()
env["PYO3_CONFIG_FILE"] = config.name
env["PYO3_CI"] = "1"

def _job_with_config(implementation, version) -> bool:
config.seek(0)
config.truncate(0)
config.write(
f"""\
implementation={implementation}
version={version}
suppress_build_script_link_lines=true
"""
)
config.flush()

session.log(f"{implementation} {version}")
return job(env)

for version in PY_VERSIONS:
_job_with_config("CPython", version)

for version in PYPY_VERSIONS:
_job_with_config("PyPy", version)
5 changes: 5 additions & 0 deletions pyo3-build-config/src/lib.rs
Expand Up @@ -161,6 +161,11 @@ pub fn print_feature_cfgs() {
if rustc_minor_version >= 59 {
println!("cargo:rustc-cfg=thread_local_const_init");
}

// Enable use of `#[cfg(panic = "...")]` on Rust 1.60 and greater
if rustc_minor_version >= 60 {
println!("cargo:rustc-cfg=panic_unwind");
}
}

/// Private exports used in PyO3's build.rs
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/README.md
Expand Up @@ -14,7 +14,7 @@ Manual][capi] for up-to-date documentation.

PyO3 supports the following software versions:
- Python 3.7 and up (CPython and PyPy)
- Rust 1.48 and up
- Rust 1.56 and up

# Example: Building Python Native modules

Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/lib.rs
Expand Up @@ -51,7 +51,7 @@
//!
//! PyO3 supports the following software versions:
//! - Python 3.7 and up (CPython and PyPy)
//! - Rust 1.48 and up
//! - Rust 1.56 and up
//!
//! # Example: Building Python Native modules
//!
Expand Down
9 changes: 5 additions & 4 deletions pyo3-macros-backend/src/pyfunction/signature.rs
Expand Up @@ -27,10 +27,11 @@ pub struct Signature {
impl Parse for Signature {
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
let content;
Ok(Signature {
paren_token: syn::parenthesized!(content in input),
items: content.parse_terminated(SignatureItem::parse)?,
})
let paren_token = syn::parenthesized!(content in input);

let items = content.parse_terminated(SignatureItem::parse)?;

Ok(Signature { paren_token, items })
}
}

Expand Down