conda-forge / opencv-feedstock

A conda-smithy repository for opencv.
BSD 3-Clause "New" or "Revised" License
64 stars 59 forks source link

Make `libopencv` independent of python version #364

Open h-vetinari opened 1 year ago

h-vetinari commented 1 year ago

Looking at the content of libopencv, it's essentially completely free of python, with the sole exception of:

lib/python3.<x>/site-packages/cv2.<abi-tag>.so

It should be possible to build libopencv once, then base the various python builds on top of that (which would then contain the stuff in $SP_DIR like the above cv2.<abi-tag>.so). This would also have the benefit of dividing our build matrix by ~6, as we're now looking at 136(!!!) jobs in #363.

We could also split off the binaries under some output-name. This is getting to be the "gold standard" as far as I understood the various discussions around this (can provide references if desired) and is being used in a few feedstocks (that do lib+bins[+py]) like thrift-cpp, sentencepiece, and probably a bunch more that I'm not familiar with.

traversaro commented 1 year ago

Fortunatly it seems that there is support for building the python bindings on their own, see https://github.com/opencv/opencv/blob/af03e000c7efc29544d964c4601f0269c2c8950b/modules/python/CMakeLists.txt#L38 , so hopefully this does not require a lot of changes at the CMake level.

hmaarrfk commented 1 year ago

At the time of writing the recipe, it was pretty hard with conda machinery to make the recipe reuse a certain portion of itself.

For more historical details, see the comment in the recipe.

Improvements are always welcome!

Personally, i think it might be a good way to reduce the build matrix.

h-vetinari commented 1 year ago

I've started on a branch, but looking at the logic Silvio linked, the standalone builds really want to find a file we're not currently shipping, and building that file with the libopencv looks like it might be persisting a bit more than I'd like, aside from the also annoying issue that then the python-less lib still needs a python to build. Haven't followed this thread to its conclusion yet.

h-vetinari commented 1 year ago

It might be easiest to patch that file a bit so the bindings get built with python itself. That would IMO be a much saner model than (how I currently understand) standalone.cmake, which also hasn't been touched in ~4 years.