-
Notifications
You must be signed in to change notification settings - Fork 1
351 lines (333 loc) · 13 KB
/
toolchain.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
name: toolchain
run-name: "${{ inputs.run_name != '' && format('{0} ({1})', inputs.run_name, inputs.compiler) || format('{0} ({1})', github.workflow, inputs.compiler) }}"
on:
# schedule:
# - cron: '0 12 * * *'
workflow_dispatch:
inputs:
build_target:
description: "Build target"
required: false
default: "all-64bit"
type: choice
options:
- 32bit
- 64bit
- 64bit-v3
- all-64bit
- all
compiler:
required: false
default: "gcc"
type: choice
options:
- gcc
- clang
no_save_cache:
description: "Don't save caches after success build"
required: false
default: false
type: boolean
skip_llvm_build:
description: "Skip building llvm if compiler is clang"
required: false
default: false
type: boolean
trigger_build:
description: "Trigger mpv build action after success build"
required: false
default: true
type: boolean
release:
description: "Publish a release"
required: false
default: false
type: boolean
run_name:
description: 'The name displayed in the list of workflow runs'
required: false
jobs:
params:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.script.outputs.matrix }}
cache_suffix: ${{ steps.suffix.outputs.cache_suffix }}
steps:
- id: script
uses: actions/github-script@v7
with:
script: |
let matrix = {};
let build_target = "${{ inputs.build_target }}"
switch ( build_target ) {
case "32bit":
matrix.bit = ["32"];
break;
case "64bit":
matrix.bit = ["64"];
break;
case "64bit-v3":
matrix.bit = ["64-v3"];
break;
case "all-64bit":
matrix.bit = ["64","64-v3"];
break;
case "all":
matrix.bit = ["32","64","64-v3"];
break;
default:
matrix.bit = ["64","64-v3"];
break;
}
core.setOutput("matrix",JSON.stringify(matrix));
- id: suffix
run: |
cache_suffix="$(date "+%Y-%m-%d")-${{ github.run_id }}-${{ github.run_attempt }}"
echo "cache_suffix=$cache_suffix" >> "$GITHUB_OUTPUT"
build_llvm:
name: Build LLVM
needs: params
if: ${{ inputs.compiler =='clang' && inputs.skip_llvm_build != true }}
continue-on-error: true
runs-on: ubuntu-latest
container:
image: archlinux/archlinux:base-devel
steps:
- name: Install Dependencies
run: |
sudo echo -e "[multilib]\nInclude = /etc/pacman.d/mirrorlist" >> /etc/pacman.conf
sudo pacman -Syu --noconfirm
sudo pacman -S --noconfirm --needed git gyp ninja cmake ragel yasm nasm asciidoc enca gperf unzip xz gcc-multilib clang lld libc++ libc++abi python-pip curl lib32-glib2 wget python-cairo
mkdir -p /home/opt/7zip
wget -qO - https://www.7-zip.org/a/7z2301-linux-x64.tar.xz | tar -xJf - -C /home/opt/7zip 7zzs
sudo ln -s /home/opt/7zip/7zzs /usr/bin/7z
pip3 install -U --break-system-packages setuptools rst2pdf mako jsonschema meson
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global pull.rebase true
git config --global rebase.autoStash true
git config --global fetch.prune true
- name: Checkout toolchain
uses: actions/checkout@v4
with:
repository: shinchiro/mpv-winbuild-cmake
path: mpv-winbuild-cmake
- name: Build LLVM
shell: bash
run: |
cd mpv-winbuild-cmake
bit="64-v3"
compiler="${{ inputs.compiler }}"
gitdir=$(pwd)
clang_root=$(pwd)/clang_root
buildroot=$(pwd)
srcdir=$(pwd)/src_packages
arch="x86_64"
gcc_arch=-DGCC_ARCH=x86-64-v3
x86_64_level=-v3
set -x
if [[ "$(ls -A ../patch/*.patch)" ]]; then
for patch in ../patch/*.patch ; do
git am --3way "$patch" || git am --abort
done
fi
clang_option="-DCMAKE_INSTALL_PREFIX=$clang_root -DMINGW_INSTALL_PREFIX=$buildroot/build$bit/install/$arch-w64-mingw32"
cmake -DTARGET_ARCH=$arch-w64-mingw32 $gcc_arch -DCOMPILER_TOOLCHAIN=$compiler $clang_option -DSINGLE_SOURCE_LOCATION=$srcdir -DRUSTUP_LOCATION=$buildroot/install_rustup -G Ninja -H$gitdir -B$buildroot/build$bit
set +x
stdbuf -oL bash -c "ninja -C $buildroot/build$bit llvm" |
while IFS= read -r line
do
echo "$line"
if grep -q "ninja: build stopped" <<< "$line"; then
exit 1
fi
done
- name: Save llvm cache
uses: actions/cache/save@v4.0.0
with:
path: |
mpv-winbuild-cmake/clang_root
key: llvm-${{ needs.params.outputs.cache_suffix }}
- name: Collect logs
if: ${{ always() }}
run: |
sudo 7z a logs.7z $(find mpv-winbuild-cmake -type f -iname "*-*.log" -or -wholename "*/ffbuild/config.log")
- name: upload logs
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: llvm_logs
path: logs.7z
build:
name: Build Toolchain
needs: [params,build_llvm]
if: ${{ always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
runs-on: ubuntu-latest
container:
image: archlinux/archlinux:base-devel
continue-on-error: true
strategy:
matrix: ${{ fromJson(needs.params.outputs.matrix) }}
steps:
- name: Install Dependencies
run: |
sudo echo -e "[multilib]\nInclude = /etc/pacman.d/mirrorlist" >> /etc/pacman.conf
sudo pacman -Syu --noconfirm
sudo pacman -S --noconfirm --needed git gyp ninja cmake ragel yasm nasm asciidoc enca gperf unzip xz gcc-multilib clang lld libc++ libc++abi python-pip curl lib32-glib2 wget python-cairo
mkdir -p /home/opt/7zip
wget -qO - https://www.7-zip.org/a/7z2301-linux-x64.tar.xz | tar -xJf - -C /home/opt/7zip 7zzs
sudo ln -s /home/opt/7zip/7zzs /usr/bin/7z
pip3 install -U --break-system-packages setuptools rst2pdf mako jsonschema meson
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global pull.rebase true
git config --global rebase.autoStash true
git config --global fetch.prune true
- name: Checkout toolchain
uses: actions/checkout@v4
with:
repository: shinchiro/mpv-winbuild-cmake
path: mpv-winbuild-cmake
- name: Restore llvm cache
if: ${{ inputs.compiler =='clang' }}
uses: actions/cache/restore@v4.0.0
with:
fail-on-cache-miss: true
path: |
mpv-winbuild-cmake/clang_root
key: llvm-${{ needs.params.outputs.cache_suffix }}
restore-keys: |
llvm-
- name: Build Toolchain
shell: bash
run: |
cd mpv-winbuild-cmake
bit="${{ matrix.bit }}"
compiler="${{ inputs.compiler }}"
gitdir=$(pwd)
clang_root=$(pwd)/clang_root
buildroot=$(pwd)
srcdir=$(pwd)/src_packages
if [ $bit == "32" ]; then
arch="i686"
elif [ $bit == "64" ]; then
arch="x86_64"
elif [ $bit == "64-v3" ]; then
arch="x86_64"
gcc_arch=-DGCC_ARCH=x86-64-v3
x86_64_level=-v3
fi
set -x
if [[ "$(ls -A ../patch/*.patch)" ]]; then
for patch in ../patch/*.patch ; do
git am --3way "$patch" || git am --abort
done
fi
if [ "$compiler" == "gcc" ]; then
command="ninja -C $buildroot/build$bit gcc"
elif [ "$compiler" == "clang" ]; then
clang_option="-DCMAKE_INSTALL_PREFIX=$clang_root -DMINGW_INSTALL_PREFIX=$buildroot/build$bit/install/$arch-w64-mingw32"
command="ninja -C $buildroot/build$bit rebuild_cache && cmake --build $buildroot/build$bit --target llvm-download && ninja -C $buildroot/build$bit llvm-clang && ninja -C $buildroot/build$bit rustup"
fi
cmake -DTARGET_ARCH=$arch-w64-mingw32 $gcc_arch -DCOMPILER_TOOLCHAIN=$compiler $clang_option -DSINGLE_SOURCE_LOCATION=$srcdir -DRUSTUP_LOCATION=$buildroot/install_rustup -G Ninja -H$gitdir -B$buildroot/build$bit
set +x
stdbuf -oL bash -c "$command" |
while IFS= read -r line
do
echo "$line"
if grep -q "ninja: build stopped" <<< "$line"; then
exit 1
fi
done
ninja -C $buildroot/build$bit cargo-clean
- name: Save Toolchain Cache
if: ${{ inputs.no_save_cache != true }}
uses: actions/cache/save@v4.0.0
with:
path: ${{ github.workspace }}/mpv-winbuild-cmake/build${{ matrix.bit }}
key: toolchain-${{ inputs.compiler }}-build${{ matrix.bit }}-${{ needs.params.outputs.cache_suffix }}
- name: Save clang_root cache
if: ${{ inputs.compiler =='clang' && inputs.no_save_cache != true }}
uses: actions/cache/save@v4.0.0
with:
path: ${{ github.workspace }}/mpv-winbuild-cmake/clang_root
key: ${{ matrix.bit }}-clang_root-${{ needs.params.outputs.cache_suffix }}
- name: Save Rust Cache
if: ${{ inputs.no_save_cache != true }}
uses: actions/cache/save@v4.0.0
with:
path: ${{ github.workspace }}/mpv-winbuild-cmake/install_rustup
key: rust-${{ needs.params.outputs.cache_suffix }}
- name: Collect logs
if: ${{ always() }}
run: |
sudo 7z a logs.7z $(find mpv-winbuild-cmake -type f -iname "*-*.log" -or -wholename "*/ffbuild/config.log")
- name: upload logs
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: ${{ matrix.bit }}_logs
path: logs.7z
trigger:
needs: [build,params]
if: ${{ always() && inputs.trigger_build != false && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
runs-on: ubuntu-latest
steps:
- name: Trigger mpv build workflow
uses: actions/github-script@v7
with:
retries: 3
script: |
let build_target=new Set();
const release = ${{ inputs.release }};
const targets = {"build64-v3":"64bit-v3","build64":"64bit","build32":"32bit"}
const repo="${{github.repository}}".split('/')[1];
const cache_suffix="${{ needs.params.outputs.cache_suffix }}";
const cache = await github.rest.actions.getActionsCacheList({
owner: '${{github.repository_owner}}',
repo,
ref: '${{github.ref}}',
key: 'toolchain-${{ inputs.compiler }}-',
sort: 'created_at',
per_page: 20,
})
if(cache?.data?.actions_caches){
let success=cache.data.actions_caches.filter((i) => i.key.endsWith(cache_suffix));
for(const i of success){
for(const [key, value] of Object.entries(targets)){
if (i.key.includes(key)) {
build_target.add(value);
core.info(`Found success ${value} build cache: ${i.key}.`)
break;
}
}
}
}
if(build_target.size>0){
if(build_target.has("64bit-v3") && build_target.has("64bit")) {
build_target.delete("64bit-v3");
build_target.delete("64bit");
build_target.add("all-64bit");
}
if(build_target.has("all-64bit") && build_target.has("32bit")) {
build_target.delete("all-64bit");
build_target.delete("32bit");
build_target.add("all");
}
for (const t of build_target){
await github.rest.actions.createWorkflowDispatch({
owner: '${{github.repository_owner}}',
repo,
ref: '${{github.ref}}',
workflow_id: 'mpv.yml',
inputs: {
build_target: t,
compiler: "${{ inputs.compiler }}",
needclean: true,
release: release
}
})
}
} else {
core.setFailed("Don't find any success build cache");
}