Skip to content

Commit 6154116

Browse files
committed
CI: Move build steps to a bash script.
1 parent d45daef commit 6154116

File tree

3 files changed

+122
-110
lines changed

3 files changed

+122
-110
lines changed

.github/workflows/micropython.yml

Lines changed: 39 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,10 @@ on:
88

99
env:
1010
MICROPYTHON_VERSION: v1.22.1
11-
WORKFLOW_VERSION: v1
1211

1312
jobs:
14-
deps:
15-
runs-on: ubuntu-20.04
16-
name: Dependencies
17-
steps:
18-
- name: Workspace Cache
19-
id: cache
20-
uses: actions/cache@v3
21-
with:
22-
path: ${{runner.workspace}}
23-
key: workspace-micropython-${{env.MICROPYTHON_VERSION}}-${{env.WORKFLOW_VERSION}}
24-
restore-keys: |
25-
workspace-micropython-${{env.MICROPYTHON_VERSION}}-${{env.WORKFLOW_VERSION}}
26-
27-
# Check out MicroPython
28-
- name: Checkout MicroPython
29-
if: steps.cache.outputs.cache-hit != 'true'
30-
uses: actions/checkout@v3
31-
with:
32-
repository: micropython/micropython
33-
ref: ${{env.MICROPYTHON_VERSION}}
34-
submodules: false # MicroPython submodules are hideously broken
35-
path: micropython
36-
37-
# Check out MicroPython Libs
38-
- name: Checkout MicroPython Libs
39-
if: steps.cache.outputs.cache-hit != 'true'
40-
uses: actions/checkout@v3
41-
with:
42-
repository: micropython/micropython-lib
43-
path: micropython-lib
44-
45-
- name: Fetch Pico submodules
46-
if: steps.cache.outputs.cache-hit != 'true'
47-
shell: bash
48-
working-directory: micropython/ports/rp2
49-
run: |
50-
git submodule update --init ../../lib/pico-sdk
51-
git submodule update --init ../../lib/cyw43-driver
52-
git submodule update --init ../../lib/lwip
53-
git submodule update --init ../../lib/mbedtls
54-
git submodule update --init ../../lib/micropython-lib
55-
git submodule update --init ../../lib/tinyusb
56-
git submodule update --init ../../lib/btstack
57-
58-
- name: Build mpy-cross
59-
if: steps.cache.outputs.cache-hit != 'true'
60-
shell: bash
61-
working-directory: micropython/mpy-cross
62-
run: make
63-
6413
build:
65-
needs: deps
66-
name: ${{matrix.name}} (${{matrix.board}})
14+
name: ${{ matrix.name }} (${{ matrix.board }})
6715
runs-on: ubuntu-20.04
6816
strategy:
6917
matrix:
@@ -82,7 +30,6 @@ jobs:
8230
board: PIMORONI_TUFTY2040
8331
- name: enviro
8432
board: PICO_W_ENVIRO
85-
patch: true
8633
- name: galactic_unicorn
8734
board: RPI_PICO_W
8835
- name: cosmic_unicorn
@@ -91,93 +38,81 @@ jobs:
9138
board: RPI_PICO_W
9239
- name: inky_frame
9340
board: PICO_W_INKY
94-
patch: true
9541

9642
env:
9743
# MicroPython version will be contained in github.event.release.tag_name for releases
98-
RELEASE_FILE: pimoroni-${{matrix.name}}-${{github.event.release.tag_name || github.sha}}-micropython
99-
MICROPY_BOARD_DIR: "$GITHUB_WORKSPACE/pimoroni-pico-${{ github.sha }}/micropython/board/${{ matrix.BOARD }}"
100-
USER_C_MODULES: "$GITHUB_WORKSPACE/pimoroni-pico-${{ github.sha }}/micropython/modules/micropython-${{matrix.name}}.cmake"
44+
RELEASE_FILE: pimoroni-${{ matrix.name }}-${{ github.event.release.tag_name || github.sha }}-micropython
45+
PIMORONI_PICO_DIR: "${{ github.workspace }}/pimoroni-pico-${{ github.sha }}"
46+
MICROPY_BOARD_DIR: "${{ github.workspace }}/pimoroni-pico-${{ github.sha }}/micropython/board/${{ matrix.BOARD }}"
47+
USER_C_MODULES: "${{ github.workspace }}/pimoroni-pico-${{ github.sha }}/micropython/modules/micropython-${{ matrix.name }}.cmake"
48+
TAG_OR_SHA: ${{ github.event.release.tag_name || github.sha }}
49+
MICROPY_BOARD: ${{ matrix.board }}
50+
BOARD_NAME: ${{ matrix.name }}
51+
BUILD_TOOLS: pimoroni-pico-${{ github.sha }}/ci/micropython.sh
10152

