-
Notifications
You must be signed in to change notification settings - Fork 120
289 lines (240 loc) · 9.88 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
name: Build C++ Shared Library
on:
push:
branches:
# - main
release:
types:
- published
workflow_dispatch:
env:
# Raw character weights are not public.
# Skip uploading to GitHub Release on public repo.
SKIP_UPLOADING_RELEASE_ASSET: ${{ secrets.SKIP_UPLOADING_RELEASE_ASSET || '1' }}
jobs:
build-cpp-shared:
strategy:
fail-fast: false
matrix:
include:
- os: windows-2019
device: gpu
python_architecture: 'x64'
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.9.0/onnxruntime-win-x64-gpu-1.9.0.zip
artifact_name: windows-x64-gpu
- os: windows-2019
device: cpu-x64
python_architecture: 'x64'
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.9.0/onnxruntime-win-x64-1.9.0.zip
artifact_name: windows-x64-cpu
- os: windows-2019
device: cpu-x86
python_architecture: 'x86'
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.9.0/onnxruntime-win-x86-1.9.0.zip
cmake_additional_options: -DCMAKE_GENERATOR_PLATFORM=Win32
artifact_name: windows-x86-cpu
- os: windows-2019
device: cpu-arm64
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.9.0/onnxruntime-win-arm64-1.9.0.zip
cmake_additional_options: -DCMAKE_GENERATOR_PLATFORM=arm64
artifact_name: windows-arm64-cpu
- os: windows-2019
device: cpu-arm
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.9.0/onnxruntime-win-arm-1.9.0.zip
cmake_additional_options: -DCMAKE_GENERATOR_PLATFORM=arm
artifact_name: windows-arm-cpu
- os: macos-10.15
device: cpu-x64
python_architecture: 'x64'
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.9.0/onnxruntime-osx-x64-1.9.0.tgz
artifact_name: osx-x64-cpu
- os: ubuntu-18.04
device: gpu
python_architecture: 'x64'
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.9.0/onnxruntime-linux-x64-gpu-1.9.0.tgz
artifact_name: linux-x64-gpu
cc_version: '8'
cxx_version: '8'
- os: ubuntu-18.04
device: cpu-x64
python_architecture: 'x64'
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.9.0/onnxruntime-linux-x64-1.9.0.tgz
artifact_name: linux-x64-cpu
cc_version: '8'
cxx_version: '8'
- os: ubuntu-18.04
device: cpu-armhf
onnxruntime_url: https://github.com/VOICEVOX/onnxruntime-builder/releases/download/1.9.1.1/onnxruntime-linux-armhf-cpu-v1.9.1.tgz
artifact_name: linux-armhf-cpu
cc_version: '8'
cxx_version: '8'
arch: arm-linux-gnueabihf
runs-on: ${{ matrix.os }}
env:
# prefix usage: "", "arm-linux-gnueabihf-" => "gcc-8", "arm-linux-gnueabihf-gcc-8" (command name)
# suffix usage: "", "-arm-linux-gnueabihf" => "gcc-8", "gcc-8-arm-linux-gnueabihf" (package name)
ARCH_PREFIX: "${{ (matrix.arch != '' && matrix.arch) || '' }}${{ (matrix.arch != '' && '-') || '' }}"
ARCH_SUFFIX: "${{ (matrix.arch != '' && '-') || '' }}${{ (matrix.arch != '' && matrix.arch) || '' }}"
steps:
- uses: actions/checkout@v2
- name: Setup Python
if: matrix.python_architecture != ''
id: setup-python
uses: actions/setup-python@v2
with:
python-version: 3.8
architecture: ${{ matrix.python_architecture }}
- run: mkdir download
# ONNX Runtime
- name: Export ONNX Runtime url to calc hash
shell: bash
run: echo "${{ matrix.onnxruntime_url }}" > download/onnxruntime_url.txt
- name: Cache ONNX Runtime
uses: actions/cache@v2
id: onnxruntime-cache
with:
key: onnxruntime-cache-v1-${{ hashFiles('download/onnxruntime_url.txt') }}
path: download/onnxruntime
# download/onnxruntime/lib/onnxruntime.dll
- name: Download ONNX Runtime (zip)
if: steps.onnxruntime-cache.outputs.cache-hit != 'true' && endsWith(matrix.onnxruntime_url, '.zip')
shell: bash
run: |
curl -L "${{ matrix.onnxruntime_url }}" > download/onnxruntime.zip
mkdir -p download/onnxruntime
# strip-components
TEMPDIR=$(mktemp -d)
unzip download/onnxruntime.zip -d "${TEMPDIR}"
mv "${TEMPDIR}"/*/* download/onnxruntime/
rm -rf "${TEMPDIR}"
rm download/onnxruntime.zip
# download/onnxruntime/lib/libonnxruntime.so
# download/onnxruntime/lib/libonnxruntime.dylib
- name: Download ONNX Runtime (tgz)
if: steps.onnxruntime-cache.outputs.cache-hit != 'true' && endsWith(matrix.onnxruntime_url, '.tgz')
shell: bash
run: |
curl -L "${{ matrix.onnxruntime_url }}" > download/onnxruntime.tgz
mkdir -p download/onnxruntime
tar xf download/onnxruntime.tgz -C download/onnxruntime --strip-components 1
rm download/onnxruntime.tgz
# Build
- if: startsWith(matrix.os, 'windows')
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.python_architecture }}
- if: startsWith(matrix.os, 'mac')
uses: jwlawson/actions-setup-cmake@v1.9
# gcc 7 (ubuntu-18.04 default) does not have stdc++fs
- name: Install build dependencies
if: startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y \
gcc-${{ matrix.cc_version }}${{ env.ARCH_SUFFIX }} \
g++-${{ matrix.cxx_version }}${{ env.ARCH_SUFFIX }} \
cmake
- name: Configure (Windows, macOS)
if: ${{ !startsWith(matrix.os, 'ubuntu') }} # '!' cannot be used as a first character in YAML
shell: bash
run: |
cmake -DONNXRUNTIME_DIR=download/onnxruntime ${{ matrix.cmake_additional_options }} .
- name: Configure (Linux)
if: startsWith(matrix.os, 'ubuntu')
shell: bash
env:
CC: ${{ env.ARCH_PREFIX }}gcc-${{ matrix.cc_version }}
CXX: ${{ env.ARCH_PREFIX }}g++-${{ matrix.cxx_version }}
run: |
cmake -DONNXRUNTIME_DIR=download/onnxruntime ${{ matrix.cmake_additional_options }} .
- name: Build
shell: bash
run: |
cmake --build . --config Release
# copy lib to core/lib/* and set rpath (linux)
cmake --install .
- name: Unit test ${{ matrix.python_architecture }}
if: matrix.python_architecture != ''
shell: bash
run: |
pip install -r requirements.txt
python setup.py test
- name: Organize artifact
shell: bash
run: |
mkdir artifact
# remove files with duplicate names to create a flat release archive
rm -vf core/lib/core.h core/lib/core.lib
# copy Windows DLL if exists
cp -v core/lib/core* artifact/ || true
# copy Linux/macOS shared library if exists
cp -v core/lib/libcore* artifact/ || true
# Upload
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.artifact_name }}-cpp-shared
path: artifact/*
retention-days: 7
# Create core.zip
upload-to-release-cpp-shared:
if: github.event.release.tag_name != ''
needs: [build-cpp-shared]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set BUILD_IDENTIFIER env var
run: |
echo "BUILD_IDENTIFIER=${GITHUB_REF##*/}" >> $GITHUB_ENV
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
zip
- name: Download and extract artifact
uses: actions/download-artifact@v2
with:
path: artifacts/
- name: Rearchive artifacts
run: |
mkdir release
readarray -t MAPPINGS <<EOF
windows-x64-gpu core.dll core_gpu_x64_nvidia.dll
windows-x64-cpu core.dll core_cpu_x64.dll
windows-x86-cpu core.dll core_cpu_x86.dll
windows-arm64-cpu core.dll core_cpu_arm64.dll
windows-arm-cpu core.dll core_cpu_arm.dll
osx-x64-cpu libcore.dylib libcore_cpu_x64.dylib
linux-x64-gpu libcore.so libcore_gpu_x64_nvidia.so
linux-x64-cpu libcore.so libcore_cpu_x64.so
linux-armhf-cpu libcore.so libcore_cpu_armhf.so
EOF
for line in "${MAPPINGS[@]}"; do
KND=$(echo $line | awk '$0=$1')
SRC=$(echo $line | awk '$0=$2')
DST=$(echo $line | awk '$0=$3')
if [ "${SRC}" = "${DST}" ]; then
echo "Skip renaming ${KND}/${SRC} => ${DST}"
continue
fi
echo "Renaming ${KND}/${SRC} => ${DST}"
mv -v "artifacts/${KND}-cpp-shared/${SRC}" "artifacts/${KND}-cpp-shared/${DST}"
done
mv -v artifacts/*-cpp-shared/* release/
cp core/src/core.h release/
echo "${{ env.BUILD_IDENTIFIER }}" > release/VERSION
cd release/
zip -r ../core.zip *
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: core
path: release/*
- name: Upload to Release
if: env.SKIP_UPLOADING_RELEASE_ASSET == '0'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref }} # ==> github.event.release.tag_name
file: core.zip