Skip to content

Remove dependency of pyo3-macros-backend on pyo3-build-config#5809

Merged
davidhewitt merged 11 commits into
PyO3:mainfrom
davidhewitt:macros-no-config
Feb 19, 2026
Merged

Remove dependency of pyo3-macros-backend on pyo3-build-config#5809
davidhewitt merged 11 commits into
PyO3:mainfrom
davidhewitt:macros-no-config

Conversation

@davidhewitt
Copy link
Copy Markdown
Member

@davidhewitt davidhewitt commented Feb 13, 2026

Looks like this cuts a few minutes off the clippy CI jobs - see #5809 (comment)

This will also fix #4579

This changes the macros to emit the same code regardless of Python version, leaving the implementation in pyo3 to decide what to do with the code.

I suspect that this will also improve the situation for users who are experiencing rebuilds as per #1708 (by making rebuilds less expensive)

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Feb 13, 2026

Merging this PR will not alter performance

✅ 103 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing davidhewitt:macros-no-config (05e6a40) with main (c442049)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@davidhewitt
Copy link
Copy Markdown
Member Author

Nice, looks like this cut the runtimes of the clippy jobs by 2-3 minutes each, which will add up when the pipelines are busy. Seems worth pushing forward with this for multiple reasons, I'll come back to this soon and see if I can figure out how to abstract the CallingConvention choice away.

@davidhewitt davidhewitt marked this pull request as ready for review February 14, 2026 13:21
@davidhewitt davidhewitt marked this pull request as draft February 16, 2026 20:45
@davidhewitt davidhewitt changed the title WIP: try removing dependency of pyo3-macros-backend on pyo3-build-config Remove dependency of pyo3-macros-backend on pyo3-build-config Feb 18, 2026
@davidhewitt davidhewitt marked this pull request as ready for review February 18, 2026 12:39
@davidhewitt
Copy link
Copy Markdown
Member Author

This is ready for review; I'm pretty pleased with this, it seems to improve a couple of painful issues with the build system with only a small bump in complexity.

Copy link
Copy Markdown
Contributor

@Tpt Tpt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see improved compile times 🥳

Comment thread pyo3-macros-backend/src/pyclass.rs Outdated
if let Some(kw) = &attr.options.dict {
assertions.extend(quote_spanned! {
kw.span() => #[allow(dead_code)]
const _: () = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pedantic-nit: could this shorter version be enough?

                const _: () = {
                    assert!(#pyo3_path::impl_::pyclass::DICT_SUPPORTED, "{}", #pyo3_path::impl_::pyclass::DICT_UNSUPPORTED_ERROR);
                };

and maybe even wrap it in a function like:

#[track_caller]
const fn assert_dict_supported() {
    assert!(cfg!(any(not(Py_LIMITED_API), Py_3_9)),
    "`dict` requires Python >= 3.9 when using the `abi3` feature");
}

and just have

const _: () = { assert_dict_supported() };

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I did try functions but I missed the #[track_caller] attribute and without that the error messages show the function source, which I didn't like as much.

With #[track_caller], this works perfectly. Pushed, will merge 👍

Comment thread Cargo.toml
[package]
name = "pyo3"
version = "0.28.1"
version = "0.28.2"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops this is from local testing, will merge release notes merge first! 🙈

@davidhewitt davidhewitt disabled auto-merge February 19, 2026 08:20
@davidhewitt davidhewitt added this pull request to the merge queue Feb 19, 2026
Merged via the queue into PyO3:main with commit 9ad3770 Feb 19, 2026
42 of 44 checks passed
@davidhewitt davidhewitt deleted the macros-no-config branch February 19, 2026 22:30
@davidhewitt davidhewitt mentioned this pull request Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pyo3_build_config::get() broken inside our proc macro crates when cross-compiling

2 participants