Skip to content

Commit b8e3fb9

Browse files
committed
Add action to run genExamples.py
1 parent 15f0c5c commit b8e3fb9

File tree

2 files changed

+157
-4
lines changed

2 files changed

+157
-4
lines changed

.github/workflows/genExamples.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Update examples.json
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
develop:
7+
description: "Test with develop branch"
8+
required: false
9+
type: boolean
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
- name: Setup Python
18+
uses: actions/setup-python@v5
19+
with:
20+
cache: 'pip'
21+
cache-dependency-path: '.github/workflows/genExamples.yml'
22+
- name: Install Dependencies
23+
run: |
24+
sudo apt update
25+
sudo apt install -y cmake ninja-build build-essential
26+
pip install pycryptodomex
27+
- name: Cache ~/.pico-sdk
28+
uses: actions/cache@v4
29+
with:
30+
path: ~/.pico-sdk
31+
key: pico-sdk-${{ hashFiles('scripts/genExamples.py') }}
32+
- name: Run genExamples.py
33+
env:
34+
SDK_VERSION: ${{ inputs.develop && '2-develop' || '' }}
35+
run: |
36+
python scripts/genExamples.py
37+
- name: Upload Artifact
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: examples.json
41+
path: |
42+
data/0.17.0/examples.json
43+
- name: Print diff
44+
run: |
45+
git diff data/0.17.0/examples.json

scripts/genExamples.py

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
import shutil
66
import json
77
import multiprocessing
8+
import configparser
9+
import platform
810

911
from pico_project import GenerateCMake
1012

13+
# This script is designed to be run on Linux
14+
assert platform.system() == "Linux"
15+
1116
boards = ["pico", "pico_w", "pico2", "pico2_w"]
1217

