Skip to content

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

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

Open
OlivierLDff opened this issue Apr 26, 2025 · 2 comments
Open

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

OlivierLDff opened this issue Apr 26, 2025 · 2 comments

Comments

@OlivierLDff
Copy link

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 OlivierLDff changed the title How to propagate #[cfg(ocvrs_has_module_xxx)] to other crates How to propagate #[cfg(ocvrs_has_module_xxx)] to user crates Apr 26, 2025
@twistedfall
Copy link
Owner

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.

@OlivierLDff
Copy link
Author

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!

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