Skip to content

Commit 48ba72c

Browse files
committed
add devcontainter-configurations per port for CP 9.x.x
1 parent 59ec955 commit 48ba72c

15 files changed

+453
-19
lines changed

.devcontainer/Readme.md

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,45 @@
1-
Build CircuitPython in a Github-Devcontainer
2-
============================================
1+
Build CircuitPython in a Github-Codespace
2+
=========================================
33

4-
To build CircuitPython within a Github-Devcontainer, you need to perform
4+
To build CircuitPython within a Github codespace, you need to perform
55
the following steps.
66

7-
1. checkout the code to a devcontainer
7+
1. checkout the code to a codespace
88

9-
- click on the green "<> Code"-button
10-
- select the Codespaces-tab
11-
- choose "+ new with options..." from the "..."-menu
12-
- in the following screen select the branch and then
13-
- select ".devcontainer/cortex-m/devcontainer.json" instead
14-
of "Default Codespaces configuration"
15-
- update region as necessary
16-
- finally, click on the green "Create codespace" button
9+
- click on the green "<> Code"-button
10+
- select the Codespaces-tab
11+
- choose "+ new with options..." from the "..."-menu
12+
- in the following screen select the branch and then
13+
- select the port instead of "Default project configuration"
14+
(unsupported: ports not using cortex-m or esp-idf)
15+
- update region as necessary
16+
- finally, click on the green "Create codespace" button
1717

18-
2. Your codespace is created. Cloning the images is quite fast, but
19-
preparing it for CircuitPython-development takes about 10 minutes.
20-
Note that this is a one-time task.
18+
2. Your codespace is created. Cloning the image and the repo is quite fast,
19+
but preparing it for CircuitPython-development takes about 10 minutes.
20+
But this is a one-time task: once created, your codespace exists
21+
until you explicitly delete it or until it times out (default: 30 days).
22+
(Technical note: due to a bug in codespace creation, the setup is
23+
triggered from `$HOME/.bashrc` and runs in the background).
2124

2225
3. During creation, you can run the command
23-
`tail -f /workspaces/.codespaces/.persistedshare/creation.log`
24-
to see what is going on.
26+
`tail -f /workspaces/install_build_env.log.active`
27+
to see what is going on. Once finished the log file is available
28+
as `/workspaces/install_build_env.log`.
2529

26-
4. To actually build CircuitPython, run
30+
4. To actually build CircuitPython, open a new terminal and run e.g.
2731

2832
cd ports/raspberrypi
2933
make -j $(nproc) BOARD=whatever TRANSLATION=xx_XX
3034

31-
This takes about 2m40s.
35+
This takes about 2m40s. The new terminal is necessary since the
36+
setup of the build environment also changes `$HOME/.bashrc` and
37+
sets important environment variables in that file.
38+
39+
As a normal user, you have 120 CPU-hours and 15GB per month free. Since
40+
the smallest machine has two CPUs, you effectively have 60 hours active
41+
time available.
42+
43+
All scripts are in `circuitpython/.devcontainer` and can also be executed
44+
manually which should usually not be necessary. With small changes, they
45+
should also work on a Linux-PC or laptop.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/universal
3+
{
4+
"name": "atmel-samd",
5+
"image": "mcr.microsoft.com/devcontainers/universal:2",
6+
"postCreateCommand": ".devcontainer/post_create.sh",
7+
"remoteEnv": { "CP_TOOLCHAIN": "cortex-m",
8+
"CP_PORT": "atmel-samd" }
9+
10+
// Features to add to the dev container. More info: https://containers.dev/features.
11+
// "features": {},
12+
13+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
14+
// "forwardPorts": [],
15+
16+
// Use 'postCreateCommand' to run commands after the container is created.
17+
// "postCreateCommand": "uname -a",
18+
19+
// Configure tool-specific properties.
20+
// "customizations": {},
21+
22+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
23+
// "remoteUser": "root"
24+
}

.devcontainer/common_tools.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
# -----------------------------------------------------------------------------
3+
# common_tools.sh: install tools and requirements for CircuitPython
4+
#
5+
# This script installs tools common to all builds.
6+
#
7+
# Author: Bernhard Bablok
8+
#
9+
# -----------------------------------------------------------------------------
10+
11+
REPO_ROOT="/workspaces/circuitpython"
12+
13+
echo -e "[common_tools.sh] starting install"
14+
cd "$REPO_ROOT"
15+
16+
# --- repositories and tools ------------------------------------------------
17+
18+
echo -e "[common_tools.sh] adding pybricks/ppa"
19+
sudo add-apt-repository -y ppa:pybricks/ppa
20+
echo -e "[common_tools.sh] installing uncrustify and mtools"
21+
sudo apt-get -y install uncrustify mtools
22+
23+
# dosfstools >= 4.2 needed, standard repo only has 4.1
24+
echo -e "[common_tools.sh] downloading and installing dosfstools"
25+
wget https://github.com/dosfstools/dosfstools/releases/download/v4.2/dosfstools-4.2.tar.gz
26+
tar -xzf dosfstools-4.2.tar.gz
27+
(cd dosfstools-4.2/
28+
./configure
29+
make -j $(nproc)
30+
sudo make install
31+
)
32+
rm -fr dosfstools-4.2 dosfstools-4.2.tar.gz
33+
34+
# --- circuitpython setup --------------------------------------------------
35+
36+
# additional python requirements
37+
echo -e "[common_tools.sh] pip-installing requirements"
38+
pip install --upgrade -r requirements-dev.txt
39+
pip install --upgrade -r requirements-doc.txt
40+
41+
# add pre-commit
42+
echo -e "[common_tools.sh] installing pre-commit"
43+
pre-commit install

.devcontainer/cortex-m-toolchain.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
# -----------------------------------------------------------------------------
3+
# cortex-m-toolchain.sh: install toolchain for CircuitPython
4+
#
5+
# Author: Bernhard Bablok
6+
#
7+
# -----------------------------------------------------------------------------
8+
9+
echo -e "[cortex-m-toolchain.sh] starting install"
10+
11+
# --- tooling --------------------------------------------------------------
12+
13+
echo -e "[cortex-m-toolchain.sh] downloading and installing gcc-arm-non-eabi toolchain"
14+
cd /workspaces
15+
16+
wget -qO gcc-arm-none-eabi.tar.xz \
17+
https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz
18+
19+
tar -xJf gcc-arm-none-eabi.tar.xz
20+
ln -s arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi gcc-arm-none-eabi
21+
rm -f gcc-arm-none-eabi.tar.xz
22+
23+
echo -e "[cortex-m-toolchain.sh] update PATH in environment"
24+
echo -e "\nexport PATH=/workspaces/gcc-arm-none-eabi/bin:$PATH" >> $HOME/.bashrc

.devcontainer/cxd56/devcontainer.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/universal
3+
{
4+
"name": "cxd56",
5+
"image": "mcr.microsoft.com/devcontainers/universal:2",
6+
"postCreateCommand": ".devcontainer/post_create.sh",
7+
"remoteEnv": { "CP_TOOLCHAIN": "cortex-m",
8+
"CP_PORT": "cxd56" }
9+
10+
// Features to add to the dev container. More info: https://containers.dev/features.
11+
// "features": {},
12+
13+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
14+
// "forwardPorts": [],
15+
16+
// Use 'postCreateCommand' to run commands after the container is created.
17+
// "postCreateCommand": "uname -a",
18+
19+
// Configure tool-specific properties.
20+
// "customizations": {},
21+
22+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
23+
// "remoteUser": "root"
24+
}

