From c0fbc4ab558f2063f67ac8ddc91836dc1a96c216 Mon Sep 17 00:00:00 2001 From: Junrou Nishida Date: Mon, 11 Oct 2021 23:41:26 +0900 Subject: [PATCH] ci: pass tests on Windows (#49) * build: copy opencv.BUILD from MediaPipeUnityPlugin * chore: current end_of_line is LF * build: remove opencv_deps option * ci: enable Windows * build: pass environment variables to build OpenCV * ci: disable LAPACK * ci: ignore SignalAbortTest on Windows * test: fix tests on Windows * doc: remove an incorrect line * Do not upload contents of build/ We already have Bazel Caching so I doubt we even needed this. Co-authored-by: Capuccino --- .editorconfig | 2 +- .github/workflows/ci.yml | 192 +++++++-------- README.md | 2 - build.py | 43 +++- .../Framework/ImageFormat/ImageFrameTest.cs | 2 +- .../Framework/Packet/FloatArrayPacketTest.cs | 9 +- .../Framework/Packet/ImageFramePacketTest.cs | 10 +- src/Akihabara/Native/NativeMethods.cs | 2 +- third_party/opencv.BUILD | 228 +++++++++++------- 9 files changed, 288 insertions(+), 202 deletions(-) diff --git a/.editorconfig b/.editorconfig index 2cbbaf0..fc89436 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,7 +2,7 @@ root = true [*] indent_style = space -end_of_line = crlf +end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 455b296..f68b17d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,96 +1,96 @@ -on: [push, pull_request] -name: Continuous Integration - -jobs: - test: - name: Test - runs-on: ${{matrix.os.fullname}} - env: - PROJECT_NAME: Akihabara - NET_ENV: net5.0 - strategy: - fail-fast: false - matrix: - os: - # - { prettyname: Windows, fullname: windows-latest } - - { prettyname: Linux, fullname: ubuntu-latest } - steps: - - name: Cache Bazel directory - uses: actions/cache@v2 - if: ${{ always() }} - env: - cache-name: bazel-cache - with: - path: ~/.cache/bazel - key: ${{runner.os}}-${{env.cache-name}}-dev - - - name: Cache build directory - uses: actions/cache@v2 - env: - cache-name: build-cache - with: - path: build - key: ${{runner.os}}-${{env.cache-name}}-dev - - - name: Checkout - uses: actions/checkout@v2 - - - name: Install .NET 5.0.x - uses: actions/setup-dotnet@v1 - with: - dotnet-version: "5.0.x" - - # FIXME: Setup will fail if you use a Python version lower than 3.9 - - name: Force Python 3.9 - uses: actions/setup-python@v2 - with: - python-version: "3.9" - architecture: "x64" - - - name: Set up MinGW - if: ${{ matrix.os.prettyname == 'Windows' }} - uses: egor-tensin/setup-mingw@v2 - with: - platform: x64 - - - name: Build (Native, Windows) - if: ${{ matrix.os.prettyname == 'Windows' }} - run: | - echo "Setting PYTHON_BIN_PATH to python in PATH" - $env:PYTHON_BIN_PATH=(Get-Command python).Path - echo $env:PYTHON_BIN_PATH - pip install numpy - python build.py build --desktop cpu --opencv=local -vv - - - name: Build (Native, *nix) - if: ${{ matrix.os.prettyname != 'Windows' }} - run: | - pip install numpy - python build.py build --desktop cpu --opencv=cmake -vv - - - name: Build (.NET) - run: dotnet build -c Debug src/${{env.PROJECT_NAME}}.sln - - - name: Copy libmediapipe_c.* into Akihabara.tests - run: cp $pwd/src/${{env.PROJECT_NAME}}/bin/Debug/${{env.NET_ENV}}/libmediapipe_c.* $pwd/src/${{env.PROJECT_NAME}}.Tests/bin/Debug/${{env.NET_ENV}}/ - shell: pwsh - - - name: Test (CPU) - run: dotnet test --filter TestCategory!=GpuOnlyTest "$pwd/src/${{env.PROJECT_NAME}}.Tests" --logger "trx;LogFileName=TestResults-${{matrix.os.prettyname}}.trx" - shell: pwsh - - # Attempt to upload results even if test fails. - # https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#always - - name: Upload Test Results (${{matrix.os.prettyname}}) - uses: actions/upload-artifact@v2 - if: ${{ always() }} - with: - name: TestResults-${{matrix.os.prettyname}} - path: ${{github.workspace}}/src/Akihabara.Tests/TestResults/TestResults-${{matrix.os.prettyname}}.trx - - # The contents of the build folder - - name: Upload Build Artifacts (${{matrix.os.prettyname}}) - uses: actions/upload-artifact@v2 - with: - name: build-artifacts-${{matrix.os.prettyname}} - path: build/ +on: [push, pull_request] +name: Continuous Integration + +jobs: + test: + name: Test + runs-on: ${{matrix.os.fullname}} + env: + PROJECT_NAME: Akihabara + NET_ENV: net5.0 + strategy: + fail-fast: false + matrix: + os: + - { prettyname: Windows, fullname: windows-latest } + - { prettyname: Linux, fullname: ubuntu-latest } + steps: + - name: Cache Bazel directory + uses: actions/cache@v2 + if: ${{ always() }} + env: + cache-name: bazel-cache + with: + path: ~/.cache/bazel + key: ${{runner.os}}-${{env.cache-name}}-dev + + - name: Cache build directory + uses: actions/cache@v2 + env: + cache-name: build-cache + with: + path: build + key: ${{runner.os}}-${{env.cache-name}}-dev + + - name: Checkout + uses: actions/checkout@v2 + + - name: Install .NET 5.0.x + uses: actions/setup-dotnet@v1 + with: + dotnet-version: "5.0.x" + + # FIXME: Setup will fail if you use a Python version lower than 3.9 + - name: Force Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: "3.9" + architecture: "x64" + + - name: Set up MinGW + if: ${{ matrix.os.prettyname == 'Windows' }} + uses: egor-tensin/setup-mingw@v2 + with: + platform: x64 + + - name: Build (Native, Windows) + if: ${{ matrix.os.prettyname == 'Windows' }} + run: | + echo "Setting PYTHON_BIN_PATH to python in PATH" + $env:PYTHON_BIN_PATH=(Get-Command python).Path + echo $env:PYTHON_BIN_PATH + pip install numpy + python build.py build --desktop cpu --opencv=cmake -vv + + - name: Build (Native, *nix) + if: ${{ matrix.os.prettyname != 'Windows' }} + run: | + pip install numpy + python build.py build --desktop cpu --opencv=cmake -vv + + - name: Build (.NET) + run: dotnet build -c Debug src/${{env.PROJECT_NAME}}.sln + + - name: Copy libmediapipe_c.* into Akihabara.tests + run: cp $pwd/src/${{env.PROJECT_NAME}}/bin/Debug/${{env.NET_ENV}}/libmediapipe_c.* $pwd/src/${{env.PROJECT_NAME}}.Tests/bin/Debug/${{env.NET_ENV}}/ + shell: pwsh + + # On Windows, ignore tests that can signal SIGABRT because it will abort the process. + - name: Test (CPU, Windows) + if: ${{ matrix.os.prettyname == 'Windows' }} + run: dotnet test --filter "TestCategory!=GpuOnlyTest&TestCategory!=SignalAbortTest" "$pwd/src/${{env.PROJECT_NAME}}.Tests" --logger "trx;LogFileName=TestResults-${{matrix.os.prettyname}}.trx" + shell: pwsh + + - name: Test (CPU, *nix) + if: ${{ matrix.os.prettyname != 'Windows' }} + run: dotnet test --filter TestCategory!=GpuOnlyTest "$pwd/src/${{env.PROJECT_NAME}}.Tests" --logger "trx;LogFileName=TestResults-${{matrix.os.prettyname}}.trx" + shell: pwsh + + # Attempt to upload results even if test fails. + # https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#always + - name: Upload Test Results (${{matrix.os.prettyname}}) + uses: actions/upload-artifact@v2 + if: ${{ always() }} + with: + name: TestResults-${{matrix.os.prettyname}} + path: ${{github.workspace}}/src/Akihabara.Tests/TestResults/TestResults-${{matrix.os.prettyname}}.trx diff --git a/README.md b/README.md index 1f593e2..002941a 100644 --- a/README.md +++ b/README.md @@ -26,5 +26,3 @@ build.py build --desktop gpu --vv - .NET 5.0 or .NET 6.0 LTS - GCC-9 (GCC-10 also works but not guranteed to work since Mediapipe uses a lot of deprecated syntax). - Bazel -- CMake (Needed if you wanna compile opencv locally with `build.py --opencv=cmake`. - diff --git a/build.py b/build.py index 88f15fd..c314a86 100644 --- a/build.py +++ b/build.py @@ -41,7 +41,7 @@ def __init__(self, command_args): self.verbose = command_args.args.verbose self.console = Console(self.verbose) - def _run_command(self, command_list, shell=False): + def _run_command(self, command_list, shell=True): self.console.v(f"Running `{' '.join(command_list)}`") if shell: @@ -69,7 +69,7 @@ def _copytree(self, source, dest): os.makedirs(dest, 0o755) # `shutil.copytree` fails on Windows if target file exists, so run `cp -r` instead. - self._run_command(['cp', '-r', f'{source}/*', dest], shell=True) + self._run_command(['cp', '-r', f'{source}/*', dest]) def _remove(self, path): self.console.v(f"Removing '{path}'...") @@ -98,7 +98,6 @@ def __init__(self, command_args): # self.ios= command_args.args.ios self.resources = command_args.args.resources self.opencv = command_args.args.opencv - self.opencv_deps = command_args.args.opencv_deps self.include_opencv_libs = command_args.args.include_opencv_libs self.compilation_mode = command_args.args.compilation_mode @@ -163,7 +162,7 @@ def run(self): # os.path.join(_BAZEL_BIN_PATH, 'mediapipe_api', 'objc', 'MediaPipeUnity.zip'), # os.path.join(_BUILD_PATH, 'Plugins', 'iOS')) - + self.console.info('Printing build path...') for root, directories, files in os.walk(_BUILD_PATH, topdown=False): @@ -197,8 +196,36 @@ def _build_common_commands(self): commands += self._build_linkopt() if self._is_windows(): - python_bin_path = os.environ['PYTHON_BIN_PATH'].replace('\\', '//') - commands += ['--action_env', f'PYTHON_BIN_PATH={python_bin_path}'] + python_bin_path_key = 'PYTHON_BIN_PATH' + if python_bin_path_key not in os.environ: + raise RuntimeError(f'`{python_bin_path_key}` is not set') + + python_bin_path = os.environ[python_bin_path_key].replace('\\', '//') + commands += ['--action_env', f'{python_bin_path_key}="{python_bin_path}"'] + + # Required to compile OpenCV + # Without this environment variable, Visual Studio instances won't be found + # cf. https://github.com/bazelbuild/rules_foreign_cc/issues/793 + program_data_key = 'ProgramData' + if program_data_key in os.environ: + commands += ['--action_env', program_data_key] + + # Enable CMake to detect processors when configuring OpenCV + processor_architecture_key = 'PROCESSOR_ARCHITECTURE' + if processor_architecture_key in os.environ: + commands += ['--action_env', processor_architecture_key] + + processor_identifier_key = 'PROCESSOR_IDENTIFIER' + if processor_identifier_key in os.environ: + commands += ['--action_env', processor_identifier_key] + + processor_level_key = 'PROCESSOR_LEVEL' + if processor_level_key in os.environ: + commands += ['--action_env', processor_level_key] + + processor_revision_key = 'PROCESSOR_REVISION' + if processor_revision_key in os.environ: + commands += ['--action_env', processor_revision_key] if self.verbose > 1: commands.append('--verbose_failures') @@ -217,9 +244,6 @@ def _build_linkopt(self): def _build_opencv_switch(self): commands = [f'--@opencv//:switch={self.opencv}'] - if self.opencv == 'cmake': - commands += [f'--@opencv//:deps={switch}' for switch in self.opencv_deps] - return commands def _build_desktop_options(self): @@ -372,7 +396,6 @@ def __init__(self): build_command_parser.add_argument('--resources', '-R', action=argparse.BooleanOptionalAction) build_command_parser.add_argument('--compilation_mode', '-c', choices=['fastbuild', 'opt', 'dbg'], default='opt') build_command_parser.add_argument('--opencv', choices=['local', 'cmake'], default='local', help='Decide to which OpenCV to link for Desktop native libraries') - build_command_parser.add_argument('--opencv_deps', action='append', choices=['ffmpeg'], default=[], help='OpenCV Dependencies (only used when `--opencv=cmake`)') build_command_parser.add_argument('--include_opencv_libs', action='store_true', help='Include OpenCV\'s native libraries for Desktop') build_command_parser.add_argument('--linkopt', '-l', action='append', help='Linker options') build_command_parser.add_argument('--verbose', '-v', action='count', default=0) diff --git a/src/Akihabara.Tests/Framework/ImageFormat/ImageFrameTest.cs b/src/Akihabara.Tests/Framework/ImageFormat/ImageFrameTest.cs index f8612fb..d675b8d 100644 --- a/src/Akihabara.Tests/Framework/ImageFormat/ImageFrameTest.cs +++ b/src/Akihabara.Tests/Framework/ImageFormat/ImageFrameTest.cs @@ -89,7 +89,7 @@ public void Ctor_ShouldInstantiateImageFrame_When_CalledWithPixelData() } } - [Test] + [Test, SignalAbort] public void Ctor_ShouldThrowMediaPipeException_When_CalledWithInvalidArgument() { Assert.Throws(() => { new ImageFrame(ImageFormat.Format.Sbgra, 640, 480, 0); }); diff --git a/src/Akihabara.Tests/Framework/Packet/FloatArrayPacketTest.cs b/src/Akihabara.Tests/Framework/Packet/FloatArrayPacketTest.cs index 4b01846..2cb876d 100644 --- a/src/Akihabara.Tests/Framework/Packet/FloatArrayPacketTest.cs +++ b/src/Akihabara.Tests/Framework/Packet/FloatArrayPacketTest.cs @@ -96,7 +96,14 @@ public void DebugTypeName_ShouldReturnFloat_When_ValueIsSet() float[] array = { 0.01f }; var packet = new FloatArrayPacket(array); - Assert.AreEqual(packet.DebugTypeName(), "float []"); + if (Environment.OSVersion.Platform == PlatformID.Win32NT) + { + Assert.AreEqual(packet.DebugTypeName(), "float [0]"); + } + else + { + Assert.AreEqual(packet.DebugTypeName(), "float []"); + } } #endregion } diff --git a/src/Akihabara.Tests/Framework/Packet/ImageFramePacketTest.cs b/src/Akihabara.Tests/Framework/Packet/ImageFramePacketTest.cs index cef20e9..cbc8a63 100644 --- a/src/Akihabara.Tests/Framework/Packet/ImageFramePacketTest.cs +++ b/src/Akihabara.Tests/Framework/Packet/ImageFramePacketTest.cs @@ -7,6 +7,7 @@ using Akihabara.Framework.Packet; using Akihabara.Framework.Port; using NUnit.Framework; +using System; namespace Akihabara.Tests.Framework.Packet { @@ -121,7 +122,14 @@ public void DebugTypeName_ShouldReturnFloat_When_ValueIsSet() { var packet = new ImageFramePacket(new ImageFrame()); - Assert.AreEqual(packet.DebugTypeName(), "mediapipe::ImageFrame"); + if (Environment.OSVersion.Platform == PlatformID.Win32NT) + { + Assert.AreEqual(packet.DebugTypeName(), "class mediapipe::ImageFrame"); + } + else + { + Assert.AreEqual(packet.DebugTypeName(), "mediapipe::ImageFrame"); + } } #endregion } diff --git a/src/Akihabara/Native/NativeMethods.cs b/src/Akihabara/Native/NativeMethods.cs index b40c2b1..00e059f 100644 --- a/src/Akihabara/Native/NativeMethods.cs +++ b/src/Akihabara/Native/NativeMethods.cs @@ -13,6 +13,6 @@ public partial class NativeMethods // variant we're basing off, which you can find here: https://git.io/Jc3y1 // // However, since we're targeting PC for now, we'll go for mediapipe_c for now. - internal const string MediaPipeLibrary = "mediapipe_c"; + internal const string MediaPipeLibrary = "libmediapipe_c"; } } diff --git a/third_party/opencv.BUILD b/third_party/opencv.BUILD index 40a21e9..96919d1 100644 --- a/third_party/opencv.BUILD +++ b/third_party/opencv.BUILD @@ -1,24 +1,27 @@ -load("@bazel_skylib//rules:common_settings.bzl", "string_flag", "string_list_flag") +# Copyright (c) 2021 homuler +# +# Use of this source code is governed by an MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT. + +load("@bazel_skylib//rules:common_settings.bzl", "string_flag") load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") load("@mediapipe_api//mediapipe_api:defs.bzl", "concat_dict_and_select") package(default_visibility = ["//visibility:public"]) filegroup( - name = "all", - srcs = glob(["**"]), + name = "all", + srcs = glob(["**"]), ) string_flag( name = "switch", - values = ["local", "cmake"], build_setting_default = "local", -) - -string_list_flag( - name = "deps", - # Currently, the only meaningful value is "ffmpeg" - build_setting_default = [], + values = [ + "local", + "cmake", + ], ) config_setting( @@ -29,10 +32,9 @@ config_setting( ) config_setting( - name = "with_ffmpeg", - flag_values = { - ":deps": "ffmpeg", - }, + name = "windows_dbg", + constraint_values = ["@platforms//os:windows"], + values = {"compilation_mode": "dbg"}, ) alias( @@ -58,9 +60,6 @@ alias( }), ) -# Note: this determines the order in which the libraries are passed to the -# linker, so if library A depends on library B, library B must come _after_. -# Hence core is at the bottom. OPENCV_MODULES = [ "calib3d", "features2d", @@ -83,104 +82,155 @@ OPENCV_3RDPARTY_LIBS = [ cmake( name = "opencv_cmake", - # Values to be passed as -Dkey=value on the CMake command line; - # here are serving to provide some CMake script configuration options - cache_entries = concat_dict_and_select({ - "CMAKE_BUILD_TYPE": "Release", - # The module list is always sorted alphabetically so that we do not - # cause a rebuild when changing the link order. - "BUILD_LIST": ",".join(sorted(OPENCV_MODULES)), - "BUILD_opencv_apps": "OFF", - "BUILD_opencv_python": "OFF", - "BUILD_EXAMPLES": "OFF", - "BUILD_PERF_TESTS": "OFF", - "BUILD_TESTS": "OFF", - "BUILD_JPEG": "ON", - "BUILD_OPENEXR": "ON", - "BUILD_PNG": "ON", - "BUILD_TIFF": "ON", - "BUILD_ZLIB": "ON", - "WITH_1394": "OFF", - "WITH_FFMPEG": "OFF", - "WITH_GSTREAMER": "OFF", - "WITH_GTK": "OFF", - # Some symbols in ippicv and ippiw cannot be resolved, and they are excluded currently in the first place. - # https://github.com/opencv/opencv/pull/16505 - "WITH_IPP": "OFF", - "WITH_ITT": "OFF", - "WITH_JASPER": "OFF", - "WITH_V4L": "OFF", - "WITH_WEBP": "OFF", - "CV_ENABLE_INTRINSICS": "ON", - "WITH_EIGEN": "ON", - # https://github.com/opencv/opencv/issues/19846 - "WITH_LAPACK": "OFF", - "WITH_PTHREADS": "ON", - "WITH_PTHREADS_PF": "ON", - "ENABLE_CCACHE": "OFF", - # flags for static build - "BUILD_SHARED_LIBS": "OFF", - "OPENCV_SKIP_PYTHON_LOADER": "ON", - "OPENCV_SKIP_VISIBILITY_HIDDEN": "ON", - }, { - ":with_ffmpeg": { "WITH_FFMPEG": "ON" }, - "//conditions:default": { "WITH_FFMPEG": "OFF" }, - }), - lib_source = "@opencv//:all", build_args = [ + "--verbose", "--parallel", ] + select({ "@bazel_tools//src/conditions:darwin": ["`sysctl -n hw.ncpu`"], - "//conditions:default" : ["`nproc`"], + "//conditions:default": ["`nproc`"], + }), + # Values to be passed as -Dkey=value on the CMake command line; + # here are serving to provide some CMake script configuration options + cache_entries = concat_dict_and_select( + { + # The module list is always sorted alphabetically so that we do not + # cause a rebuild when changing the link order. + "BUILD_LIST": ",".join(sorted(OPENCV_MODULES)), + "BUILD_opencv_apps": "OFF", + "BUILD_opencv_python": "OFF", + "BUILD_opencv_world": "ON", + "BUILD_EXAMPLES": "OFF", + "BUILD_PERF_TESTS": "OFF", + "BUILD_TESTS": "OFF", + "BUILD_JPEG": "ON", + "BUILD_OPENEXR": "ON", + "BUILD_PNG": "ON", + "BUILD_TIFF": "ON", + "BUILD_ZLIB": "ON", + "WITH_1394": "OFF", + "WITH_FFMPEG": "OFF", + "WITH_GSTREAMER": "OFF", + "WITH_GTK": "OFF", + # Some symbols in ippicv and ippiw cannot be resolved, and they are excluded currently in the first place. + # https://github.com/opencv/opencv/pull/16505 + "WITH_IPP": "OFF", + "WITH_ITT": "OFF", + "WITH_JASPER": "OFF", + "WITH_V4L": "OFF", + "WITH_WEBP": "OFF", + "CV_ENABLE_INTRINSICS": "ON", + "WITH_EIGEN": "ON", + "ENABLE_CCACHE": "OFF", + # flags for static build + "BUILD_SHARED_LIBS": "OFF", + "OPENCV_SKIP_PYTHON_LOADER": "ON", + "OPENCV_SKIP_VISIBILITY_HIDDEN": "ON", + }, + { + "@bazel_tools//src/conditions:windows": { + "CMAKE_CXX_FLAGS": "/std:c++14", + # required to link to .dll statically + "BUILD_WITH_STATIC_CRT": "OFF", + # disable LAPACK to reduce build time in CI + "WITH_LAPACK": "OFF", + }, + "//conditions:default": { + # https://github.com/opencv/opencv/issues/19846 + "WITH_LAPACK": "OFF", + "WITH_PTHREADS": "ON", + "WITH_PTHREADS_PF": "ON", + }, + }, + ), + generate_args = select({ + "@bazel_tools//src/conditions:windows": [ + "-G \"Visual Studio 16 2019\"", + "-A x64", + ], + "//conditions:default": [], + }), + lib_source = "@opencv//:all", + out_lib_dir = select({ + "@bazel_tools//src/conditions:windows": "x64/vc16/staticlib", + "//conditions:default": "lib", + }), + out_static_libs = select({ + ":windows_dbg": ["opencv_world3410d.lib"], + "@bazel_tools//src/conditions:windows": ["opencv_world3410.lib"], + "//conditions:default": ["libopencv_world.a"], }), - out_static_libs = ["libopencv_%s.a" % (module) for module in OPENCV_MODULES], ) cc_library( name = "opencv_from_source", - srcs = [ - "libopencv_%s.a" % (module) for module in OPENCV_MODULES - ] + [ - "lib%s.a" % (lib) for lib in OPENCV_3RDPARTY_LIBS - ], + srcs = select({ + ":windows_dbg": ["opencv_world3410d.lib"], + "@bazel_tools//src/conditions:windows": ["opencv_world3410.lib"], + "//conditions:default": ["libopencv_world.a"], + }) + select({ + ":windows_dbg": ["%sd.lib" % lib for lib in OPENCV_3RDPARTY_LIBS], + "@bazel_tools//src/conditions:windows": ["%s.lib" % lib for lib in OPENCV_3RDPARTY_LIBS], + "//conditions:default": ["lib%s.a" % lib for lib in OPENCV_3RDPARTY_LIBS], + }), hdrs = glob(["include/opencv2/**/*.h*"]), - includes = ["include/"], - deps = [ - ":opencv_cmake", - ] + select({ - ":with_ffmpeg": ["@//third_party:libffmpeg"], - "//conditions:default": [], + data = select({ + ":windows_dbg": [ + ":opencv_static_libs_win_dbg", + ], + "@bazel_tools//src/conditions:windows": [ + ":opencv_static_libs_win", + ], + "//conditions:default": [ + ":opencv_static_libs", + ":opencv_3rdparty_libs", + ], }), - data = [ - ":opencv_static_libs", - ":opencv_3rdparty_libs", - ], - linkopts = [ - "-ldl", - "-lm", - "-lpthread", - ] + select({ + includes = ["include/"], + linkopts = select({ + "@bazel_tools//src/conditions:windows": [], + "//conditions:default": [ + "-ldl", + "-lm", + "-lpthread", + ], + }) + select({ + "@bazel_tools//src/conditions:windows": [], "@bazel_tools//src/conditions:darwin": [], "//conditions:default": ["-lrt"], }), + deps = [":opencv_cmake"], ) filegroup( - name = "opencv_gen_dir", - srcs = [":opencv_cmake"], - output_group = "gen_dir", + name = "opencv_gen_dir", + srcs = [":opencv_cmake"], + output_group = "gen_dir", ) genrule( name = "opencv_static_libs", srcs = [":opencv_gen_dir"], - outs = ["libopencv_%s.a" % (lib) for lib in OPENCV_MODULES], - cmd = "cp $