1318
platforms = {
@@ -32,7 +37,107 @@
3237

3338
CURRENT_DATA_VERSION = "0.17.0"
3439

35-
SDK_VERSION = "2.1.1"
40+
SDK_VERSION = os.environ.get("SDK_VERSION", "2.1.1")
41+
ARM_TOOLCHAIN_VERSION = os.environ.get("ARM_TOOLCHAIN_VERSION", "14_2_Rel1")
42+
RISCV_TOOLCHAIN_VERSION = os.environ.get(
43+
"RISCV_TOOLCHAIN_VERSION", "RISCV_ZCB_RPI_2_1_1_3"
44+
)
45+
46+
# To test with develop SDK, uncomment the line below - this will clone the SDK & picotool, and build picotool & pioasm
47+
# note: the 2- is required due to a VERSION_LESS check in pico-vscode.cmake
48+
# SDK_VERSION = "2-develop"
49+
50+
BUILD_TOOLS = not os.path.exists(os.path.expanduser(f"~/.pico-sdk/sdk/{SDK_VERSION}"))
51+
52+
if "develop" in SDK_VERSION:
53+
SDK_BRANCH = "develop"
54+
PICOTOOL_BRANCH = "develop"
55+
EXAMPLES_BRANCH = "develop"
56+
BUILD_TOOLS = True # Always clone & build the latest when using develop
57+
else:
58+
SDK_BRANCH = SDK_VERSION
59+
PICOTOOL_BRANCH = SDK_VERSION
60+
EXAMPLES_BRANCH = f"sdk-{SDK_VERSION}"
61+
62+
# Platform & toolchain setup
63+
platform = "linux_x64" if platform.machine() == "x86_64" else "linux_arm64"
64+
config = configparser.ConfigParser()
65+
config.read(
66+
f"{os.path.dirname(os.path.realpath(__file__))}/../data/{CURRENT_DATA_VERSION}/supportedToolchains.ini"
67+
)
68+
69+
# Download arm toolchain if not already downloaded
70+
if not os.path.exists(
71+
os.path.expanduser(f"~/.pico-sdk/toolchain/{ARM_TOOLCHAIN_VERSION}")
72+
):
73+
toolchain_url = config[ARM_TOOLCHAIN_VERSION][platform]
74+
os.mkdir(os.path.expanduser(f"~/.pico-sdk/toolchain/{ARM_TOOLCHAIN_VERSION}"))
75+
os.system(f"wget {toolchain_url}")
76+
os.system(
77+
f"tar -xf {toolchain_url.split('/')[-1]} --strip-components 1 -C ~/.pico-sdk/toolchain/{ARM_TOOLCHAIN_VERSION}"
78+
)
79+
os.system(f"rm {toolchain_url.split('/')[-1]}")
80+
81+
# Download riscv toolchain if not already downloaded
82+
if not os.path.exists(
83+
os.path.expanduser(f"~/.pico-sdk/toolchain/{RISCV_TOOLCHAIN_VERSION}")
84+
):
85+
toolchain_url = config[RISCV_TOOLCHAIN_VERSION][platform]
86+
os.mkdir(os.path.expanduser(f"~/.pico-sdk/toolchain/{RISCV_TOOLCHAIN_VERSION}"))
87+
os.system(f"wget {toolchain_url}")
88+
os.system(
89+
f"tar -xf {toolchain_url.split('/')[-1]} -C ~/.pico-sdk/toolchain/{RISCV_TOOLCHAIN_VERSION}"
90+
)
91+
os.system(f"rm {toolchain_url.split('/')[-1]}")
92+
93+
if BUILD_TOOLS:
94+
# Clone pico-sdk
95+
try:
96+
shutil.rmtree(os.path.expanduser(f"~/.pico-sdk/sdk/{SDK_VERSION}"))
97+
except FileNotFoundError:
98+
pass
99+
os.system(
100+
f"git -c advice.detachedHead=false clone https://github.com/raspberrypi/pico-sdk.git --depth=1 --branch {SDK_BRANCH} --recurse-submodules --shallow-submodules ~/.pico-sdk/sdk/{SDK_VERSION}"
101+
)
102+
103+
# Clone & build picotool
104+
try:
105+
shutil.rmtree("picotool")
106+
except FileNotFoundError:
107+
pass
108+
try:
109+
shutil.rmtree("picotool-build")
110+
except FileNotFoundError:
111+
pass
112+
try:
113+
shutil.rmtree(os.path.expanduser(f"~/.pico-sdk/picotool/{SDK_VERSION}"))
114+
except FileNotFoundError:
115+
pass
116+
os.system(
117+
f"git -c advice.detachedHead=false clone https://github.com/raspberrypi/picotool.git --depth=1 --branch {PICOTOOL_BRANCH}"
118+
)
119+
os.system(
120+
f"cmake -S picotool -B picotool-build -GNinja -DPICO_SDK_PATH=~/.pico-sdk/sdk/{SDK_VERSION} -DPICOTOOL_FLAT_INSTALL=1 -DPICOTOOL_NO_LIBUSB=1"
121+
)
122+
os.system(f"cmake --build picotool-build")
123+
os.system(
124+
f"cmake --install picotool-build --prefix ~/.pico-sdk/picotool/{SDK_VERSION}"
125+
)
126+
127+
# Build pioasm
128+
try:
129+
shutil.rmtree("pioasm-build")
130+
except FileNotFoundError:
131+
pass
132+
try:
133+
shutil.rmtree(os.path.expanduser(f"~/.pico-sdk/tools/{SDK_VERSION}"))
134+
except FileNotFoundError:
135+
pass
136+
os.system(
137+
f"cmake -S ~/.pico-sdk/sdk/{SDK_VERSION}/tools/pioasm -B pioasm-build -GNinja -DPIOASM_FLAT_INSTALL=1 -DPIOASM_VERSION_STRING={SDK_VERSION}"
138+
)
139+
os.system(f"cmake --build pioasm-build")
140+
os.system(f"cmake --install pioasm-build --prefix ~/.pico-sdk/tools/{SDK_VERSION}")
36141

37142
try:
38143
shutil.rmtree("pico-examples")
@@ -44,7 +149,7 @@
44149
except FileNotFoundError:
45150
pass
46151
os.system(
47-
f"git -c advice.detachedHead=false clone https://github.com/raspberrypi/pico-examples.git --depth=1 --branch sdk-{SDK_VERSION}"
152+
f"git -c advice.detachedHead=false clone https://github.com/raspberrypi/pico-examples.git --depth=1 --branch {EXAMPLES_BRANCH}"
48153
)
49154
os.environ["PICO_SDK_PATH"] = f"~/.pico-sdk/sdk/{SDK_VERSION}"
50155
os.environ["WIFI_SSID"] = "Your Wi-Fi SSID"
@@ -65,7 +170,7 @@
65170
except FileNotFoundError:
66171
pass
67172
toolchainVersion = (
68-
"RISCV_ZCB_RPI_2_1_1_3" if "riscv" in platform else "14_2_Rel1"
173+
RISCV_TOOLCHAIN_VERSION if "riscv" in platform else ARM_TOOLCHAIN_VERSION
69174
)
70175
toolchainPath = f"~/.pico-sdk/toolchain/{toolchainVersion}"
71176
picotoolDir = f"~/.pico-sdk/picotool/{SDK_VERSION}/picotool"
@@ -148,6 +253,9 @@ def test_build(target, v):
148253
dir = f"tmp-{target}"
149254
try:
150255
shutil.rmtree(dir)
256+
except FileNotFoundError:
257+
pass
258+
try:
151259
shutil.rmtree(f"{dir}-build")
152260
except FileNotFoundError:
153261
pass
@@ -210,7 +318,7 @@ def test_build(target, v):
210318

211319
ordered_targets.extend(target_locs.keys())
212320

213-
with multiprocessing.Pool(processes=22) as pool:
321+
with multiprocessing.Pool(processes=os.cpu_count()) as pool:
214322
ret = pool.starmap(
215323
test_build,
216324
[(target, v) for target, v in target_locs.items()],

0 commit comments

Comments
 (0)