scikit-build-core
scikit-build-core copied to clipboard
Building with MinGW on Windows fails
Installing e.g. the pybind11 example https://github.com/pybind/scikit_build_example with only MinGW (GCC) installed on Windows fails with a cryptic error message:
× Building wheel for scikit_build_example (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [23 lines of output]
2024-09-14 09:09:38,528 - scikit_build_core - INFO - RUN: C:\Program Files\CMake\bin\cmake.EXE -E capabilities
2024-09-14 09:09:38,544 - scikit_build_core - INFO - CMake version: 3.29.2
*** scikit-build-core 0.10.6 using CMake 3.29.2 (wheel)
2024-09-14 09:09:38,557 - scikit_build_core - INFO - Build directory: C:\Users\Thore\AppData\Local\Temp\tmpcpenilot\build
*** Configuring CMake...
2024-09-14 09:09:38,634 - scikit_build_core - WARNING - Can't find a Python library, got libdir=None, ldlibrary=None, multiarch=None, masd=None
2024-09-14 09:09:38,643 - scikit_build_core - INFO - RUN: C:\Program Files\CMake\bin\cmake.EXE -S. -BC:\Users\Thore\AppData\Local\Temp\tmpcpenilot\build -CC:\Users\Thore\AppData\Local\Temp\tmpcpenilot\build\CMakeInit.txt -DCMAKE_INSTALL_PREFIX=C:\Users\Thore\AppData\Local\Temp\tmpcpenilot\wheel\platlib
loading initial cache file C:\Users\Thore\AppData\Local\Temp\tmpcpenilot\build\CMakeInit.txt
-- Building for: NMake Makefiles
CMake Error at CMakeLists.txt:7 (project):
Running
'nmake' '-?'
failed with:
no such file or directory
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
*** CMake configuration failed
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for scikit_build_example
Failed to build scikit_build_example
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (scikit_build_example)
Building with MSVC works fine. I know that GCC is not recommended for building extensions on Windows. Thus, a descriptive error message should hint the user at this problem.
Scikit-build-core should try to build with the compiler used to compile Python. So if you used an MSVC-compiled Python, you'll likely see the above. If you used a Python built with MinGW, it should work out of the box.
Though I think the actual problem here is CMake can't find MSVC, so it's falling back on NMake as a default generator. Can you set CMAKE_GENERATOR to Ninja (for example) and try again?
If you used a Python built with MinGW, it should work out of the box.
We test this, actually:
https://github.com/scikit-build/scikit-build-core/blob/ca529d62164989c59b5740a39f6f19667dffc93b/.github/workflows/ci.yml#L294
Though MSVC might still be detectable, so maybe we should make sure it's not used.
Scikit-build-core should try to build with the compiler used to compile Python. So if you used an MSVC-compiled Python, you'll likely see the above. If you used a Python built with MinGW, it should work out of the box.
Though I think the actual problem here is CMake can't find MSVC, so it's falling back on NMake as a default generator. Can you set CMAKE_GENERATOR to Ninja (for example) and try again?
That's good to know. It can't find MSVC, because it was not installed on that machine. I've encountered this problem when using a pre-compiled Python for Windows (Which are compiled with MSVC, I presume) with a machine with only GCC available.
Can scikit-build-core detect this? For me it's no problem to install MSVC, but it took 2 hours with a colleague to find the culprit (Missing MSVC on his machine).
Actually, sk-build is able to identify such a situation:
2024-09-14 09:09:38,634 - scikit_build_core - WARNING - Can't find a Python library, got libdir=None, ldlibrary=None, multiarch=None, masd=None
Maybe make it more verbose and hint on this error?
Actually, sk-build is able to identify such a situation:
2024-09-14 09:09:38,634 - scikit_build_core - WARNING - Can't find a Python library, got libdir=None, ldlibrary=None, multiarch=None, masd=None
Maybe make it more verbose and hint on this error?
Unfortunately that may not be desired. There are projects made in skbuild-core without python bindings like cmake or ninja. Maybe there could be a find_python like option that would control finding python-devel files and error if it couldn't.
I've encountered this problem when using a pre-compiled Python for Windows (Which are compiled with MSVC, I presume) with a machine with only GCC available.
Can scikit-build-core detect this?
Interesting idea, I think there could be a design for that if skbuild-core has a find_package(scikit-build-core) I'll open an issue for that.
The problem I see here is, that the build process hints at the CMakeLists.txt file as the source of error, whereas the different compilers for Python and the bindings are the problem.
If you used a Python built with MinGW, it should work out of the box.
Does anyone have recommendations for how to go about getting a version of Python built with MinGW on a GitHub actions runner? The codebase I'm working with uses VLAs, and the MSVC compiler does not support this, so I'm attempting to get cibuildwheel to run with MinGW. But I also seem to be having trouble with it finding the Python library. Thanks!