-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (134 loc) · 6.55 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# This is a basic workflow to help you get started with Actions
name: build
on:
push:
branches: [ "**" ]
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: false
jobs:
build:
strategy:
fail-fast: false
matrix:
os-image:
- ubuntu-22.04
opencv-version:
- 4.10.0
linkage:
- static
include:
- os-image: ubuntu-22.04
opencv-version: 4.10.0
linkage: static
runs-on: ${{ matrix.os-image }}
env:
Atlas_ROOT_DIR: /usr/include/ # for cmake to find lapacke.h
OPENCV_VERSION: ${{ matrix.opencv-version }}
OPENCV_LINKAGE: ${{ matrix.linkage }}
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
CMAKE_C_COMPILER_LAUNCHER: "sccache"
CMAKE_CXX_COMPILER_LAUNCHER: "sccache"
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: mozilla-actions/[email protected]
- uses: actions/cache@v4
with:
path: ~/dist
key: dist-${{ matrix.opencv-version }}
- uses: actions/cache@v4
with:
path: ~/build
key: build-${{ matrix.opencv-version }}-${{ matrix.linkage }}-${{ matrix.os-image }}
- name: Install dependencies
run: scripts/install.sh
shell: bash
- name: Build project
run: scripts/build.sh
shell: bash
windows-build:
# The type of runner that the job will run on
runs-on: windows-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
# Install rust
- name: Install rust
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- name: Chocolatey Action
# You may pin to the exact commit or the version.
# uses: crazy-max/ghaction-chocolatey@0e015857dd851f84fcb7fb53380eb5c4c8202333
uses: crazy-max/[email protected]
with:
# Arguments to pass to Chocolatey
# don't install opencv here as we build the staticlib below
args: install llvm wget strawberryperl
# Docker image to use
#image: # optional, default is ghcr.io/crazy-max/ghaction-chocolatey
- name: Cache OpenCV build
uses: actions/cache@v4
with:
path: |
D:/opt/opencv
key: ${{ runner.os }}-opencv-windows-${{ hashFiles('**/CMakeLists.txt') }} # 使用 CMakeLists.txt 的哈希作为缓存键
restore-keys: |
${{ runner.os }}-opencv-windows
# Note: in order to set config profile to Release and use a prefix path, we have to separate cmake steps for building/installing. CMake nuances...
# See https://stackoverflow.com/questions/19024259/how-to-change-the-build-type-to-release-mode-in-cmake, https://stackoverflow.com/questions/50028570/is-it-possible-to-build-cmake-projects-directly-using-msbuildtools, https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html
# Pull opencv source, unzip, configure cmake, build, and install
# Disable image formats like jpeg, png, tiff, as we use rust image crate instead. See https://docs.opencv.org/4.x/db/d05/tutorial_config_reference.html
# Inspired from https://github.com/twistedfall/opencv-rust/issues/364
- name: Install OpenCV static lib
run: |
if (-Not (Test-Path "D:/opt/opencv")) {
wget -O opencv.zip https://github.com/opencv/opencv/archive/refs/tags/4.8.1.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/refs/tags/4.8.1.zip
unzip opencv.zip
rm opencv.zip
unzip opencv_contrib.zip
rm opencv_contrib.zip
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=NO -DCMAKE_INSTALL_PREFIX="D:/opt/opencv" -DOPENCV_BUILD_3RDPARTY_LIBS=ON -DBUILD_DOCS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_opencv_java=OFF -DBUILD_opencv_python=OFF -DOPENCV_EXTRA_MODULES_PATH="../opencv_contrib-4.8.1/modules" ../opencv-4.8.1
cmake --build . --target install --config Release --parallel 8
cmake --install . --prefix D:/opt/opencv
cd ..
} else {
Write-Host "Using cached OpenCV build"
}
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
- uses: Swatinem/rust-cache@v2
with:
cache-directories: |
"D:/opt/opencv"
# OPENCV_LINK_LIBS includes both opencv modules and 3rdparty. Note: 3rdparty libs may be named differently on different platforms
# OPENCV_LINK_PATHS points to the installed staticlib folder after cmake install
# OPENCV_INCLUDE_PATHS points to installed include folder after cmake install
# OPENCV_MSVC_CRT is for CRT library to be static or dynamic using windows MSVC: https://github.com/twistedfall/opencv-rust/blob/master/README.md#troubleshooting
# Build
- name: Build
#run: $env:OPENCV_LINK_LIBS=$(Get-ChildItem -Path C:\tools -Recurse -Filter 'opencv_world*.lib' | Select-Object -first 1 | Select-Object -ExpandProperty Name); $env:OPENCV_LINK_PATHS=$(Get-ChildItem -Path C:\tools -Recurse -Filter 'opencv_world*.lib' | Select-Object -first 1 | Select-Object -ExpandProperty FullName | Split-Path -parent); $env:OPENCV_INCLUDE_PATHS="C:\tools\opencv\build\include"; cargo build --release
run: |
$env:OPENCV_LINK_LIBS="opencv_core481,opencv_videoio481,opencv_imgcodecs481,opencv_imgproc481,ippiw,ittnotify,ippicvmt,zlib,IlmImf,libjpeg-turbo,libopenjp2,libpng,libtiff,libwebp"
$env:OPENCV_LINK_PATHS="D:/opt/opencv/staticlib"
$env:OPENCV_INCLUDE_PATHS="D:/opt/opencv/include"
$env:OPENCV_MSVC_CRT="static"
cargo build --release
# Upload artifact: https://github.com/actions/upload-artifact
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: imagetools
path: |
target/release/imagetools.exe
target/release/imagetools.pdb
retention-days: 14