generated from BrianPugh/python-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
234 lines (206 loc) · 7.48 KB
/
mpy_native_module.yaml
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
name: Build MicroPython Native Module
on:
workflow_dispatch:
push:
tags:
- "v*.*.*"
branches:
- main
pull_request:
jobs:
build:
# explicitly setting due to iffy GA rollout.
# TODO: Revert to `ubuntu-latest` at a future date.
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
micropython_version: ["1.21.0", "1.22.2", "1.23.0"]
ARCH:
- "x86"
- "x64"
- "armv6m"
- "armv7m"
- "armv7emsp"
- "armv7emdp"
- "xtensa"
- "xtensawin"
env:
ARCH: ${{ matrix.ARCH }}
POETRY_HOME: "~/poetry"
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# Fixes some bugs on some platforms?
- name: Replace "static const uint8_t" with "const uint8_t"
run: |
find . -type f -name "*.c" -exec sed -i 's/static const uint8_t/const uint8_t/g' {} +
- name: Set up python ${{ matrix.python-version }}
if: env.ARCH != 'xtensa'
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Xtensa dependencies
if: env.ARCH == 'xtensa'
run: |
sudo apt-get update
sudo apt-get install -y \
gperf \
help2man \
libtool-bin \
python3 \
python3-dev
- name: arm-none-eabi-gcc GNU Arm Embedded Toolchain
if: startsWith(env.ARCH, 'arm')
uses: carlosperate/arm-none-eabi-gcc-action@v1.8.1
- name: Install Micropython Build Dependencies
run: |
sudo apt-get update && sudo apt-get install gcc-multilib
pip install pyelftools --break-system-packages
- name: Cache Setup Xtensa Toolchain (ESP8266)
if: env.ARCH == 'xtensa'
uses: actions/cache@v4
with:
path: |
esp-open-sdk/xtensa-lx106-elf
key: xtensa-toolchain-${{ hashFiles('**/Makefile') }}
restore-keys: |
xtensa-toolchain-
- name: Clone and build Xtensa toolchain
if: env.ARCH == 'xtensa'
run: |
if [ ! -d "esp-open-sdk" ]; then
git clone --branch fix-ubuntu-21.10-build --recursive https://github.com/BrianPugh/esp-open-sdk.git
cd esp-open-sdk
unset LD_LIBRARY_PATH
make
cd ..
fi
echo "$PWD/esp-open-sdk/xtensa-lx106-elf/bin" >> $GITHUB_PATH
- name: Cache Setup ESP-IDF (ESP32)
if: env.ARCH == 'xtensawin'
uses: actions/cache@v4
with:
path: |
esp-idf
~/.espressif
!esp-idf/.git
key: esp-idf-${{ hashFiles('**/Makefile') }}
restore-keys: |
esp-idf-
- name: Setup ESP-IDF (ESP32)
if: env.ARCH == 'xtensawin'
run: |
if [ ! -d "esp-idf" ]; then
git clone -b v5.0.6 --recursive https://github.com/espressif/esp-idf.git
cd esp-idf
git submodule update --init --recursive
./install.sh
cd ..
fi
cd esp-idf
ENV_BEFORE=$(env)
source export.sh
ENV_AFTER=$(env)
echo "$ENV_AFTER" | grep -vxF "$ENV_BEFORE" | grep '=' | while IFS='=' read -r name value
do
echo "exporting to GITHUB_ENV: ${name}=${value}"
echo "${name}=${value}" >> $GITHUB_ENV
done
- name: Install MicroPython
uses: BrianPugh/install-micropython@v2
with:
reference: v${{ matrix.micropython_version }}
- name: Cache Poetry Install
uses: actions/cache@v4
id: cached-poetry
with:
path: ${{ env.POETRY_HOME }}
key: poetry-cache-${{ runner.os }}-${{ env.PYTHON }}-${{ hashFiles('.github/workflows/tests.yaml') }}
- name: Install poetry
uses: snok/install-poetry@v1
if: steps.cached-poetry.outputs.cache-hit != 'true'
- name: Add Poetry to PATH # Needs to be separate from install-poetry because cache.
run: |
echo "$POETRY_HOME/bin" >> $GITHUB_PATH
- name: Configure Poetry # Needs to be separate from install-poetry because cache.
run: |
poetry self add "poetry-dynamic-versioning[plugin]"
poetry config virtualenvs.create false
poetry config virtualenvs.in-project false
- name: Get Tag or Commit Hash
run: |
poetry dynamic-versioning # in-place updates files with correct version string
VERSION=$(poetry version | sed 's/tamp //; s/\x1b\[[0-9;]*m//g')
echo "Detected version is: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
export MICROPYTHON_VERSION=${{ matrix.micropython_version }}
export MICROPYTHON_VERSION_MAJOR_MINOR=${MICROPYTHON_VERSION%.*}
echo "Detected Micropython Major.Minor: $MICROPYTHON_VERSION_MAJOR_MINOR"
echo "MICROPYTHON_VERSION_MAJOR_MINOR=$MICROPYTHON_VERSION_MAJOR_MINOR" >> $GITHUB_ENV
- name: Install library
if: env.ARCH == 'x64'
run: poetry install --no-interaction
- name: Build MicroPython Native Module
run: |
echo "Building architecture $ARCH Complete"
make clean
make ARCH=$ARCH
if [[ "$ARCH" == "x64" ]]; then
cp tamp.mpy tamp_native.mpy
belay run micropython -X heapsize=200M -m unittest tests/test_*.py
rm tamp_native.mpy
fi
mv tamp.mpy tamp-${VERSION}-mpy${MICROPYTHON_VERSION_MAJOR_MINOR}-${ARCH}.mpy
make clean
echo "Building architecture $ARCH Compressor"
make clean
make ARCH=$ARCH TAMP_DECOMPRESSOR=0
if [[ "$ARCH" == "x64" ]]; then
cp tamp.mpy tamp_native.mpy
belay run micropython -X heapsize=200M -m unittest tests/test_compressor.py
rm tamp_native.mpy
fi
mv tamp.mpy tamp[compressor]-${VERSION}-mpy${MICROPYTHON_VERSION_MAJOR_MINOR}-${ARCH}.mpy
make clean
echo "Building architecture $ARCH Decompressor"
make clean
make ARCH=$ARCH TAMP_COMPRESSOR=0
if [[ "$ARCH" == "x64" ]]; then
cp tamp.mpy tamp_native.mpy
belay run micropython -X heapsize=200M -m unittest tests/test_decompressor.py
rm tamp_native.mpy
fi
mv tamp.mpy tamp[decompressor]-${VERSION}-mpy${MICROPYTHON_VERSION_MAJOR_MINOR}-${ARCH}.mpy
make clean
- name: Upload Native Module MPY Files
uses: actions/upload-artifact@v4
with:
name: mpy-native-module-tamp-${{ env.VERSION }}-mpy${{ env.MICROPYTHON_VERSION_MAJOR_MINOR }}-${{ env.ARCH }}
path: "*.mpy"
release_upload:
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Download All Native Module Artifacts
uses: actions/download-artifact@v4
with:
path: mpy-native-modules
pattern: mpy-native-module-*
merge-multiple: true
- name: Display All Native Module Artifacts
run: ls -alh mpy-native-modules
- name: Upload Single Native Module MPY Archive
uses: actions/upload-artifact@v4
with:
name: mpy-native-module-all
path: "mpy-native-modules/*.mpy"
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
mpy-native-modules/*