Skip to content

Remove cfg-if dependency. #5110

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

Merged
merged 2 commits into from
May 4, 2025
Merged

Remove cfg-if dependency. #5110

merged 2 commits into from
May 4, 2025

Conversation

m-ou-se
Copy link
Contributor

@m-ou-se m-ou-se commented May 4, 2025

This removes the cfg-if dependency.

It was only used in one place with a single if-else, which can easily be replaced.

Before:

cfg_if::cfg_if! {
    if #[cfg(..)] {
        ..
    } else {
        ..
    }
}

After:

#[cfg(..)]
{
    ..
}
#[cfg(not(..))]
{
    ..
}

@m-ou-se
Copy link
Contributor Author

m-ou-se commented May 4, 2025

This reduces the number of dependencies of a no-default-features build from 8 to 7:

  1. libc
  2. memoffset
  3. autocfg
  4. once_cell
  5. pyo3-ffi
  6. pyo3-build-config
  7. target-lexicon

@m-ou-se
Copy link
Contributor Author

m-ou-se commented May 4, 2025

If PyO3 ever bumps its MSRV to 1.70, once_cell can be removed in favor of std::sync::{OnceLock, LazyLock}.

Similarly, if PyO3 ever bumps its MSRV to 1.77, memoffset (and therefore autocfg) can be removed in favor of std::mem::offset_of.

At which point the base pyo3 build will only have 4 dependencies. :)

@LilyAcorn LilyAcorn added this pull request to the merge queue May 4, 2025
@davidhewitt
Copy link
Member

Thanks, yep always keen to minimize dependencies here! I had been meaning to drop that cfg_if code for a while but never quite got around to it 😅

@m-ou-se
Copy link
Contributor Author

m-ou-se commented May 4, 2025

always keen to minimize dependencies here!

Fwiw, if you want to go even further, you could maybe also consider getting rid of libc. In pyo3 it is mainly used for size_t, ssize_t, intptr_t and uintptr_t, but those are just usize and isize on all platforms. wchar_t is a bit annoying, but the only real problem might be libc::FILE. There might be some workaround for that.

Probably not worth it though. :)

Merged via the queue into PyO3:main with commit 91b3825 May 4, 2025
44 of 45 checks passed
@m-ou-se m-ou-se deleted the bye-cfg-if branch May 4, 2025 18:44
@davidhewitt
Copy link
Member

always keen to minimize dependencies here!

Fwiw, if you want to go even further, you could maybe also consider getting rid of libc. In pyo3 it is mainly used for size_t, ssize_t, intptr_t and uintptr_t, but those are just usize and isize on all platforms. wchar_t is a bit annoying, but the only real problem might be libc::FILE. There might be some workaround for that.

Probably not worth it though. :)

Agreed, I had considered similar but it seems fine to keep it and let libc get those core definitions right on all platforms!

@alex
Copy link
Contributor

alex commented May 4, 2025

Of course, if std/core were to get these types, we could use those :-)

@m-ou-se
Copy link
Contributor Author

m-ou-se commented May 4, 2025

The size and intptr types, sure, that seems likely to happen. Not sure about wchar_t.. maybe. FILE, however, seems unlikely.

@alex
Copy link
Contributor

alex commented May 4, 2025

Perhaps if the integer types were in std we could just drop the FILE-using functions, I wonder if anyone uses them. (They basically all have some alternatives.)

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.

4 participants