-
Notifications
You must be signed in to change notification settings - Fork 114
448 lines (373 loc) · 16 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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
name: Build C++ Shared Library
on:
push:
branches:
# - main
pull_request:
release:
types:
- published
workflow_dispatch:
inputs:
version:
description: "バージョン情報(A.BB.C / A.BB.C-preview.D)"
required: true
code_signing:
description: "コード署名する"
type: boolean
env:
# releaseタグ名か、workflow_dispatchでのバージョン名か、DEBUGが入る
VERSION: ${{ github.event.release.tag_name || github.event.inputs.version || 'DEBUG' }}
# 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:
environment: ${{ github.event.inputs.code_signing == 'true' && 'code_signing' }} # コード署名用のenvironment(false時の挙動は2022年7月10日時点で未定義動作)
strategy:
fail-fast: false
matrix:
include:
- os: windows-2019
device: gpu
python_architecture: "x64"
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.10.0/onnxruntime-win-x64-gpu-1.10.0.zip
artifact_name: windows-x64-cuda
- os: windows-2019
device: cpu-x64
python_architecture: "x64"
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.10.0/onnxruntime-win-x64-1.10.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.10.0/onnxruntime-win-x86-1.10.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.10.0/onnxruntime-win-arm64-1.10.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.10.0/onnxruntime-win-arm-1.10.0.zip
cmake_additional_options: -DCMAKE_GENERATOR_PLATFORM=arm
artifact_name: windows-arm-cpu
- os: windows-2019
device: directml
python_architecture: "x64"
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.10.0/Microsoft.ML.OnnxRuntime.DirectML.1.10.0.zip
directml_url: https://www.nuget.org/api/v2/package/Microsoft.AI.DirectML/1.8.0
cmake_additional_options: -DDIRECTML=ON -DDIRECTML_DIR=download/directml
artifact_name: windows-x64-directml
- os: macos-10.15
device: cpu-x64
python_architecture: "x64"
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.10.0/onnxruntime-osx-universal2-1.10.0.tgz
artifact_name: osx-universal2-cpu
- os: ubuntu-18.04
device: gpu
python_architecture: "x64"
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.10.0/onnxruntime-linux-x64-gpu-1.10.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.10.0/onnxruntime-linux-x64-1.10.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.10.0.1/onnxruntime-linux-armhf-cpu-v1.10.0.tgz
artifact_name: linux-armhf-cpu
cc_version: "8"
cxx_version: "8"
arch: arm-linux-gnueabihf
- os: ubuntu-18.04
device: cpu-arm64
onnxruntime_url: https://github.com/VOICEVOX/onnxruntime-builder/releases/download/1.10.0.1/onnxruntime-linux-arm64-cpu-v1.10.0.tgz
artifact_name: linux-arm64-cpu
cc_version: "8"
cxx_version: "8"
arch: aarch64-linux-gnu
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
with:
submodules: true
- name: Setup Python
if: matrix.python_architecture != ''
id: setup-python
uses: actions/setup-python@v2
with:
python-version: 3.8
architecture: ${{ matrix.python_architecture }}
cache: pip
- 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
- name: Export DirectML url to calc hash
if: endswith(matrix.artifact_name, '-directml')
shell: bash
run: echo "${{matrix.directml_url}}" >> download/directml_url.txt
- name: Cache DirectML
if: endswith(matrix.artifact_name, '-directml')
uses: actions/cache@v2
id: directml-cache
with:
key: directml-cache-v1-${{ hashFiles('download/directml_url.txt') }}
path: download/directml
# 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}"
if [[ ${{ matrix.artifact_name }} != *-directml ]]; then
mv "${TEMPDIR}"/*/* download/onnxruntime/
else
mv "${TEMPDIR}"/* download/onnxruntime/
fi
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
# download directml
- name: Download DirectML
if: steps.directml-cache.outputs.cache-hit != 'true' && endswith(matrix.artifact_name, '-directml')
shell: bash
run: |
curl -L "${{matrix.directml_url}}" -o download/directml.zip
mkdir -p download/directml
# strip-components
TEMPDIR=$(mktemp -d)
unzip download/directml.zip -d "${TEMPDIR}"
mv "${TEMPDIR}"/* download/directml/.
rm -rf "${TEMPDIR}"
rm download/directml.zip
ls download/directml
# 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)
if: startsWith(matrix.os, 'windows')
shell: bash
run: |
cmake -DONNXRUNTIME_DIR=download/onnxruntime ${{ matrix.cmake_additional_options }} .
# libcore.dylib for macOS universal
- name: Configure (macOS)
if: startsWith(matrix.os, 'macos')
shell: bash
run: |
env CMAKE_OSX_ARCHITECTURES="x86_64;arm64" 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: Set ASSET_NAME env var
shell: bash
run: |
echo "ASSET_NAME=voicevox_core-${{ matrix.artifact_name }}-${{ env.VERSION }}" >> $GITHUB_ENV
- name: Organize artifact
shell: bash
run: |
mkdir -p "artifact/${{ env.ASSET_NAME }}"
# copy core.h (and Windows DLL if exists)
cp -v core/lib/core* "artifact/${{ env.ASSET_NAME }}" || true
# copy Linux/macOS shared library if exists
cp -v core/lib/libcore* "artifact/${{ env.ASSET_NAME }}" || true
echo "${{ env.VERSION }}" > "artifact/${{ env.ASSET_NAME }}/VERSION"
cp README.md "artifact/${{ env.ASSET_NAME }}/README.txt"
- name: Code signing (Windows)
if: startsWith(matrix.os, 'windows') && github.event.inputs.code_signing == 'true'
shell: bash
run: |
bash build_util/codesign.bash "artifact/${{ env.ASSET_NAME }}/core.dll"
env:
CERT_BASE64: ${{ secrets.CERT_BASE64 }}
CERT_PASSWORD: ${{ secrets.CERT_PASSWORD }}
# Upload
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.artifact_name }}-cpp-shared
path: artifact/${{ env.ASSET_NAME }}/*
retention-days: 7
- name: Archive artifact
if: env.VERSION != 'DEBUG' && !startsWith(matrix.os, 'windows-')
shell: bash
run: |
cd artifact
zip -r "../${{ env.ASSET_NAME }}.zip" "${{ env.ASSET_NAME }}"
- name: Archive artifact (Windows)
if: env.VERSION != 'DEBUG' && startsWith(matrix.os, 'windows-')
run: |
powershell Compress-Archive -Path "artifact/${{ env.ASSET_NAME }}" -DestinationPath "${{ env.ASSET_NAME }}.zip"
- name: Upload to Release
if: env.VERSION != 'DEBUG' && env.SKIP_UPLOADING_RELEASE_ASSET == '0'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
prerelease: true
tag: ${{ env.VERSION }}
file: ${{ env.ASSET_NAME }}.zip
build-win-cpp-example:
runs-on: windows-latest
needs: [build-cpp-shared]
env:
# Path to the solution file relative to the root of the project.
SOLUTION_FILE_PATH: example\cpp\windows\windows_example.sln
# Configuration type to build.
# You can convert this to a build matrix if you need coverage of multiple configuration types.
# https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
BUILD_CONFIGURATION: Release
steps:
- uses: actions/checkout@v3
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
- name: Restore NuGet packages
working-directory: ${{env.GITHUB_WORKSPACE}}
run: nuget restore ${{env.SOLUTION_FILE_PATH}}
- name: Download and extract artifact
uses: actions/download-artifact@v2
id: download
with:
name: windows-x64-cpu-cpp-shared
path: artifacts\
- name: Copy core.lib
working-directory: ${{env.GITHUB_WORKSPACE}}
run: |
mkdir example\cpp\windows\simple_tts\lib\x64
copy ${{steps.download.outputs.download-path}}\core.lib example\cpp\windows\simple_tts\lib\x64
- name: Build
working-directory: ${{env.GITHUB_WORKSPACE}}
# Add additional options to the MSBuild command line here (like platform or verbosity level).
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}
build-unix-cpp-example:
needs: [build-cpp-shared]
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
artifact_name: osx-universal2-cpu-cpp-shared
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.10.0/onnxruntime-osx-universal2-1.10.0.tgz
onnxruntime_lib_name: libonnxruntime.1.10.0.dylib
core_name: libcore.dylib
- os: ubuntu-latest
artifact_name: linux-x64-cpu-cpp-shared
onnxruntime_url: https://github.com/microsoft/onnxruntime/releases/download/v1.10.0/onnxruntime-linux-x64-1.10.0.tgz
onnxruntime_lib_name: libonnxruntime.so.1.10.0
core_name: libcore.so
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Download and extract artifact
uses: actions/download-artifact@v2
id: download
with:
name: ${{ matrix.artifact_name }}
path: artifacts/
- name: Copy core library
shell: bash
run: |
cp ${{ steps.download.outputs.download-path }}/${{ matrix.core_name }} example/cpp/unix
- 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/libonnxruntime.so
# download/onnxruntime/lib/libonnxruntime.dylib
- name: Download ONNX Runtime (tgz)
if: steps.onnxruntime-cache.outputs.cache-hit != 'true'
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
- name: Copy ONNX Runtime
shell: bash
run: |
cp download/onnxruntime/lib/${{ matrix.onnxruntime_lib_name }} example/cpp/unix
- if: startsWith(matrix.os, 'mac')
uses: jwlawson/actions-setup-cmake@v1.9
- name: Install build dependencies
if: startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y cmake
- name: Build
shell: bash
run: |
cd example/cpp/unix
cmake -S . -B build
cmake --build build