-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (148 loc) · 8.94 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# This is a basic workflow to help you get started with Actions
name: build
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "**" ]
# Allows you to run this workflow manually from the Actions tab
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
# Generates binaries for different platforms, which will be uploaded to the Actions page.
# We then manually uplaod them into the Release's assets.
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# Builds for linux
# ubuntu-build:
# # The type of runner that the job will run on
# runs-on: ubuntu-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@v3
# # Install rust
# - name: Install rust
# run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
# # Install opencv
# #- name: Install opencv
# # run: sudo apt install libopencv-dev clang libclang-dev
# # 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: |
# 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=/opt/opencv -DBUILD_DOCS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DWITH_PNG=OFF -DWITH_JPEG=OFF -DWITH_TIFF=OFF -DWITH_WEBP=OFF -DWITH_OPENJPEG=OFF -DWITH_JASPER=OFF -DWITH_OPENEXR=OFF -DWITH_V4L=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 /opt/opencv
# cd ..
# # Note: OPENCV_LINK_LIBS ordering matters for linux. Put lower level deps after higher level. See https://answers.opencv.org/question/186124/undefined-reference-to-cvsoftdoubleoperator/
# # libclang files are in /usr/lib/llvm-##/lib. We symlink it to one of the opencv_link_paths
# # OpenCV-rust looks for "opencv2/core/version.hpp" for the OpenCV version: https://github.com/twistedfall/opencv-rust/issues/368
# # which is under /<install-prefix>/include/opencv4 for linux
# # Build
# - name: Build
# run: |
# export OPENCV_LINK_LIBS="opencv_videoio,opencv_imgcodecs,opencv_imgproc,opencv_core,libippiw,libittnotify,libippicv,z"
# export OPENCV_LINK_PATHS=/opt/opencv/lib,/opt/opencv/lib/opencv4/3rdparty,/usr/lib/x86_64-linux-gnu
# export OPENCV_INCLUDE_PATHS=/opt/opencv/include,/opt/opencv/include/opencv4
# sudo ln -s /usr/lib/llvm-15/lib/libclang.so.1 /usr/lib/x86_64-linux-gnu/libclang.so
# ls -R /opt/opencv
# ls -R /usr/lib
# cargo build --release
# # Upload artifact: https://github.com/actions/upload-artifact
# - name: Upload Artifacts
# uses: actions/upload-artifact@v3
# with:
# name: imagetools
# path: target/release/imagetools
# retention-days: 14
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-${{ hashFiles('**/CMakeLists.txt') }} # 使用 CMakeLists.txt 的哈希作为缓存键
restore-keys: |
${{ runner.os }}-opencv-
# 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