-
Notifications
You must be signed in to change notification settings - Fork 15
165 lines (141 loc) · 6.33 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
name: Build C++ Shared Library
on:
push:
branches:
# - main
release:
types:
- published
workflow_dispatch:
jobs:
build-onnxruntime:
strategy:
fail-fast: false
matrix:
include:
- artifact_name: onnxruntime-linux-armhf-cpu
os: ubuntu-18.04
cc_version: '8'
cxx_version: '8'
arch: arm-linux-gnueabihf
ld_symlink_name: ld-linux-armhf.so.3
build_opts: --arm --cmake_extra_defines CMAKE_SYSTEM_NAME=Linux CMAKE_SYSTEM_PROCESSOR=armv7l --use_openmp --config Release --parallel --update --build --build_shared_lib
result_dir: build/Linux/Release
env:
ONNXRUNTIME_VERSION: v1.10.0
# 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) || '' }}"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
repository: microsoft/onnxruntime
submodules: true
ref: ${{ env.ONNXRUNTIME_VERSION }}
- name: Dump matrix context
env:
MATRIX_CONTEXT: ${{ toJSON(matrix) }}
run: echo "$MATRIX_CONTEXT" > matrix.json
- name: Cache build result
id: cache-build-result
uses: actions/cache@v2
with:
path: build/
key: ${{ matrix.artifact_name }}-${{ env.ONNXRUNTIME_VERSION }}-cache-v1-${{ hashFiles('matrix.json') }}
- name: Install build dependencies
if: steps.cache-build-result.outputs.cache-hit != 'true'
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
git \
wget \
qemu-user-binfmt \
gcc-${{ matrix.cc_version }}${{ env.ARCH_SUFFIX }} \
g++-${{ matrix.cxx_version }}${{ env.ARCH_SUFFIX }} \
python3
# ONNX Runtime v1.9.0 requires CMake 3.18 or higher.
- name: Install CMake
if: steps.cache-build-result.outputs.cache-hit != 'true'
env:
CMAKE_VERSION: 3.22.0-rc2
run: |
wget -O cmake.sh "https://github.com/Kitware/CMake/releases/download/v${{ env.CMAKE_VERSION }}/cmake-${{ env.CMAKE_VERSION }}-linux-x86_64.sh"
sudo bash cmake.sh --skip-license --prefix=/usr/local
- name: Configure build environment
if: steps.cache-build-result.outputs.cache-hit != 'true'
run: |
# Required for arm build
# https://github.com/microsoft/onnxruntime/issues/4189#issuecomment-642528278
echo 'string(APPEND CMAKE_C_FLAGS " -latomic")' >> cmake/CMakeLists.txt
echo 'string(APPEND CMAKE_CXX_FLAGS " -latomic")' >> cmake/CMakeLists.txt
# Prevent Exec Format Error during cross-compiling
if [ -n "${{ matrix.ld_symlink_name }}" ]; then
sudo ln -s /usr/${{ matrix.arch }}/lib /lib/${{ matrix.arch }}
sudo ln -s /lib/${{ matrix.arch }}/ld-*.so /lib/${{ matrix.ld_symlink_name }}
fi
- name: Build ONNX Runtime
if: steps.cache-build-result.outputs.cache-hit != 'true'
env:
CC: ${{ env.ARCH_PREFIX }}gcc-${{ matrix.cc_version }}
CXX: ${{ env.ARCH_PREFIX }}g++-${{ matrix.cxx_version }}
run: |
# add --arm for gcc-8: https://github.com/microsoft/onnxruntime/issues/4189
# skip test: https://github.com/microsoft/onnxruntime/issues/2436
# ONNX Runtime v1.9.0 requires CMAKE_SYSTEM_PROCESSOR, https://github.com/microsoft/onnxruntime/releases/tag/v1.9.0
# Both CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR are required.
bash ./build.sh ${{ matrix.build_opts }}
- name: Organize artifact
run: |
mkdir artifact
# copy shared lib
mkdir artifact/lib
NAME=$(basename ${{ matrix.result_dir }}/libonnxruntime.so.*)
cp "${{ matrix.result_dir }}/${NAME}" artifact/lib/
ln -s "${NAME}" artifact/lib/libonnxruntime.so
# copy header files
mkdir artifact/include
readarray -t HEADERS <<EOF
onnxruntime/core/session/onnxruntime_c_api.h
onnxruntime/core/session/onnxruntime_cxx_api.h
onnxruntime/core/session/onnxruntime_cxx_inline.h
onnxruntime/core/providers/cpu/cpu_provider_factory.h
onnxruntime/core/session/onnxruntime_session_options_config_keys.h
onnxruntime/core/session/onnxruntime_run_options_config_keys.h
onnxruntime/core/framework/provider_options.h
EOF
for path in "${HEADERS[@]}"; do
cp "include/${path}" ./artifact/include/
done
# copy docs & license
cp VERSION_NUMBER ./artifact/
cp LICENSE ./artifact/
cp ThirdPartyNotices.txt ./artifact/
cp docs/Privacy.md ./artifact/
cp README.md ./artifact/
echo "$(git rev-parse HEAD)" >> ./artifact/GIT_COMMIT_ID
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.artifact_name }}
path: artifact/*
retention-days: 14
- name: Generate RELEASE_NAME
if: github.event.release.tag_name != '' # If release
run: |
echo "RELEASE_NAME=${{ matrix.artifact_name }}-${{ env.ONNXRUNTIME_VERSION }}" >> $GITHUB_ENV
- name: Rearchive artifact
if: github.event.release.tag_name != '' # If release
run: |
mv artifact/ "${{ env.RELEASE_NAME }}"
tar cfz "${{ env.RELEASE_NAME }}.tgz" "${{ env.RELEASE_NAME }}/"
- name: Upload to Release
if: github.event.release.tag_name != '' # If release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref }} # ==> github.event.release.tag_name
file: ${{ env.RELEASE_NAME }}.tgz