Build #192
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
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 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 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 for Toit SDK ${{ github.event.inputs.toit-version }} | |
allowUpdates: true | |
token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ github.event.inputs.toit-version }} | |
commit: main |