-
Notifications
You must be signed in to change notification settings - Fork 48
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
Question installing cmake-built shared library to fixed destination in editable mode #374
Comments
In spglib, I simply install directly to the relative path, and they I just setup
Iirc, Hope the tips help. PS: can you link me to the project? I am looking for some inspiration for C++ python binding that has proper usage of classes and std library. |
Hey @LecrisUT thanks for the suggestions, I took a look but no immediate luck, I'll try some of them again tomorrow. Maybe I'm doing something non-standard because I'm not building a binding interface like you are in _spglib.c. The two projects I'm trying to migrate to scikit-build-core are llama-cpp-python (currenty scikit-build with a setup.py file) and ggml-python (scikit-build-core with a workaround that copies shared libary to both valid locations). In both projects trying to build a shared library in a git submodule where submodule already has a build target I can reference from the CMakeLists file. I have interfaces written using ctypes so I don't need any seperate C / C++ source files in my own projects. |
Ok, I kinda get the gist of what you do there with llama-cpp-python. That one is similar to how I load the spglib C library. I see that you are installing to the llama_cpp package folder, so you can try with an empty Edit: I should mention this, in editable mode, sk-core does install the libraries in a fixed location, but it makes redirection calls for python binding libraries that redirects calls to After you install in editable mode, there is a file related to the name of the package installed that tells where everyty is redirected, including the installed cpp libraries. |
I hope you don't mind me commenting, but after some thought I think it's dangerous to use a direct call to import the libraries and directly call and assume the structure of the cpp library. Mostly because there is only linking to the file name and it is not linked to the library version. When the libraries are linked between each other, the soname, version etc. are baked in the linkage (not sure how to do version specific linkage in cmake though). If you are using a python binding module file, then you are guaranteed to:
|
The downside to making a normal module instead is that then you have to build one wheel per python version, while the ctypes version doesn't care about what Python version you are using. Does your method (loading the so directly) work when run through auditwheel? I'm guessing it doesn't mangle the names of the shared SO, and instead you'd just not be able to bundle your lib into two different wheels? In general, you should never rely on the file layout. Python happens to default to laying out things on a file system, but it's not required. It could be inside a zip file. I've even seen people use a database instead of a real filesystem (common in banking, IIRC). Instead, you should always use |
Do you have a PR or branch with your attempt that mostly works except for editable mode on one of the projects? (whichever one is simpler :) ) |
@abetlen, here is a snippet from
Notice how But the the question is how do you use Also this use-case will be nice to add as an example @henryiii once all the nuances are understood. |
Ah, we might not support |
I aggree that the current solution is probably brittle and having the additional resolution logic included in Currently the libraries I'm linking against (llama.cpp and ggml) don't have stable releases / APIs so it doesn't make sense really to search The ggml-python main branch has my best attempt at migrating to |
That would be
Indeed that seems like a reasonable implementation that you had there. Hopefully my |
Yes, if you are not using the one binary for all Pythons feature, I'd probably go for something like swig, pybind11, or nanobind. Though I'll try to work on making |
@henryiii I appreciate it, for now I'll keep my ctypes approach with the workaround of copying the shared library to both locations but I have moved over to using I've also started experimenting with swig (early) and I'll give pybind11 / nanobind a try as well. |
(privateGPT) C:\Users\AJAY\Desktop\PrivateGpt>$env:CMAKE_ARGS = "-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS" (privateGPT) C:\Users\AJAY\Desktop\PrivateGpt>pip install llama-cpp-python × Building wheel for llama-cpp-python (pyproject.toml) did not run successfully.
note: This error originates from a subprocess, and is likely not a problem with pip. |
Hi there, first of all thank you for all the amazing work.
I'm currently maintaining some python projects that bind to c++ code in a shared library via the python ctypes module. I have been using scikit-build with a setup.py file to build the c++ shared library and then place it relative to the python source files where the package can find it during import.
I've been working on migrating from scikit-build to scikit-build-core and have been able to get the project installing correctly by setting the output destination of the shared library file relative to
${SKBUILD_PLATLIB_DIR}
. However when the package is installed in editable mode such as during development this does not copy to shared library file to the same location relative to the python files.Is it possible to detect in cmake when the project is built in editable mode and change the output destination accordingly? Alternatively, is there some better way for me to place and find this shared library file that I'm completely missing (tried importlib.resources but no luck)?
The text was updated successfully, but these errors were encountered: