-
Notifications
You must be signed in to change notification settings - Fork 677
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
Automatically call CMake as part of PEP 517 build #1512
base: main
Are you sure you want to change the base?
Conversation
Call CMake and build the CPU extension when invoking the build via a PEP 517 backend, to ensure that at least some extension is built when users are building from source. This improves consistency with other Python packages, and reduces the risk of accidents. We are using `scikit-build-core` setuptools plugin to take care of CMake dependencies and call into CMake. However, we need to modify the `build_py` command to ensure that CMake is called prior to the setuptools command, as otherwise the newly built shared library won't be picked up by `build_py`. Since setuptools is still responsible for collecting the Python package, it also collects all other shared libraries that were built earlier, for example via manual CMake calls as done in the CI pipeline. Furthermore, if the user does not have `scikit-build-core` installed and calls `setup.py` directly, we output a warning but continue working as before. The logic can be further extended in the future, for example to detect the best COMPUTE_BACKEND default. Fixes bitsandbytes-foundation#1511
|
||
setup(version="0.45.3.dev0", | ||
packages=find_packages(), | ||
distclass=BinaryDistribution, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, this is no longer necessary when CMake is called. However, since I preserved the support for using setup.py
without scikit-build-core
installed, I've left this hack in.
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Thanks! I do have a few questions, as I'm not familiar with
|
To be honest, I'm not very fluent with it either, and we aren't exactly using it in the most standard way here either (to allow for the current behavior of placing the shared library directly in source directory). In general, since the "base" here is
Yes.
Since it's all handled via |
Hmm, I have a slightly different idea. The current approach of writing straight into source directory is a bit hacky. I think a cleaner and more future-proof way would be to convert into |
First of all, thank you for your proactive approach with this PR. I agree that it makes sense to add this and it's very nice to have community members with a hands-on approach take the initiative. As we're currently trying to streamline things a bit in our repo, just wondering what's the plan for this PR? Are there any unresolved issues that need our input? Is it clear which open steps we have? If we do, could those be added as a task list on the PR? |
@Titus-von-Koeller, I'm sorry but I'm not sure if I understand your question. Right now, I think we're at the point of discussing a solution. This PR provides a "minimal change" solution to the problem at hand — however, as I noted above, it's a bit hacky still. Alternatively, I could explore more significant changes to the build system, that would streamline the build process into a typical PEP517 scikit-build-core package, that builds and installs a single variant — and then build an additional "CI support" workflow that would allow combining different variants on top of that. I think the end result would be the same, but the changes to code would be more significant. Notably, different libraries would not be picked implicitly by setuptools anymore, but would be pulled explicitly via CMake. That said, I'm not 100% sure if it'll work but that's my risk. So I'm open to proceeding either way, just would like to know what you think. I've just pushed a fix to this approach, by the way, that should hopefully resolve the CI failures. |
Call CMake and build the CPU extension when invoking the build via a PEP 517 backend, to ensure that at least some extension is built when users are building from source. This improves consistency with other Python packages, and reduces the risk of accidents.
We are using
scikit-build-core
setuptools plugin to take care of CMake dependencies and call into CMake. However, we need to modify thebuild_py
command to ensure that CMake is called prior to the setuptools command, as otherwise the newly built shared library won't be picked up bybuild_py
.Since setuptools is still responsible for collecting the Python package, it also collects all other shared libraries that were built earlier, for example via manual CMake calls as done in the CI pipeline. Furthermore, if the user does not have
scikit-build-core
installed and callssetup.py
directly, we output a warning but continue working as before.The logic can be further extended in the future, for example to detect the best COMPUTE_BACKEND default.
Fixes #1511