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

cmake config and args sections (and maybe more) in py-build-cmake.local.toml does not seem to apply #27

Open oyvindln opened 3 weeks ago

oyvindln commented 3 weeks ago

I'm trying to set up a project to build a binary with py-build-cmake and need to pass some options via a config file depending on system but anything I add to args and config in the py-build-cmake.local.toml do not seem to have any effect. If I change source_path it does however so the config is clearly being parsed. It works fine if I put the same options in pyproject.toml. Same happens on both ubuntu 24.04 and windows 10 with python 3.12. I couldn't figure out if there was a way to load a different config file when running py -m build and running py-build-cmake manually just fails with Error: /home/___/___/___/minimal-program/.py-build-cmake_cache/cp312-cp312-linux_x86_64 is not a directory (or doesn't do anything meaningful and just skips the build process if there is an existing build already)

Not sure if it's in any way related but the build env also complains about /tmp/build-env-z_d23dbe/lib/python3.12/site-packages/py_build_cmake/config_options.py:510: SyntaxWarning: invalid escape sequence '\|'

oyvindln commented 3 weeks ago

Ok so it does work when running py -m pip install ., just not with py -m build for some reason

tttapa commented 3 weeks ago

I'll have a more detailed look later, but I suspect that the issue is that PyPA build first creates an sdist. Then it extracts all source code from the sdist in a separate environment, and then does the main build. By default, your local config file is not included in the sdist, so it will not be considered when PyPA build builds the main wheel from the sdist.

I don't think automatically including these config files in the sdist is a good idea (they're meant to be local, after all), but py-build-cmake should at least warn about this, though.

To skip the sdist step, you can use py -m build -w. Alternatively, use the command-line overrides instead of local overrides, these should work even when going through an sdist first: https://tttapa.github.io/py-build-cmake/Config.html#command-line-overrides

oyvindln commented 3 weeks ago

That would make sense.

Ultimately the goal here is to deal with a library dependency for the binary bundled in the wheel on different platforms and on e.g windows there is a need to confige paths for that.

tttapa commented 3 weeks ago

on windows ends with a failure to find the file in the temporary build directory

The problem here is that PyPA build changes the current working directory to its own temporary build directory. So by the time py-build-cmake receives --local argument, it no longer knows which folder you were in. On Linux, I have a workaround, I'll have a look if I can do something similar on Windows. Absolute paths should always work, though.

Ultimately the goal here is to deal with a library dependency for the binary bundled in the wheel on different platforms and on e.g windows there is a need to confige paths for that.

In an ideal world, you'd use a package manager like Conan or vcpkg for this purpose. You could also add a CMake Find module to your project, but that's usually more work to maintain.

oyvindln commented 3 weeks ago

Yeah the reason I was trying to pass in a config in the first place was specify the vcpkg toolchain location and tell vcpkg to use the static triplet instead of the default one to avoid having to deal with dlls. In any case I can still put that in the cmake file for now.