-
Notifications
You must be signed in to change notification settings - Fork 2
241 lines (197 loc) · 8.99 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
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: [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
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-x86_64.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 SuperGenius 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
if: ${{ matrix.target != 'OSX' && matrix.target != 'iOS' && matrix.target != 'Android' }}
run: cmake -S build/${{matrix.target}} -B $BUILD_DIRECTORY -DCMAKE_BUILD_TYPE=${{matrix.build-type}}
- name: Creating 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
run: |
declare -A target_shas
declare -A target_build_directories
while IFS=':' read -r file src_dir; do
target="${file%-source_dirinfo.txt}"
target="${target##*/}"
sha=$(git -C "$src_dir" rev-parse HEAD)
target_shas[$target]=$sha
build_directory="${file%%*/}"
target_build_directories[$target]=$build_directory
done < <(rg 'source_dir=(.*)' -u -r '$1' -g '*-source_dirinfo.txt')
if [ $(gh release view $RELEASE_TAG --json assets --jq "any(.assets[]; .name == \"release.json\")") ]; then
echo "Downloading release.json file"
gh release download $RELEASE_TAG --pattern "release.json" --clobber
fi
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=()
skipped_targets=()
for target in "${!target_shas[@]}"; do
if [[ -v release_shas["$target"] && "${target_shas[$target]}" == "${release_shas[$target]}" ]]; then
echo "Skipping $target due to same SHA from release"
skipped_targets+=("${target}")
else
echo "Adding $target to the update list"
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_ENV
echo "SHA_OF_TARGETS_TO_UPDATE=${sha_of_targets_to_update[@]}" >>$GITHUB_ENV
echo "BUILD_DIRECTORIES_OF_TARGETS_TO_UPDATE=${build_directories_of_targets_to_update[@]}" >>$GITHUB_ENV
echo "SKIPPED_TARGETS=${skipped_targets}" >>$GITHUB_ENV
shell: bash
- name: Build targets in POSIX hosts
if: ${{matrix.host != 'Windows'}}
run: |
for target in "${targets_to_update[@]}"; do
echo Building ${target}
cmake --build . --target ${target} -j
done
- name: Build targets in Windows host
if: ${{matrix.host == 'Windows'}}
run: |
foreach ($target in $targets_to_update) {
Write-Host "Building $target"
cmake --build . --target $target -j
}
- name: Compress and upload targets
run: |
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
for i in "${!TARGETS_TO_UPDATE[@]}"; do
target=${TARGETS_TO_UPDATE[$i]}
compressed_file="${target}-lib.tar.gz"
directory_to_compress="${BUILD_DIRECTORIES_OF_TARGETS_TO_UPDATE[$i]}"
echo Compressing ${target}
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_TO_UPDATE[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