tttapa / py-build-cmake

Modern, PEP 517 compliant build backend for creating Python packages with extensions built using CMake.
https://pypi.org/project/py-build-cmake
MIT License
38 stars 6 forks source link

On v0.2.0 rework branch: -A platform option passed to CMake for generators that don't support it #21

Closed SanderVocke closed 7 months ago

SanderVocke commented 7 months ago

Noticed this trying to run a Ninja-based build on Windows with py-build-cmake.

py-build-cmake passes the -A x64 flag to cmake on Windows. This will lead to an error if using Ninja (or most other non-MSVC builders).

I found in the code that this happens in get_cmake_generator_platform. It seems indeed to be based on the OS and not on the generator.

According to the CMake docs (https://cmake.org/cmake/help/latest/variable/CMAKE_GENERATOR_PLATFORM.html), only Visual Studio generators and "Green Hills MULTI" generators support the -A flag.

Could another check be added to ensure the -A is only passed when using a VS generator?

tttapa commented 7 months ago

Thanks for the report!

I've added a check in 2fba7c5404cc0cf2a68914b780ae52b404aafd32.

You can try it out using the following in your pyproject.toml:

[build-system]
requires = [
    "py-build-cmake@git+https://github.com/tttapa/py-build-cmake@2fba7c5404cc0cf2a68914b780ae52b404aafd32",
]
build-backend = "py_build_cmake.build"
SanderVocke commented 7 months ago

Seems to work like a charm, thanks for the lightning-fast fix!