I have a system that is built using Bazel
and is using OpenCV
as a 3rd party package.
When building on Linux I want to use a prebuilt package using conan
, and when using Windows I want to use a locally compiled version, and not use conan.
What I have at the moment is in my WORKSPACE
file:
load("@//conan:dependencies.bzl", "load_conan_dependencies")
load_conan_dependencies()
new_local_repository(
name = "windows_opencv",
build_file = "@//third_party:opencv_windows.BUILD",
path = "C:\\opencv\\build",
)
and the conanfile.txt
looks like this:
[requires]
OpenCV/3.4.13@company/dev
[generators]
BazelDeps
BazelToolchain
This works well for the Linux part, but because I don't have the OpenCV/3.4.13@company/dev
package for Windows, I can't use conan install
and not rules are generated, so trying to build on Windows causes this error:
ERROR: error loading package '': Label '//conan:dependencies.bzl' is invalid because 'conan' is not a package; perhaps you meant to put the colon here: '//:conan/dependencies.bzl'?
The way I currently see this is I have 2 options:
- Have 2
conanfile.txt
, 1 which contains theOpenCV
package and another empty only with the generators, to create the necessary conan files so it would pass theload
call - Create an empty
OpenCV
conan package and again just insall it so theload
call would pass
Both options seems to me like bad hacks and workarounds, but I'm not familiar enough with Bazel
to know if there's a better option.
What I would like to be able to do is only load the conan dependencies rule for Linux and ignore it on Windows.
Currently the selection between Linux & Windows OpenCV is done using alias:
alias(
name = "opencv_binary",
actual = select({
"//mediapipe:windows": "@windows_opencv//:opencv",
"//conditions:default": "@opencv//:opencv",
}),
)
where @opencv//:opencv
is the conan pacakge