Skip to content

Add cmake dependency only when system cmake is not available #6642

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

Closed
wants to merge 1 commit into from

Conversation

mgorny
Copy link
Contributor

@mgorny mgorny commented Jan 16, 2025

Description

Instead of unconditionally pulling cmake PyPI package in, check whether cmake is available first and add the dependency only when it is not available. This is the same approach as used by the scikit-build-core package, and it improves portability, especially given that CMake frequently requires downstream patching to work.

Motivation and Context

Currently, having an unconditional cmake dependency means that pip or uv will install a local PyPI-packaged version of cmake to build the package. Besides being unnecessary, this can be particularly problematic, given that CMake is buggy in general and sometimes relies on downstream patching, that is carried in system CMake but not (yet) in PyPI's CMake. Ensuring that system CMake is used when available generally improves interoperability and consistency.

@mgorny mgorny requested a review from a team as a code owner January 16, 2025 19:23
Instead of unconditionally pulling `cmake` PyPI package in, check
whether `cmake` is available first and add the dependency only when
it is not available.  This is the same approach as used
by the `scikit-build-core` package, and it improves portability,
especially given that CMake frequently requires downstream patching
to work.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
@justinchuby justinchuby added the run release CIs Use this label to trigger release tests in CI label Jan 16, 2025
Copy link

codecov bot commented Jan 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 57.46%. Comparing base (8275472) to head (e288703).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6642   +/-   ##
=======================================
  Coverage   57.46%   57.46%           
=======================================
  Files         507      507           
  Lines       31584    31584           
  Branches     3046     3046           
=======================================
  Hits        18151    18151           
  Misses      12607    12607           
  Partials      826      826           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@justinchuby justinchuby left a comment

Choose a reason for hiding this comment

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

@mgorny
Copy link
Contributor Author

mgorny commented Jan 17, 2025

I've filed pypa/setuptools#4806 asking for a "better way", but I don't hold my hopes high. This is pretty much a corner case.

The alternative approach would be to create a custom PEP517 build backend that calls into setuptools and overrides get_requires_for_build_wheel(). Or switch to scikit-build-core, which is specifically focused on building projects using CMake, but that's a larger change.

@mgorny
Copy link
Contributor Author

mgorny commented Jan 17, 2025

I'm trying the alternate approach to see how hard it will end up, and will file an alternate PR with it.

Copy link
Member

@justinchuby justinchuby left a comment

Choose a reason for hiding this comment

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

Personally I think this is still easier/better than having to create a custom build backend. What do you think?

@mgorny
Copy link
Contributor Author

mgorny commented Jan 17, 2025

#6643. It's definitely more complex but not as complex as I thought. It has the extra advantage that the dependency is only added when building wheels and not when building sdists. I think the protobuf dependency could be moved there as well.

@justinchuby justinchuby added do not merge and removed run release CIs Use this label to trigger release tests in CI labels Jan 19, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jan 20, 2025
… version) (#6643)

### Description
Instead of unconditionally pulling `cmake` PyPI package in, check
whether `cmake` is available first and add the dependency only when it
is not available. This is the same approach as used by the
`scikit-build-core` package, and it improves portability, especially
given that CMake frequently requires downstream patching to work.

In this version of the patch, I've created a minimal PEP517 build
backend that inherits the functions provided by setuptools, and adds the
CMake dependency when necessary. This avoids using deprecated setuptools
`setup_requires` argument, and it avoids adding CMake dependency when
building source distributions.

### Motivation and Context
Same as #6642, except using PEP517 backend instead of deprecated
`setup_requires`.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
andife pushed a commit that referenced this pull request Jan 25, 2025
… version) (#6643)

### Description
Instead of unconditionally pulling `cmake` PyPI package in, check
whether `cmake` is available first and add the dependency only when it
is not available. This is the same approach as used by the
`scikit-build-core` package, and it improves portability, especially
given that CMake frequently requires downstream patching to work.

In this version of the patch, I've created a minimal PEP517 build
backend that inherits the functions provided by setuptools, and adds the
CMake dependency when necessary. This avoids using deprecated setuptools
`setup_requires` argument, and it avoids adding CMake dependency when
building source distributions.

### Motivation and Context
Same as #6642, except using PEP517 backend instead of deprecated
`setup_requires`.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
Signed-off-by: Andreas Fehlner <fehlner@arcor.de>
seungwoo-ji-03 pushed a commit to seungwoo-ji-03/onnx that referenced this pull request Feb 17, 2025
… version) (onnx#6643)

### Description
Instead of unconditionally pulling `cmake` PyPI package in, check
whether `cmake` is available first and add the dependency only when it
is not available. This is the same approach as used by the
`scikit-build-core` package, and it improves portability, especially
given that CMake frequently requires downstream patching to work.

In this version of the patch, I've created a minimal PEP517 build
backend that inherits the functions provided by setuptools, and adds the
CMake dependency when necessary. This avoids using deprecated setuptools
`setup_requires` argument, and it avoids adding CMake dependency when
building source distributions.

### Motivation and Context
Same as onnx#6642, except using PEP517 backend instead of deprecated
`setup_requires`.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
Signed-off-by: seungwoo-ji <seungwoo.ji@nuvilab.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants