Skip to content

Commit

Permalink
Add macOS vcpkg and cleanup CI
Browse files Browse the repository at this point in the history
  • Loading branch information
twistedfall committed Apr 16, 2024
1 parent 63a0ba9 commit fddfd87
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 28 deletions.
1 change: 1 addition & 0 deletions .github/workflows/opencv-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
os-image:
- ubuntu-22.04
- windows-2022
- macos-14
vcpkg-version:
- 2024.03.25
runs-on: ${{ matrix.os-image }}
Expand Down
20 changes: 0 additions & 20 deletions ci/install-macos-brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,6 @@ set -xeu

brew list --versions
brew -v update

# fixes the install on 2023-12-10
rm -f /usr/local/bin/2to3-3.11
rm -f /usr/local/bin/idle3.11
rm -f /usr/local/bin/pydoc3.11
rm -f /usr/local/bin/python3.11
rm -f /usr/local/bin/python3.11-config
rm -f /usr/local/bin/2to3-3.12
rm -f /usr/local/bin/idle3.12
rm -f /usr/local/bin/pydoc3.12
rm -f /usr/local/bin/python3.12
rm -f /usr/local/bin/python3.12-config
rm -f /usr/local/bin/2to3
rm -f /usr/local/bin/idle3
rm -f /usr/local/bin/pydoc3
rm -f /usr/local/bin/python3
rm -f /usr/local/bin/python3-config

brew uninstall --force node@18

brew upgrade --force --display-times
brew list --versions
brew -v install --force --display-times opencv"$BREW_OPENCV_VERSION"
Expand Down
45 changes: 45 additions & 0 deletions ci/install-macos-vcpkg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -xeu

if [[ "${VCPKG_VERSION:-}" == "" ]]; then
echo "Must set VCPKG_VERSION environment var"
exit 1
fi

export VCPKG_ROOT="$HOME/build/vcpkg"
if [[ -e "$VCPKG_ROOT" && ! -e "$VCPKG_ROOT/.git" ]]; then
rm -rf "$VCPKG_ROOT"
fi
if [ ! -e "$VCPKG_ROOT" ]; then
git clone https://github.com/Microsoft/vcpkg.git "$VCPKG_ROOT"
fi
pushd "$VCPKG_ROOT"
git fetch --all --prune --tags
git status
git checkout .
git checkout "$VCPKG_VERSION"
./bootstrap-vcpkg.sh -disableMetrics
#./vcpkg integrate install
echo "set(VCPKG_BUILD_TYPE release)" >> triplets/arm64-osx.cmake
echo "set(VCPKG_BUILD_TYPE release)" >> triplets/x64-osx.cmake
export VCPKG_DEFAULT_TRIPLET=arm64-osx
(
set +e
which cmake
cmake --version
# 2024-04-15, cmake 3.29.1 doesn't work so well with vcpkg, remove this hack when cmake is 3.29.2+
# https://github.com/microsoft/vcpkg/issues/37968
mv -vf /usr/local/bin/cmake /usr/local/bin/cmake.bad
if ! ./vcpkg install --clean-after-build --recurse "opencv[contrib,nonfree]"; then
for log in "$VCPKG_ROOT/buildtrees"/**/*out.log; do
echo "=== $log"
cat "$log"
done
exit 1
fi
mv -vf /usr/local/bin/cmake.bad /usr/local/bin/cmake
)
# remove build artifacts to save CI cache space
rm -rf "$VCPKG_ROOT/downloads" "$VCPKG_ROOT/buildtrees" "$VCPKG_ROOT/packages"
popd
1 change: 1 addition & 0 deletions ci/install-ubuntu-vcpkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export VCPKG_DEFAULT_TRIPLET=x64-linux
#./vcpkg install llvm # takes very long time
(
set +e
which cmake
cmake --version
# 2024-04-15, cmake 3.29.1 doesn't work so well with vcpkg, remove this hack when cmake is 3.29.2+
# https://github.com/microsoft/vcpkg/issues/37968
Expand Down
1 change: 1 addition & 0 deletions ci/install-windows-vcpkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export VCPKG_DEFAULT_TRIPLET=x64-windows
#./vcpkg install llvm # takes very long time
(
set +e
which cmake
cmake --version
if ! ./vcpkg install --clean-after-build --recurse "opencv[contrib,nonfree]"; then
for log in "$VCPKG_ROOT/buildtrees"/**/*out.log; do
Expand Down
6 changes: 3 additions & 3 deletions ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ ci_dir="$(dirname "$0")"

if [[ "$OS_FAMILY" == "Linux" ]]; then
# free up disk space in Github Actions image: https://github.com/actions/runner-images/issues/2840
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/share/boost
if [[ "${VCPKG_VERSION:-}" != "" ]]; then # vcpkg build
"$ci_dir/install-ubuntu-vcpkg.sh"
else
Expand All @@ -17,6 +15,8 @@ if [[ "$OS_FAMILY" == "Linux" ]]; then
elif [[ "$OS_FAMILY" == "macOS" ]]; then
if [[ "${BREW_OPENCV_VERSION:-}" != "" ]]; then # brew build
"$ci_dir/install-macos-brew.sh"
elif [[ "${VCPKG_VERSION:-}" != "" ]]; then # vcpkg build
"$ci_dir/install-macos-vcpkg.sh"
else
"$ci_dir/install-macos-framework.sh"
fi
Expand Down
1 change: 1 addition & 0 deletions ci/msrv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ rustc --version
rustc --print=cfg

cargo update
rm -vf examples/cuda.rs # no CUDA support in CI
cargo check -vv --all-targets --all-features --workspace --tests
2 changes: 1 addition & 1 deletion ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ elif [[ "$OS_FAMILY" == "Linux" ]]; then
"$VCPKG_ROOT/vcpkg" list
else
if [[ "${OPENCV_LINKAGE:-dynamic}" == "static" ]]; then # static build
export OPENCV_LINK_LIBS=opencv_highgui,opencv_objdetect,opencv_dnn,opencv_videostab,opencv_calib3d,opencv_features2d,opencv_stitching,opencv_flann,opencv_videoio,opencv_rgbd,opencv_aruco,opencv_video,opencv_ml,opencv_imgcodecs,opencv_imgproc,opencv_core,ittnotify,tbb,liblibwebp,liblibtiff,liblibjpeg-turbo,liblibpng,liblibopenjp2,ippiw,ippicv,liblibprotobuf,quirc,zlib
export OPENCV_LINK_LIBS=opencv_highgui,opencv_objdetect,opencv_dnn,opencv_videostab,opencv_calib3d,opencv_features2d,opencv_stitching,opencv_flann,opencv_videoio,opencv_rgbd,opencv_aruco,opencv_video,opencv_ml,opencv_imgcodecs,opencv_imgproc,opencv_core,opencv_gapi,ade,ittnotify,tbb,liblibwebp,liblibtiff,liblibjpeg-turbo,liblibpng,liblibopenjp2,ippiw,ippicv,liblibprotobuf,quirc,zlib
fi
fi
fi
Expand Down
8 changes: 4 additions & 4 deletions examples/cuda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ fn main() -> Result<()> {
if cuda_available {
println!("Timing CUDA implementation... ");
let img = imgcodecs::imread(&img_file, imgcodecs::IMREAD_COLOR)?;
let mut img_gpu = GpuMat::default()?;
let mut img_gpu = GpuMat::new_def()?;
img_gpu.upload(&img)?;
let mut stream = core::Stream::default()?;
let start = time::Instant::now();
for _ in 0..ITERATIONS {
let mut gray = GpuMat::default()?;
let mut gray = GpuMat::new_def()?;
cudaimgproc::cvt_color(&img_gpu, &mut gray, imgproc::COLOR_BGR2GRAY, 0, &mut stream)?;
let mut blurred = GpuMat::default()?;
let mut blurred = GpuMat::new_def()?;
let mut filter = cudafilters::create_gaussian_filter(
gray.typ()?,
blurred.typ()?,
Expand All @@ -57,7 +57,7 @@ fn main() -> Result<()> {
core::BORDER_DEFAULT,
)?;
filter.apply(&gray, &mut blurred, &mut stream)?;
let mut edges = GpuMat::default()?;
let mut edges = GpuMat::new_def()?;
let mut detector = cudaimgproc::create_canny_edge_detector(0., 50., 3, false)?;
detector.detect(&blurred, &mut edges, &mut stream)?;
stream.wait_for_completion()?;
Expand Down

0 comments on commit fddfd87

Please sign in to comment.