-
Notifications
You must be signed in to change notification settings - Fork 7
423 lines (371 loc) · 13.1 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
# Copyright (C) 2023 Toitware ApS.
#
# Use of this source code is governed by a BSD0-style license that can be
# found in the LICENSE_BSD0 file.
name: Build
on:
workflow_dispatch:
inputs:
build-esp32:
description: Build for ESP32
required: false
type: boolean
default: true
build-host:
description: Build for host
required: false
type: boolean
default: true
build-cross:
description: Build for cross
required: false
type: boolean
default: true
build-partitions:
description: Build partitions
required: false
type: boolean
default: true
toit-version:
description: Toit SDK version to check out
required: true
type: string
branch:
description: Branch to check out (overrides toit-version)
required: false
type: string
default: ""
upload-release:
description: Upload release artifacts
required: true
type: boolean
default: false
variant:
description: Variant to build
required: false
type: string
gist:
description: Link to gist with variant files
required: false
type: string
env:
# Toit currently supports the following architectures.
# See Toit's Makefile and search for 'TOITLANG_SYSROOTS'.
CROSS_ARCHS: aarch64 arm-linux-gnueabi armv7 raspbian
jobs:
build-esp32:
name: "Build ESP32 - ${{ github.event.inputs.toit-version }}"
if: ${{ github.event.inputs.build-esp32 == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Show inputs
run: echo "${{ toJSON(github.event.inputs) }}"
- uses: actions/checkout@v4
- name: Set the git version
run: |
echo "TOIT_GIT_VERSION=${{ github.event.inputs.toit-version }}" >> $GITHUB_ENV
- name: Fetch the Toit repository
run: |
# We allow the workflow dispatch to override the checked out branch.
# Note that we set the TOIT_GIT_VERSION env variable. The checked out branch
# thus doesn't influence the version of the SDK we build.
REF=${{ github.event.inputs.branch }}
if [[ -z "$REF" ]]; then
REF=${{ github.event.inputs.toit-version }}
fi
make TOIT_VERSION=$REF download-toit
- name: Setup build dependencies
uses: ./toit/actions/setup-build
with:
toit-dir: toit
esp32: true
- name: Ccache stats before SDK build
run: |
ccache -s
- name: Increase ccache max size
run: |
echo "CCACHE_MAXSIZE=600M" >> $GITHUB_ENV
- name: Build the host SDK
run: |
make build-host
- name: Ccache stats after SDK build
run: |
ccache -s
- name: Build the envelope tool
run: |
build/host/sdk/bin/toit pkg install --project-root=tools
build/host/sdk/bin/toit compile -o build/envelope-tool tools/main.toit
- name: Setting the variants
run: |
VARIANTS="${{ github.event.inputs.variant }}"
if [ -z "$VARIANTS" ]; then
if ! [ -z "${{ github.event.inputs.gist }}" ]; then
VARIANTS="gist"
else
VARIANTS=$(build/envelope-tool list)
if [ $? -ne 0 ]; then
echo "Failed to list variants"
exit 1
fi
fi
fi
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "VARIANTS<<$EOF" >> $GITHUB_ENV
echo "$VARIANTS" >> $GITHUB_ENV
echo "$EOF" >> $GITHUB_ENV
echo "VARIANTS_ROOT=variants" >> $GITHUB_ENV
- name: Download Gist
if: ${{ github.event.inputs.gist }}
run: |
GIST=${{ github.event.inputs.gist }}
mkdir -p "gist-variant/$VARIANTS"
build/envelope-tool download-gist -o "gist-variant/$VARIANTS" "$GIST"
echo "VARIANTS_ROOT=gist-variant" >> $GITHUB_ENV
find gist-variant
- name: Synthesize the variants
run: |
build/envelope-tool synthesize \
--ignore-errors \
--toit-root=toit \
--output-root=synthesized \
--sdk-path=build/host/sdk \
--variants-root=$VARIANTS_ROOT \
--build-root=build \
$VARIANTS
- name: Ccache stats before variants build
run: |
ccache -s
- name: Build the variants
run: |
for variant in $VARIANTS; do
mkdir -p build/$variant
if [ -e synthesized/$variant/failed ]; then
echo "Skipping $variant to due failed synthesis."
touch build/$variant/failed
continue
fi
ccache -s
(cd synthesized/$variant && make) || touch build/$variant/failed
done
- name: Ccache stats after variants build
run: |
ccache -s
- name: Prepare envelopes for upload
run: |
mkdir envelopes
for variant in $VARIANTS; do
if [ -e build/$variant/failed ]; then
echo "Skipping $variant"
continue
fi
cp build/$variant/firmware.envelope envelopes/firmware-$variant.envelope
gzip -9 envelopes/firmware-$variant.envelope
done
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts
path: |
envelopes
- name: Release
if: ${{ github.event.inputs.upload-release == 'true' }}
uses: ncipollo/release-action@v1
with:
artifacts: |
envelopes/*
body: |
Envelopes and partitions for Toit SDK ${{ github.event.inputs.toit-version }}
allowUpdates: true
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.inputs.toit-version }}
commit: main
- name: Report failed builds
if: ${{ github.event.inputs.upload-release == 'true' }}
run: |
build_failed=false
for variant in $VARIANTS; do
if [ -e build/$variant/failed ]; then
echo "Build of $variant failed"
build_failed=true
fi
done
if [ "$build_failed" = true ]; then
exit 1
fi
build-host:
if: ${{ github.event.inputs.build-host == 'true' }}
strategy:
matrix:
# ubuntu-20.04 so that we don't depend on a recent glibc.
# macos-13, since it's still intel based.
container: [ ubuntu-20.04, macos-13, macos-latest, windows-latest ]
architecture: [ x64 ]
include:
- container: ubuntu-20.04
architecture: x86
name: "Build ${{ matrix.container }} - ${{ matrix.architecture }} - ${{ github.event.inputs.toit-version }}"
runs-on: ${{ matrix.container }}
steps:
- uses: actions/checkout@v4
- name: Set the git version
run: |
echo "TOIT_GIT_VERSION=${{ github.event.inputs.toit-version }}" >> $GITHUB_ENV
- name: Fetch the Toit repository
shell: bash
run: |
# We allow the workflow dispatch to override the checked out branch.
# Note that we set the TOIT_GIT_VERSION env variable. The checked out branch
# thus doesn't influence the version of the SDK we build.
REF=${{ github.event.inputs.branch }}
if [[ -z "$REF" ]]; then
REF=${{ github.event.inputs.toit-version }}
fi
make TOIT_VERSION=$REF download-toit
- name: Setup build dependencies
uses: ./toit/actions/setup-build
with:
toit-dir: toit
cache-key-prefix: "cache-host"
- name: Build the host envelopes
shell: bash
run: |
if [[ ${{ matrix.architecture }} == 'x86' ]]; then
TARGET=host32;
else
TARGET=host;
fi
echo "HOST_TARGET=$TARGET" >> $GITHUB_ENV
make -C toit TARGET=$TARGET BUILD=$PWD/build build-envelope
- name: Prepare envelopes for upload
shell: bash
run: |
if [[ ${{ runner.os }} == 'Windows' ]]; then
variant="${{ matrix.architecture }}-windows"
elif [[ ${{ runner.os }} == 'macOS' ]]; then
if [[ ${{ matrix.container }} == 'macos-13' ]]; then
variant="x64-macos"
else
variant="aarch64-macos"
fi
else
variant="${{ matrix.architecture }}-linux"
fi
mkdir envelopes
mkdir snapshots
cp build/$HOST_TARGET/firmware.envelope envelopes/firmware-$variant.envelope
gzip -9 envelopes/firmware-$variant.envelope
cp build/$HOST_TARGET/generated/run_image.snapshot snapshots/run-image-$variant.snapshot
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts-host-${{ matrix.architecture }}-${{ matrix.container }}
path: |
envelopes
snapshots
- name: Release
if: ${{ github.event.inputs.upload-release == 'true' }}
uses: ncipollo/release-action@v1
with:
artifacts: |
envelopes/*
body: |
Envelopes and partition tables for Toit SDK ${{ github.event.inputs.toit-version }}
allowUpdates: true
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.inputs.toit-version }}
commit: main
build-cross:
name: "Build cross - ${{ github.event.inputs.toit-version }}"
if: ${{ github.event.inputs.build-cross == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set the git version
run: |
echo "TOIT_GIT_VERSION=${{ github.event.inputs.toit-version }}" >> $GITHUB_ENV
- name: Fetch the Toit repository
run: |
# We allow the workflow dispatch to override the checked out branch.
# Note that we set the TOIT_GIT_VERSION env variable. The checked out branch
# thus doesn't influence the version of the SDK we build.
REF=${{ github.event.inputs.branch }}
if [[ -z "$REF" ]]; then
REF=${{ github.event.inputs.toit-version }}
fi
make TOIT_VERSION=$REF download-toit
- name: Setup build dependencies
uses: ./toit/actions/setup-build
with:
toit-dir: toit
cache-key-prefix: "cache-cross"
- name: Build the cross envelopes
run: |
cd toit
for arch in $CROSS_ARCHS; do
make TARGET=$arch sdk
done
- name: Prepare envelopes for upload
run: |
mkdir envelopes
for arch in $CROSS_ARCHS; do
variant_arch=$arch
if [[ "$arch" == "arm-linux-gnueabi" ]]; then
variant_arch="arm-gnueabi"
elif [[ "$arch" == "raspbian" ]]; then
variant_arch="arm"
fi
cp toit/build/$arch/firmware.envelope envelopes/firmware-$variant_arch-linux.envelope
gzip -9 envelopes/firmware-$variant_arch-linux.envelope
done
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts-cross
path: |
envelopes
- name: Release
if: ${{ github.event.inputs.upload-release == 'true' }}
uses: ncipollo/release-action@v1
with:
artifacts: |
envelopes/*
body: |
Envelopes and partition tables for Toit SDK ${{ github.event.inputs.toit-version }}
allowUpdates: true
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.inputs.toit-version }}
commit: main
release-partition-tables:
name: "Release partition tables - ${{ github.event.inputs.toit-version }}"
if: ${{ github.event.inputs.build-partitions == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Show inputs
run: echo "${{ toJSON(github.event.inputs) }}"
- uses: actions/checkout@v4
- name: Set the git version
run: |
echo "TOIT_GIT_VERSION=${{ github.event.inputs.toit-version }}" >> $GITHUB_ENV
- name: Prepare partition tables
shell: bash
run: |
mkdir -p build
shopt -s nullglob
for csv_file in partitions/esp32/*/partitions.csv; do
variant=$(basename "$(dirname "$csv_file")")
if [ -e "partitions/esp32/$variant/partitions.csv" ]; then
cp "$csv_file" "build/partitions-esp32-$variant.csv"
fi
done
- name: Release
if: ${{ github.event.inputs.upload-release == 'true' }}
uses: ncipollo/release-action@v1
with:
artifacts: |
build/partitions-*.csv
body: |
Envelopes and partition tables for Toit SDK ${{ github.event.inputs.toit-version }}
allowUpdates: true
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.inputs.toit-version }}
commit: main