-
Notifications
You must be signed in to change notification settings - Fork 2
282 lines (228 loc) · 10.6 KB
/
build-targets.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
name: Multiplatform build and upload
on:
workflow_dispatch:
env:
GH_TOKEN: ${{ secrets.GNUS_TOKEN_1 }}
jobs:
build:
env:
GRPC_BUILD_ENABLE_CCACHE: "ON"
runs-on: ${{matrix.host}}
strategy:
fail-fast: false
matrix:
target: [Android, iOS, OSX, Linux, Windows]
build-type: [Debug, Release]
include:
- target: Linux
host: ubuntu-latest
- target: Windows
host: windows-latest
- target: OSX
host: macos-latest
- target: Android
host: ubuntu-latest
abi: arm64-v8a
- target: iOS
host: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: "recursive"
- name: Configure Linux host
if: ${{ matrix.host == 'ubuntu-latest'}}
run: |
sudo update-alternatives --install /usr/bin/cc cc $(which clang) 100
sudo update-alternatives --install /usr/bin/c++ c++ $(which clang++) 100
sudo update-alternatives --set cc $(which clang)
sudo update-alternatives --set c++ $(which clang++)
sudo apt install ccache libvulkan-dev ninja-build ripgrep -y
echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV
- name: Configure Windows host
if: ${{ matrix.host == 'windows-latest'}}
run: |
choco install ccache ripgrep -A
- name: Configure macOS host
if: ${{ matrix.host == 'macos-latest'}}
run: |
brew install ccache ninja ripgrep bash
echo "CMAKE_GENERATOR=Ninja" >> $GITHUB_ENV
- name: Add Darwin toolchain
if: ${{ matrix.target == 'OSX'}}
run: rustup target add x86_64-apple-darwin
- name: Add iOS toolchain
if: ${{ matrix.target == 'iOS' }}
run: |
rustup toolchain install nightly-aarch64-apple-darwin
rustup component add rust-src --toolchain nightly-aarch64-apple-darwin
rustup target add aarch64-apple-ios
- name: Add Android toolchain
if: ${{ matrix.target == 'Android' }}
run: |
NDK_VERSION="r27b"
wget https://dl.google.com/android/repository/android-ndk-$NDK_VERSION-linux.zip -O ndk.zip
unzip ndk.zip -d $HOME
echo "ANDROID_NDK_HOME=$HOME/android-ndk-$NDK_VERSION" >> $GITHUB_ENV
rustup target add aarch64-linux-android
- name: Install bindgen
run: cargo install cbindgen
- name: Add wasm Rust target
run: rustup target add wasm32-unknown-emscripten
- name: Set build directory
run: |
if ${{matrix.target == 'Android'}}; then
BUILD_DIRECTORY=build/${{matrix.target}}/${{matrix.build-type}}/${{matrix.abi}}
else
BUILD_DIRECTORY=build/${{matrix.target}}/${{matrix.build-type}}
fi
echo "BUILD_DIRECTORY=$BUILD_DIRECTORY" >> $GITHUB_ENV
shell: bash
- name: Configure CMake for Mac x86
if: ${{ matrix.target == 'OSX'}}
run: cmake -S build/${{matrix.target}} -B $BUILD_DIRECTORY -DCMAKE_BUILD_TYPE=${{matrix.build-type}} -DPLATFORM=MAC
- name: Configure CMake for iOS
if: ${{ matrix.target == 'iOS'}}
run: cmake -S build/${{matrix.target}} -B $BUILD_DIRECTORY -DCMAKE_BUILD_TYPE=${{matrix.build-type}} -DPLATFORM=OS64
- name: Configure CMake for Android
if: ${{ matrix.target == 'Android'}}
run: cmake -S build/${{matrix.target}} -B $BUILD_DIRECTORY -DCMAKE_BUILD_TYPE=${{matrix.build-type}} -DANDROID_ABI=${{matrix.abi}}
- name: Configure CMake for Windows
if: ${{ matrix.target == 'Windows' }}
run: cmake -S build/${{matrix.target}} -B $env:BUILD_DIRECTORY -DCMAKE_BUILD_TYPE=${{matrix.build-type}}
- name: Configure CMake for Linux
if: ${{ matrix.target == 'Linux' }}
run: cmake -S build/${{matrix.target}} -B $BUILD_DIRECTORY -DCMAKE_BUILD_TYPE=${{matrix.build-type}}
- name: Create release tag
id: create-release-tag
run: |
RELEASE_TAG='${{matrix.target}}-${{ github.ref_name }}-${{matrix.build-type}}'
echo "RELEASE_TAG=${RELEASE_TAG}" >> $GITHUB_ENV
echo "Check if GitHub release tag $RELEASE_TAG available."
set +e
gh release view $RELEASE_TAG
releaseFound=$?
set -e
if [[ $releaseFound -ne 0 ]]; then
echo "Release not found, creating with tag: $RELEASE_TAG"
RELEASE_TYPE="--latest"
if [ '${{ matrix.build-type }}' != 'Release' ]; then
RELEASE_TYPE="--prerelease"
fi
# Create release on GitHub
gh release create $RELEASE_TAG \
-n '${{ github.ref_name }} branch' \
--target '${{ github.ref_name }}' \
${RELEASE_TYPE} \
-t '${{ matrix.target }} ${{ github.ref_name }} branch ${{ matrix.build-type }} build'
fi
shell: bash
- name: Check which targets need updating
id: check-targets
working-directory: ${{env.BUILD_DIRECTORY}}
run: |
declare -A target_shas
declare -A target_build_directories
echo Detecting targets:
while IFS=':' read -r file src_dir; do
if ${{matrix.host == 'windows-latest'}}; then
file=$(cygpath -u ${file})
src_dir=$(cygpath -u ${src_dir})
fi
target="${file%-source_dirinfo.txt}"
target="${target##*/}"
echo ${target}: ${src_dir}
sha=$(git -C ${src_dir} rev-parse HEAD)
target_shas[$target]=$sha
build_directory=$(echo $file | sed 's|^\(\./[^/]*\).*|\1|')
target_build_directories[$target]=$build_directory
done < <(rg 'source_dir=(.*)' -u -r '$1' -g '*-source_dirinfo.txt' .)
echo "\nDownloading release.json file"
set +e
gh release download $RELEASE_TAG --pattern "release.json" --clobber
set -e
declare -A release_shas
if [[ -f "release.json" ]]; then
while IFS="=" read -r target sha; do
release_shas[$target]=$sha
done < <(jq -r '.[] | "\(.name)=\(.sha)"' release.json)
fi
targets_to_update=()
sha_of_targets_to_update=()
build_directories_of_targets_to_update=()
up_to_date_targets=()
echo "\nChecking SHAs:"
for target in "${!target_shas[@]}"; do
if [[ -v release_shas["$target"] && "${target_shas[$target]}" == "${release_shas[$target]}" ]]; then
echo "$target: up to date"
up_to_date_targets+=("${target}")
else
echo "$target: out of date"
targets_to_update+=("${target}")
sha_of_targets_to_update+=("${target_shas[$target]}")
build_directories_of_targets_to_update+=("${target_build_directories[$target]}")
fi
done
echo "TARGETS_TO_UPDATE=${targets_to_update[@]}" >>$GITHUB_OUTPUT
echo "SHA_OF_TARGETS_TO_UPDATE=${sha_of_targets_to_update[@]}" >>$GITHUB_OUTPUT
echo "BUILD_DIRECTORIES_OF_TARGETS_TO_UPDATE=${build_directories_of_targets_to_update[@]}" >>$GITHUB_OUTPUT
echo "UP_TO_DATE_TARGETS=${up_to_date_targets}" >>$GITHUB_OUTPUT
shell: bash
- name: Download up to date targets
working-directory: ${{env.BUILD_DIRECTORY}}
run: |
up_to_date_targets=(${{steps.check-targets.outputs.UP_TO_DATE_TARGETS}})
for target in "${up_to_date_targets[@]}"; do
compressed_target="${target}-lib.tar.gz"
echo Downloading ${compressed_target}
gh release download ${RELEASE_TAG} --pattern "${compressed_target}" --clobber
tar -xzf ${compressed_target}
done
shell: bash
- name: Build targets in POSIX hosts
working-directory: ${{env.BUILD_DIRECTORY}}
if: ${{matrix.host != 'windows-latest'}}
run: |
targets_to_update=(${{steps.check-targets.outputs.TARGETS_TO_UPDATE}})
for target in "${targets_to_update[@]}"; do
echo Building ${target}
cmake --build . --target ${target} -j
done
- name: Build targets in Windows host
working-directory: ${{env.BUILD_DIRECTORY}}
if: ${{matrix.host == 'windows-latest'}}
run: |
$targets_to_update = "${{steps.check-targets.outputs.TARGETS_TO_UPDATE}}" -split ' '
foreach ($target in $targets_to_update) {
Write-Host "Building $target"
cmake --build . --target $target -j
}
- name: Compress and upload targets
working-directory: ${{env.BUILD_DIRECTORY}}
run: |
targets_to_update=(${{steps.check-targets.outputs.TARGETS_TO_UPDATE}})
build_directories=(${{steps.check-targets.outputs.BUILD_DIRECTORIES_OF_TARGETS_TO_UPDATE}})
sha_of_targets=(${{steps.check-targets.outputs.SHA_OF_TARGETS_TO_UPDATE}})
declare -A release_shas
if [[ -f "release.json" ]]; then
while IFS="=" read -r target sha; do
release_shas[$target]=$sha
done < <(jq -r '.[] | "\(.name)=\(.sha)"' release.json)
fi
echo Compressing targets
for i in "${!targets_to_update[@]}"; do
target=${targets_to_update[$i]}
compressed_file="${target}-lib.tar.gz"
directory_to_compress=$(basename "${build_directories[$i]}")
echo ${target}: $directory_to_compress
tar --exclude="${directory_to_compress}/src" --exclude="${directory_to_compress}/tmp" -czf ${compressed_file} ${directory_to_compress}
echo -e "Uploading ${compressed_file}\n"
gh release upload --clobber ${RELEASE_TAG} ${compressed_file}
release_shas[${target}]="${sha_of_targets[i]}"
done
json_data=$(for key in "${!release_shas[@]}"; do
printf '{"name": "%s", "sha": "%s"}\n' "$key" "${release_shas[$key]}"
done | jq -s '.')
echo "$json_data" >release.json
gh release upload --clobber ${RELEASE_TAG} release.json
shell: bash