Skip to content
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

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

Open
oyvindln opened this issue Jun 4, 2024 · 5 comments

Comments

@oyvindln
Copy link

oyvindln commented Jun 4, 2024

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
Copy link
Author

oyvindln commented Jun 4, 2024

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

@tttapa
Copy link
Owner

tttapa commented Jun 4, 2024

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
Copy link
Author

oyvindln commented Jun 4, 2024

That would make sense.

  • using py -m build -w works, python -m build -C--local=py-build-cmake.local.toml works on linux - on windows ends with a failure to find the file in the temporary build directory unless I put in the whole absolute path to the file as the argument (also have to quote the filename otherwise I get a unregocnized arguments: .local.toml error but that may be something to do with powershell rather than python or py-build-cmake )

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
Copy link
Owner

tttapa commented Jun 4, 2024

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
Copy link
Author

oyvindln commented Jun 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants