opencv-rust icon indicating copy to clipboard operation
opencv-rust copied to clipboard

How to propagate `#[cfg(ocvrs_has_module_xxx)]` to user crates

Open OlivierLDff opened this issue 10 months ago • 2 comments

Hi I'm not sure if this is a general rust question, or something related specifically to this build.rs.

I see that modules are generated based on what the found opencv library what compiled with. So if let's say sfm is disabled, no function for the opencv::sfm modules will exists.

How to get access to that in my crate so I can do some fallback if the function wasn't generated on avoid build failure?

From my small understanding:

  • cfg can be defined by a build.rs, but then I would have to reimplement all of the Library::probe() logic.
  • How can I consume the library used in the build script of this repo?

An alternative would be to use features flags, but I would like to keep that as last resort.

OlivierLDff avatar Apr 26 '25 14:04 OlivierLDff

That information is unfortunately not readily available to the dependent crates in cargo. I have manually implemented some helper macros for the OpenCV branch detection, e.g. opencv_branch_4. Maybe generating those can be automated in the build script together with the similar ones for the modules.

twistedfall avatar Apr 26 '25 15:04 twistedfall

I see what you mean! I don't have time to investigate on that or work on a PR right now. For my use case right now I will just force the correct module to be here for now. But I will definitely need something like that on the future, so maybe I will put some work into it.

Thank for the quick reply!

OlivierLDff avatar Apr 26 '25 15:04 OlivierLDff

Forgot to mention this, but it was implemented a while ago in v0.95.0 using opencv_has_module_<MODULE_NAME>! macros

twistedfall avatar Sep 24 '25 20:09 twistedfall