Skip to content

Commit 392d75b

Browse files
authored
Merge pull request #878 from pimoroni/ci/tooling
CI: Move some workflow steps into ci/micropython.sh
2 parents 911cbb7 + bd6bd28 commit 392d75b

File tree

12 files changed

+163
-140
lines changed

12 files changed

+163
-140
lines changed

.github/workflows/micropython.yml

Lines changed: 49 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -7,63 +7,11 @@ on:
77
types: [created]
88

99
env:
10-
MICROPYTHON_VERSION: v1.21.0
11-
WORKFLOW_VERSION: v1
10+
MICROPYTHON_VERSION: v1.22.1
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,91 @@ 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}}-
111-
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}}
60+
ccache-micropython-${{ matrix.name }}-${{ github.ref }}
61+
ccache-micropython-${{ matrix.name }}-
11962
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 }}
12967

130-
- name: Set MicroPython Version Env Vars
131-
shell: bash
68+
- name: Install Arm GNU Toolchain (arm-none-eabi-gcc)
69+
uses: carlosperate/arm-none-eabi-gcc-action@v1
70+
with:
71+
release: '9-2020-q2'
72+
73+
- name: Install CCache
13274
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
75+
source $BUILD_TOOLS
76+
apt_install_build_deps
77+
78+
- name: Checkout MicroPython & Submodules
79+
run: |
80+
source $BUILD_TOOLS
81+
micropython_clone
82+
83+
- name: Build MPY Cross
84+
run: |
85+
source $BUILD_TOOLS
86+
micropython_build_mpy_cross
13587
13688
- name: "HACK: CMakeLists.txt Disable C++ Exceptions Patch"
13789
shell: bash
138-
working-directory: micropython
139-
run: git apply $GITHUB_WORKSPACE/pimoroni-pico-${{ github.sha }}/micropython/micropython_nano_specs.patch
90+
run: |
91+
source $BUILD_TOOLS
92+
hack_patch_micropython_disable_exceptions
14093
14194
- name: "HACK: Pico SDK Patch"
142-
if: matrix.patch == true
14395
shell: bash
144-
working-directory: micropython
14596
run: |
146-
$GITHUB_WORKSPACE/pimoroni-pico-${{ github.sha }}/micropython/board/pico-sdk-patch.sh ${{matrix.board}}
97+
source $BUILD_TOOLS
98+
hack_patch_pico_sdk
14799
148100
- name: Configure MicroPython
149101
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
157102
run: |
158-
ccache --zero-stats || true
159-
cmake --build build-${{matrix.name}} -j 1
160-
ccache --show-stats || true
103+
source $BUILD_TOOLS
104+
micropython_version
105+
cmake_configure
161106
162-
- name: Rename .uf2 for artifact
107+
- name: Build MicroPython
163108
shell: bash
164-
working-directory: micropython/ports/rp2/build-${{matrix.name}}
165109
run: |
166-
cp firmware.uf2 $RELEASE_FILE.uf2
110+
source $BUILD_TOOLS
111+
cmake_build
167112
168113
- name: Store .uf2 as artifact
169114
uses: actions/upload-artifact@v3
170115
with:
171-
name: ${{env.RELEASE_FILE}}.uf2
172-
path: micropython/ports/rp2/build-${{matrix.name}}/${{env.RELEASE_FILE}}.uf2
116+
name: ${{ env.RELEASE_FILE }}.uf2
117+
path: build-${{ matrix.name }}/${{ env.RELEASE_FILE }}.uf2
173118

174119
- name: Upload .uf2
175120
if: github.event_name == 'release'
176121
uses: actions/upload-release-asset@v1
177122
env:
178-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
123+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
179124
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
125+
asset_path: build-${{ matrix.name }}/firmware.uf2
126+
upload_url: ${{ github.event.release.upload_url }}
127+
asset_name: ${{ env.RELEASE_FILE }}.uf2
183128
asset_content_type: application/octet-stream

ci/micropython.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 micropython_clone {
16+
log_inform "Using MicroPython $MICROPYTHON_VERSION"
17+
git clone https://github.com/micropython/micropython --depth=1 --branch=$MICROPYTHON_VERSION
18+
cd micropython
19+
git submodule update --init lib/pico-sdk
20+
git submodule update --init lib/cyw43-driver
21+
git submodule update --init lib/lwip
22+
git submodule update --init lib/mbedtls
23+
git submodule update --init lib/micropython-lib
24+
git submodule update --init lib/tinyusb
25+
git submodule update --init lib/btstack
26+
cd ../
27+
}
28+
29+
function micropython_build_mpy_cross {
30+
cd micropython/mpy-cross
31+
ccache --zero-stats || true
32+
CROSS_COMPILE="ccache " make
33+
ccache --show-stats || true
34+
cd ../../
35+
}
36+
37+
function apt_install_build_deps {
38+
sudo apt update && sudo apt install ccache
39+
}
40+
41+
function micropython_version {
42+
echo "MICROPY_GIT_TAG=$MICROPYTHON_VERSION, $BOARD_NAME $TAG_OR_SHA" >> $GITHUB_ENV
43+
echo "MICROPY_GIT_HASH=$MICROPYTHON_VERSION-$TAG_OR_SHA" >> $GITHUB_ENV
44+
}
45+
46+
function hack_patch_micropython_disable_exceptions {
47+
cd micropython
48+
git apply $PIMORONI_PICO_DIR/micropython/micropython_nano_specs.patch
49+
cd ../
50+
}
51+
52+
function hack_patch_pico_sdk {
53+
# pico-sdk-patch.sh will apply the patch if it exists
54+
cd micropython
55+
$PIMORONI_PICO_DIR/micropython/board/pico-sdk-patch.sh $MICROPY_BOARD
56+
cd ../
57+
}
58+
59+
function cmake_configure {
60+
cmake -S micropython/ports/rp2 -B build-$BOARD_NAME \
61+
-DPICO_BUILD_DOCS=0 \
62+
-DUSER_C_MODULES=$USER_C_MODULES \
63+
-DMICROPY_BOARD_DIR=$MICROPY_BOARD_DIR \
64+
-DMICROPY_BOARD=$MICROPY_BOARD \
65+
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
66+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
67+
}
68+
69+
function cmake_build {
70+
ccache --zero-stats || true
71+
cmake --build build-$BOARD_NAME -j 2
72+
ccache --show-stats || true
73+
cd build-$BOARD_NAME
74+
cp firmware.uf2 $RELEASE_FILE.uf2
75+
}

