Skip to content

Commit 9ed33da

Browse files
committed
ci: install only the OpenCV modules the cv extension uses
`libopencv-dev` is a meta-package that hard-depends on the viz and contrib modules, pulling VTK, OpenMPI, tesseract and ~220 packages. On a throttled Azure mirror that ran past 50 minutes (libvtk9 alone: 20 MB in ~10 min). --no-install-recommends would not have helped, since those are hard Depends. Install libopencv-{core,imgproc}-dev instead. OpenCVConfig.cmake ships only in the meta-package, so cpp/tests now prefers OpenCV's CMake package when present and otherwise locates core/imgproc directly; both paths verified to build and pass all 121 tests. Also caps the job at 30 minutes so a stalled download fails with logs rather than running to the 6 h default.
1 parent 31cfac6 commit 9ed33da

3 files changed

Lines changed: 67 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ jobs:
4343
native-tests:
4444
name: C++ unit tests
4545
runs-on: ubuntu-latest
46+
# Well clear of a cold run (dependency build ~2 min) but far below the 6 h
47+
# default, so a stalled download fails with logs instead of hanging.
48+
timeout-minutes: 30
4649
defaults:
4750
run:
4851
working-directory: packages/react-native-executorch
@@ -70,9 +73,19 @@ jobs:
7073
with:
7174
node-version-file: .nvmrc
7275

76+
# Only the two OpenCV modules the cv extension uses. The `libopencv-dev`
77+
# meta-package hard-depends on the viz and contrib modules, which pull VTK,
78+
# OpenMPI and ~220 packages — over 50 minutes on a throttled mirror.
79+
# OpenCVConfig.cmake ships only in that meta-package, so cpp/tests
80+
# falls back to locating the libraries directly.
7381
- name: Install build tooling
74-
run: sudo apt-get update && sudo apt-get install -y ninja-build libopencv-dev
82+
run: |
83+
sudo apt-get update
84+
sudo apt-get install -y --no-install-recommends \
85+
ninja-build libopencv-core-dev libopencv-imgproc-dev
7586
working-directory: ${{ github.workspace }}
87+
env:
88+
DEBIAN_FRONTEND: noninteractive
7689

7790
- name: Provision third-party headers
7891
run: RNET_HEADERS_ONLY=1 node scripts/download-libs.js

packages/react-native-executorch/cpp/tests/CMakeLists.txt

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,44 @@ set(RNE_SOURCES
121121
"${CPP_DIR}/RnExecutorch.cpp"
122122
${CORE_SOURCES} ${MATH_SOURCES} ${NLP_SOURCES} ${SPEECH_SOURCES})
123123

124+
# The cv extension uses only core and imgproc. Prefer OpenCV's CMake package
125+
# when it is installed (Homebrew, or a full distro OpenCV), but fall back to
126+
# locating the two libraries directly: on Debian/Ubuntu OpenCVConfig.cmake ships
127+
# only in the `libopencv-dev` meta-package, which hard-depends on the viz and
128+
# contrib modules and so drags in VTK, OpenMPI and ~220 packages. The fallback
129+
# lets CI install just libopencv-{core,imgproc}-dev instead.
130+
function(rne_find_opencv)
131+
add_library(rne_opencv INTERFACE)
132+
133+
find_package(OpenCV QUIET COMPONENTS core imgproc)
134+
if(OpenCV_FOUND)
135+
message(STATUS "OpenCV: using CMake package ${OpenCV_VERSION}")
136+
target_include_directories(rne_opencv INTERFACE ${OpenCV_INCLUDE_DIRS})
137+
target_link_libraries(rne_opencv INTERFACE ${OpenCV_LIBS})
138+
return()
139+
endif()
140+
141+
find_path(OPENCV_INCLUDE_DIR
142+
NAMES opencv2/core.hpp
143+
PATH_SUFFIXES opencv4)
144+
find_library(OPENCV_CORE_LIB NAMES opencv_core)
145+
find_library(OPENCV_IMGPROC_LIB NAMES opencv_imgproc)
146+
147+
if(NOT OPENCV_INCLUDE_DIR OR NOT OPENCV_CORE_LIB OR NOT OPENCV_IMGPROC_LIB)
148+
message(FATAL_ERROR
149+
"OpenCV (core + imgproc) not found. Install it with:\n"
150+
" brew install opencv\n"
151+
" apt-get install libopencv-core-dev libopencv-imgproc-dev\n"
152+
"or configure with -DRNE_TESTS_ENABLE_OPENCV=OFF to skip the cv suite.")
153+
endif()
154+
155+
message(STATUS "OpenCV: using ${OPENCV_CORE_LIB}")
156+
target_include_directories(rne_opencv INTERFACE "${OPENCV_INCLUDE_DIR}")
157+
target_link_libraries(rne_opencv INTERFACE "${OPENCV_CORE_LIB}" "${OPENCV_IMGPROC_LIB}")
158+
endfunction()
159+
124160
if(RNE_TESTS_ENABLE_OPENCV)
125-
find_package(OpenCV REQUIRED COMPONENTS core imgproc)
161+
rne_find_opencv()
126162
list(APPEND RNE_SOURCES ${OPENCV_SOURCES})
127163
endif()
128164

@@ -146,7 +182,7 @@ endif()
146182

147183
if(RNE_TESTS_ENABLE_OPENCV)
148184
target_compile_definitions(rne_under_test PUBLIC RNE_ENABLE_OPENCV)
149-
target_link_libraries(rne_under_test PUBLIC ${OpenCV_LIBS})
185+
target_link_libraries(rne_under_test PUBLIC rne_opencv)
150186
endif()
151187

152188
# --- Test support -----------------------------------------------------------

packages/react-native-executorch/cpp/tests/README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,21 @@ scripts/run-native-tests.sh
6565
scripts/run-native-tests.sh -R MathOpsTest # extra args go to ctest
6666
```
6767

68-
Requires `cmake`, `ninja` and — for the `cv` suite — OpenCV
69-
(`brew install opencv` / `apt-get install libopencv-dev`). Without OpenCV, run
70-
with `RNE_TESTS_ENABLE_OPENCV=OFF` to skip that suite.
68+
Requires `cmake`, `ninja` and — for the `cv` suite — OpenCV's core and imgproc
69+
modules:
70+
71+
```bash
72+
brew install opencv # macOS
73+
apt-get install libopencv-core-dev libopencv-imgproc-dev # Debian/Ubuntu
74+
```
75+
76+
Without OpenCV, run with `RNE_TESTS_ENABLE_OPENCV=OFF` to skip that suite.
77+
78+
Note the deliberately narrow apt packages. `libopencv-dev` is a meta-package
79+
that hard-depends on the viz and contrib modules, so it drags in VTK, OpenMPI
80+
and ~220 packages — it took over 50 minutes on a throttled CI mirror. Since
81+
`OpenCVConfig.cmake` ships only in that meta-package, the build prefers OpenCV's
82+
CMake package when present and otherwise locates the two libraries directly.
7183

7284
## Keeping the pins honest
7385

0 commit comments

Comments
 (0)