10253
steps:
10354
- name: Compiler Cache
10455
uses: actions/cache@v3
10556
with:
10657
path: /home/runner/.ccache
107-
key: ccache-micropython-${{matrix.name}}-${{github.ref}}-${{github.sha}}
58+
key: ccache-micropython-${{ matrix.name }}-${{ github.ref }}-${{ github.sha }}
10859
restore-keys: |
109-
ccache-micropython-${{matrix.name}}-${{github.ref}}
110-
ccache-micropython-${{matrix.name}}-
60+
ccache-micropython-${{ matrix.name }}-${{ github.ref }}
61+
ccache-micropython-${{ matrix.name }}-
11162
112-
- name: Workspace Cache
113-
uses: actions/cache@v3
114-
with:
115-
path: ${{runner.workspace}}
116-
key: workspace-micropython-${{env.MICROPYTHON_VERSION}}-${{env.WORKFLOW_VERSION}}
117-
restore-keys: |
118-
workspace-micropython-${{env.MICROPYTHON_VERSION}}-${{env.WORKFLOW_VERSION}}
119-
120-
- name: Install Compiler & CCache
121-
if: runner.os == 'Linux'
122-
run: |
123-
sudo apt update && sudo apt install ccache gcc-arm-none-eabi
124-
125-
- uses: actions/checkout@v3
63+
- uses: actions/checkout@v4
12664
with:
12765
submodules: true
12866
path: pimoroni-pico-${{ github.sha }}
129-
130-
- name: Set MicroPython Version Env Vars
131-
shell: bash
67+
68+
- name: Install Compiler & CCache
13269
run: |
133-
echo "MICROPY_GIT_TAG=$MICROPYTHON_VERSION, ${{matrix.name}} ${{github.event.release.tag_name || github.sha}}" >> $GITHUB_ENV
134-
echo "MICROPY_GIT_HASH=$MICROPYTHON_VERSION-${{github.event.release.tag_name || github.sha}}" >> $GITHUB_ENV
70+
source $BUILD_TOOLS
71+
build_deps
72+
73+
- name: Checkout MicroPython & MicroPython Libs
74+
run: |
75+
source $BUILD_TOOLS
76+
clone_micropython_lib
77+
clone_micropython
13578
13679
- name: "HACK: CMakeLists.txt Disable C++ Exceptions Patch"
13780
shell: bash
138-
working-directory: micropython
139-
run: git apply $GITHUB_WORKSPACE/pimoroni-pico-${{ github.sha }}/micropython/micropython_nano_specs.patch
81+
run: |
82+
source $BUILD_TOOLS
83+
hack_patch_micropython_disable_exceptions
14084
14185
- name: "HACK: Pico SDK Patch"
142-
if: matrix.patch == true
14386
shell: bash
144-
working-directory: micropython
14587
run: |
146-
$GITHUB_WORKSPACE/pimoroni-pico-${{ github.sha }}/micropython/board/pico-sdk-patch.sh ${{matrix.board}}
88+
source $BUILD_TOOLS
89+
hack_patch_pico_sdk
14790
14891
- name: Configure MicroPython
14992
shell: bash
150-
working-directory: micropython/ports/rp2
151-
run: |
152-
cmake -S . -B build-${{matrix.name}} -DPICO_BUILD_DOCS=0 -DUSER_C_MODULES=${{env.USER_C_MODULES}} -DMICROPY_BOARD_DIR=${{env.MICROPY_BOARD_DIR}} -DMICROPY_BOARD=${{matrix.board}} -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
153-
154-
- name: Build MicroPython # Multiple simultaneous jobs trigger https://github.com/pimoroni/pimoroni-pico/issues/761
155-
shell: bash
156-
working-directory: micropython/ports/rp2
15793
run: |
158-
ccache --zero-stats || true
159-
cmake --build build-${{matrix.name}} -j 1
160-
ccache --show-stats || true
94+
source $BUILD_TOOLS
95+
cmake_configure
16196
162-
- name: Rename .uf2 for artifact
97+
- name: Build MicroPython
16398
shell: bash
164-
working-directory: micropython/ports/rp2/build-${{matrix.name}}
16599
run: |
166-
cp firmware.uf2 $RELEASE_FILE.uf2
100+
source $BUILD_TOOLS
101+
cmake_build
167102
168103
- name: Store .uf2 as artifact
169104
uses: actions/upload-artifact@v3
170105
with:
171-
name: ${{env.RELEASE_FILE}}.uf2
172-
path: micropython/ports/rp2/build-${{matrix.name}}/${{env.RELEASE_FILE}}.uf2
106+
name: ${{ env.RELEASE_FILE }}.uf2
107+
path: build-${{ matrix.name }}/${{ env.RELEASE_FILE }}.uf2
173108

174109
- name: Upload .uf2
175110
if: github.event_name == 'release'
176111
uses: actions/upload-release-asset@v1
177112
env:
178-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
113+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
179114
with:
180-
asset_path: micropython/ports/rp2/build-${{matrix.name}}/firmware.uf2
181-
upload_url: ${{github.event.release.upload_url}}
182-
asset_name: ${{env.RELEASE_FILE}}.uf2
115+
asset_path: build-${{ matrix.name }}/firmware.uf2
116+
upload_url: ${{ github.event.release.upload_url }}
117+
asset_name: ${{ env.RELEASE_FILE }}.uf2
183118
asset_content_type: application/octet-stream