.devcontainer/esp-idf-toolchain.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# -----------------------------------------------------------------------------
3+
# esp-idf-toolchain.sh: install toolchain for CircuitPython
4+
#
5+
# Author: Bernhard Bablok
6+
#
7+
# -----------------------------------------------------------------------------
8+
REPO_ROOT="/workspaces/circuitpython"
9+
10+
echo -e "[esp-idf-toolchain.sh] starting install"
11+
12+
# --- tooling --------------------------------------------------------------
13+
14+
echo -e "[esp-idf-toolchain.sh] fetch packages"
15+
sudo apt-get update
16+
sudo apt-get -y install ninja-build cmake libusb-1.0-0
17+
18+
# --- esp-idf --------------------------------------------------------------
19+
20+
echo -e "[esp-idf-toolchain.sh] installing esp-idf"
21+
cd "$REPO_ROOT/ports/espressif"
22+
esp-idf/install.sh
23+
source esp-idf/export.sh
24+
25+
# --- re-install our packages in venv created by export.sh -----------------
26+
27+
echo -e "[esp-idf-toolchain.sh] updating python-packages"
28+
cd "$REPO_ROOT"
29+
pip3 install --upgrade -r requirements-dev.txt
30+
pip3 install --upgrade -r requirements-doc.txt
31+
32+
# --- and again install esp-idf (needs other versions) ----------------------
33+
34+
echo -e "[esp-idf-toolchain.sh] installing esp-idf (2nd iteration)"
35+
cd "$REPO_ROOT/ports/espressif"
36+
esp-idf/install.sh
37+
38+
# --- update $HOME/.bashrc --------------------------------------------------
39+
40+
echo -e "[esp-idf-toolchain.sh] update environment in .bashrc"
41+
42+
echo -e "\nsource $REPO_ROOT/ports/espressif/esp-idf/export.sh &> /dev/null\n" >> "$HOME"/.bashrc
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/universal
3+
{
4+
"name": "espressif",
5+
"image": "mcr.microsoft.com/devcontainers/universal:2",
6+
"postCreateCommand": ".devcontainer/post_create.sh",
7+
"remoteEnv": { "CP_TOOLCHAIN": "esp-idf",
8+
"CP_PORT": "espressif" }
9+
10+
// Features to add to the dev container. More info: https://containers.dev/features.
11+
// "features": {},
12+
13+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
14+
// "forwardPorts": [],
15+
16+
// Use 'postCreateCommand' to run commands after the container is created.
17+
// "postCreateCommand": "uname -a",
18+
19+
// Configure tool-specific properties.
20+
// "customizations": {},
21+
22+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
23+
// "remoteUser": "root"
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# -----------------------------------------------------------------------------
3+
# fetch-port-submodules.sh: fetch port specific submodules
4+
#
5+
# Author: Bernhard Bablok
6+
#
7+
# -----------------------------------------------------------------------------
8+
9+
REPO_ROOT="/workspaces/circuitpython"
10+
cd "$REPO_ROOT"
11+
12+
if [ -z "$CP_PORT" ]; then
13+
echo -e "[fetch-port-submodules.sh] CP_PORT not set. Cannot fetch submodules!"
14+
exit 3
15+
fi
16+
17+
cd "ports/$CP_PORT"
18+
echo -e "[fetch-port-submodules.sh] fetching necessary submodules"
19+
make fetch-port-submodules

.devcontainer/install_build_env.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
# -----------------------------------------------------------------------------
3+
# install_build_env.sh: install build-environment for CircuitPython
4+
#
5+
# Normally, this should run directly as postCreateCommand during container
6+
# creation. Due to an unresolved bug on how Github-codespaces creates a clone,
7+
# this script is started from $HOME/.bashrc instead.
8+
#
9+
# The script delegates parts to other scripts for reuse across toolchains.
10+
# This has the added benefit that they can be called independently later again
11+
# if necessary.
12+
#
13+
# The scripts expect the environment-variables CP_TOOLCHAIN and CP_PORT to be set
14+
# to valid values. This is normally done from within
15+
# .devcontainer/<port>/devcontainer.json
16+
#
17+
# Author: Bernhard Bablok
18+
#
19+
# -----------------------------------------------------------------------------
20+
REPO_ROOT="/workspaces/circuitpython"
21+
22+
# --- install exit-handler for cleanup --------------------------------------
23+
24+
on_exit() {
25+
rc=$?
26+
if [ -f /workspaces/install_build_env.log.active ]; then
27+
mv /workspaces/install_build_env.log.active /workspaces/install_build_env.log
28+
fi
29+
rm -rf /tmp/install_build_env
30+
exit $rc
31+
}
32+
33+
# --- test prerequisites for installation ------------------------------------
34+
35+
while ! test -f /workspaces/post_create.finished; do
36+
echo -e "[install_build_env.sh] waiting for /workspaces/post_create.finished ..."
37+
sleep 1
38+
done
39+
40+
if [ -f /workspaces/install_build_env.log ]; then
41+
echo -e "[install_build_env.sh] installation already done"
42+
exit 0
43+
elif ! mkdir /tmp/install_build_env 2>/dev/null; then
44+
# mkdir is atomic, so we know we are already running
45+
echo -e "[install_build_env.sh] install already running with PID $(cat /tmp/install_build_env/pid.txt)"
46+
exit 0
47+
else
48+
echo -e "$$" > /tmp/install_build_env/pid.txt
49+
trap 'on_exit' EXIT
50+
fi
51+
52+
echo -e "[install_build_env.sh] starting install"
53+
54+
# --- delegate install steps to other scripts -------------------------------
55+
(
56+
"$REPO_ROOT/.devcontainer/fetch-port-submodules.sh" || exit 3
57+
"$REPO_ROOT/.devcontainer/common_tools.sh" || exit 3
58+
"$REPO_ROOT/.devcontainer/$CP_TOOLCHAIN-toolchain.sh" || exit 3
59+
"$REPO_ROOT/.devcontainer/make-mpy-cross.sh" || exit 3
60+
echo -e "Setup complete!\nStart a new terminal and build CircuitPython!\n"
61+
) |& tee /workspaces/install_build_env.log.active
62+
63+
echo -e "[install_build_env.sh] Setup complete!"
64+
exit 0

.devcontainer/make-mpy-cross.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
# -----------------------------------------------------------------------------
3+
# make-mpy-cross.sh: fetch tags and prereqs, then build mpy-cross
4+
#
5+
# Author: Bernhard Bablok
6+
#
7+
# -----------------------------------------------------------------------------
8+
9+
REPO_ROOT="/workspaces/circuitpython"
10+
cd "$REPO_ROOT"
11+
12+
# fetch tags and tools for mpy-cross
13+
echo -e "[make-mpy-cross.sh] fetching tags"
14+
make fetch-tags
15+
echo -e "[make-mpy-cross.sh] fetching prerequisites"
16+
python3 tools/ci_fetch_deps.py mpy-cross
17+
18+
# create cross-compiler
19+
echo -e "[make-mpy-cross.sh] building mpy-cross"
20+
if ! make -j $(nproc) -C mpy-cross; then # time: about 36 sec
21+
echo -e "[make-mpy-cross.sh] make mpy-cross failed"
22+
exit 3
23+
fi
24+
exit 0

0 commit comments

Comments
 (0)