micropython/board/pico-sdk-patch.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ if [[ -f "$FIXUP_DIR/$BOARD/pico_sdk.patch" ]]; then
77
echo "Applying pico_sdk.patch"
88
cd $MPY_DIR/lib/pico-sdk
99
git apply "$FIXUP_DIR/$BOARD/pico_sdk.patch"
10+
else
11+
echo "Skipping patch. $FIXUP_DIR/$BOARD/pico_sdk.patch not found!"
1012
fi
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt
2-
index 094031c6852a..5f268414c08f 100644
2+
index 281b0c3bc..7e04bb549 100644
33
--- a/ports/rp2/CMakeLists.txt
44
+++ b/ports/rp2/CMakeLists.txt
5-
@@ -374,6 +374,15 @@ target_compile_options(${MICROPY_TARGET} PRIVATE
6-
target_link_options(${MICROPY_TARGET} PRIVATE
7-
-Wl,--defsym=__micropy_c_heap_size__=${MICROPY_C_HEAP_SIZE}
5+
@@ -453,6 +453,16 @@ target_link_options(${MICROPY_TARGET} PRIVATE
6+
-Wl,--wrap=dcd_event_handler
87
)
8+
99
+# Do not include stack unwinding & exception handling for C++ user modules
1010
+target_compile_definitions(usermod INTERFACE PICO_CXX_ENABLE_EXCEPTIONS=0)
1111
+target_compile_options(usermod INTERFACE $<$<COMPILE_LANGUAGE:CXX>:
@@ -15,6 +15,7 @@ index 094031c6852a..5f268414c08f 100644
1515
+ -fno-use-cxa-atexit
1616
+>)
1717
+target_link_options(usermod INTERFACE -specs=nano.specs)
18-
18+
+
1919
set_source_files_properties(
2020
${PICO_SDK_PATH}/src/rp2_common/pico_double/double_math.c
21+
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_math.c

micropython/modules/badger2040/badger2040.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ mp_obj_t Badger2040_update(mp_obj_t self_in) {
122122
_Badger2040_obj_t *self = MP_OBJ_TO_PTR2(self_in, _Badger2040_obj_t);
123123

124124
while(self->badger2040->is_busy()) {
125-
#ifdef MICROPY_EVENT_POLL_HOOK
126-
MICROPY_EVENT_POLL_HOOK
125+
#ifdef mp_event_handle_nowait
126+
mp_event_handle_nowait();
127127
#endif
128128
}
129129

@@ -133,8 +133,8 @@ MICROPY_EVENT_POLL_HOOK
133133
// Ensure blocking for the minimum amount of time
134134
// in cases where "is_busy" is unreliable.
135135
while(self->badger2040->is_busy() || absolute_time_diff_us(get_absolute_time(), t_end) > 0) {
136-
#ifdef MICROPY_EVENT_POLL_HOOK
137-
MICROPY_EVENT_POLL_HOOK
136+
#ifdef mp_event_handle_nowait
137+
mp_event_handle_nowait();
138138
#endif
139139
}
140140

@@ -166,8 +166,8 @@ mp_obj_t Badger2040_partial_update(size_t n_args, const mp_obj_t *pos_args, mp_m
166166

167167

168168
while(self->badger2040->is_busy()) {
169-
#ifdef MICROPY_EVENT_POLL_HOOK
170-
MICROPY_EVENT_POLL_HOOK
169+
#ifdef mp_event_handle_nowait
170+
mp_event_handle_nowait();
171171
#endif
172172
}
173173

@@ -177,8 +177,8 @@ MICROPY_EVENT_POLL_HOOK
177177
// Ensure blocking for the minimum amount of time
178178
// in cases where "is_busy" is unreliable.
179179
while(self->badger2040->is_busy() || absolute_time_diff_us(get_absolute_time(), t_end) > 0) {
180-
#ifdef MICROPY_EVENT_POLL_HOOK
181-
MICROPY_EVENT_POLL_HOOK
180+
#ifdef mp_event_handle_nowait
181+
mp_event_handle_nowait();
182182
#endif
183183
}
184184

@@ -199,8 +199,8 @@ mp_obj_t Badger2040_halt(mp_obj_t self_in) {
199199

200200
self->badger2040->update_button_states();
201201
while (self->badger2040->button_states() == 0) {
202-
#ifdef MICROPY_EVENT_POLL_HOOK
203-
MICROPY_EVENT_POLL_HOOK
202+
#ifdef mp_event_handle_nowait
203+
mp_event_handle_nowait();
204204
#endif
205205
self->badger2040->update_button_states();
206206
}

micropython/modules/jpegdec/jpegdec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ int32_t jpegdec_seek_callback(JPEGFILE *jpeg, int32_t p) {
8484
}
8585

8686
int JPEGDraw(JPEGDRAW *pDraw) {
87-
#ifdef MICROPY_EVENT_POLL_HOOK
88-
MICROPY_EVENT_POLL_HOOK
87+
#ifdef mp_event_handle_nowait
88+
mp_event_handle_nowait();
8989
#endif
9090
PicoGraphics *current_graphics = (PicoGraphics *)pDraw->pUser;
9191
// "pixel" is slow and clipped,

micropython/modules/pico_scroll/pico_scroll.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ mp_obj_t picoscroll_scroll_text(mp_uint_t n_args, const mp_obj_t *args) {
110110
self->scroll->clear();
111111
self->scroll->set_bitmap_1d((const char *)draw_buffer, draw_buffer_len, brightness, offset);
112112
self->scroll->update();
113-
MICROPY_EVENT_POLL_HOOK
113+
mp_event_handle_nowait();
114114
sleep_ms(delay_ms);
115115
}
116116

0 commit comments

Comments
 (0)