ci/micropython.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
export TERM=${TERM:="xterm-256color"}
2+
3+
function log_success {
4+
echo -e "$(tput setaf 2)$1$(tput sgr0)"
5+
}
6+
7+
function log_inform {
8+
echo -e "$(tput setaf 6)$1$(tput sgr0)"
9+
}
10+
11+
function log_warning {
12+
echo -e "$(tput setaf 1)$1$(tput sgr0)"
13+
}
14+
15+
function clone_micropython_lib {
16+
git clone https://github.com/micropython/micropython-lib --depth=1
17+
}
18+
19+
function clone_micropython {
20+
log_inform "Using MicroPython $MICROPYTHON_VERSION"
21+
git clone https://github.com/micropython/micropython --depth=1 --branch=$MICROPYTHON_VERSION
22+
cd micropython
23+
git submodule update --init lib/pico-sdk
24+
git submodule update --init lib/cyw43-driver
25+
git submodule update --init lib/lwip
26+
git submodule update --init lib/mbedtls
27+
git submodule update --init lib/micropython-lib
28+
git submodule update --init lib/tinyusb
29+
git submodule update --init lib/btstack
30+
cd mpy-cross
31+
make
32+
cd ../../
33+
}
34+
35+
function build_deps {
36+
sudo apt update && sudo apt install ccache gcc-arm-none-eabi
37+
}
38+
39+
function clone_pimoroni_pico {
40+
git clone https://github.com/micropython/micropython --branch=$PIMORONI_PICO_SHA --depth=1
41+
}
42+
43+
function micropython_version {
44+
echo "MICROPY_GIT_TAG=\"$MICROPYTHON_VERSION, $BOARD_NAME $TAG_OR_SHA\"" >> $GITHUB_ENV
45+
echo "MICROPY_GIT_HASH=\"$MICROPYTHON_VERSION-$TAG_OR_SHA\"" >> $GITHUB_ENV
46+
}
47+
48+
function hack_patch_micropython_disable_exceptions {
49+
cd micropython
50+
git apply $PIMORONI_PICO_DIR/micropython/micropython_nano_specs.patch
51+
cd ../
52+
}
53+
54+
function hack_patch_pico_sdk {
55+
# pico-sdk-patch.sh will apply the patch if it exists
56+
cd micropython
57+
$PIMORONI_PICO_DIR/micropython/board/pico-sdk-patch.sh $MICROPY_BOARD
58+
cd ../
59+
}
60+
61+
function cmake_configure {
62+
cmake -S micropython/ports/rp2 -B build-$BOARD_NAME \
63+
-DPICO_BUILD_DOCS=0 \
64+
-DUSER_C_MODULES=$USER_C_MODULES \
65+
-DMICROPY_BOARD_DIR=$MICROPY_BOARD_DIR \
66+
-DMICROPY_BOARD=$MICROPY_BOARD \
67+
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
68+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
69+
}
70+
71+
function cmake_build {
72+
ccache --zero-stats || true
73+
cmake --build build-$BOARD_NAME -j 2
74+
ccache --show-stats || true
75+
cd build-$BOARD_NAME
76+
cp firmware.uf2 $RELEASE_FILE.uf2
77+
}

micropython/modules_py/modules_py.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@ set(MODULES_DIR ${CMAKE_CURRENT_LIST_DIR})
22

33
function (copy_module MODULE)
44
add_custom_command(
5-
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/../modules/${MODULE}
5+
OUTPUT ${MICROPY_PORT_DIR}/modules/${MODULE}
66

77
COMMAND
8-
cp ${MODULES_DIR}/${MODULE} ${CMAKE_CURRENT_BINARY_DIR}/../modules/${MODULE}
8+
cp ${MODULES_DIR}/${MODULE} ${MICROPY_PORT_DIR}/modules/${MODULE}
99

1010
DEPENDS ${MODULES_DIR}/${MODULE}
1111
)
1212

13-
target_sources(usermod_modules_py INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/../modules/${MODULE})
13+
target_sources(usermod_modules_py INTERFACE ${MICROPY_PORT_DIR}/modules/${MODULE})
1414
endfunction()
1515

1616
function (genversion VERSION_FILE)
1717
add_custom_command(
18-
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/../modules/${VERSION_FILE}
18+
OUTPUT ${MICROPY_PORT_DIR}/modules/${VERSION_FILE}
1919

2020
COMMAND
21-
bash ${MODULES_DIR}/genversion.sh ${CMAKE_CURRENT_BINARY_DIR}/../modules/${VERSION_FILE}
21+
bash ${MODULES_DIR}/genversion.sh ${MICROPY_PORT_DIR}/modules/${VERSION_FILE}
2222

2323
DEPENDS ${MODULES_DIR}/genversion.sh
2424
)
2525

26-
target_sources(usermod_modules_py INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/../modules/${VERSION_FILE})
26+
target_sources(usermod_modules_py INTERFACE ${MICROPY_PORT_DIR}/modules/${VERSION_FILE})
2727
endfunction()
2828

2929
# Create a dummy usermod to hang our .py copies from

0 commit comments

Comments
 (0)