Skip to content

Commit a9d13be

Browse files
committed
docker: Add Containerfile for building CircuitPython with ARM toolchains
This commit introduces a new Containerfile that sets up a Docker environment for building CircuitPython. It includes installation of necessary apt dependencies and ARM toolchains based on architecture. Additionally, it configures the workspace for cloning the CircuitPython repository and installing required Python packages. Signed-off-by: Chiho Sin <[email protected]>
0 parents  commit a9d13be

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed

Containerfile

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
FROM python:3.13-bookworm AS base
2+
3+
ENV PIP_ROOT_USER_ACTION=ignore
4+
ENV ARM_TOOLCHAIN_EABI_VERSION=14.2.rel1
5+
ENV ARM_TOOLCHAIN_ELF_VERSION=13.3.rel1
6+
7+
# Apt dependencies
8+
RUN apt-get update && apt-get install -y \
9+
jq jdupes build-essential \
10+
libgpiod-dev libyaml-cpp-dev libbluetooth-dev libusb-1.0-0-dev libi2c-dev libuv1-dev \
11+
libx11-dev libinput-dev libxkbcommon-x11-dev \
12+
openssl libssl-dev libulfius-dev liborcania-dev \
13+
git git-lfs gettext cmake mtools floppyd dosfstools \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
# Install ARM toolchain (EABI) based on architecture
17+
RUN ARCH=$(dpkg --print-architecture) && \
18+
if [ "$ARCH" = "arm64" ]; then \
19+
TOOLCHAIN_URL="https://developer.arm.com/-/media/Files/downloads/gnu/$ARM_TOOLCHAIN_EABI_VERSION/binrel/arm-gnu-toolchain-$ARM_TOOLCHAIN_EABI_VERSION-aarch64-arm-none-eabi.tar.xz"; \
20+
elif [ "$ARCH" = "amd64" ]; then \
21+
TOOLCHAIN_URL="https://developer.arm.com/-/media/Files/downloads/gnu/$ARM_TOOLCHAIN_EABI_VERSION/binrel/arm-gnu-toolchain-$ARM_TOOLCHAIN_EABI_VERSION-x86_64-arm-none-eabi.tar.xz"; \
22+
else \
23+
echo "Unsupported architecture: $ARCH"; \
24+
exit 1; \
25+
fi && \
26+
mkdir -p /usr/local/arm-none-eabi && \
27+
curl -fsSL "$TOOLCHAIN_URL" | tar -xJ -C /usr/local/arm-none-eabi --strip-components=1 && \
28+
for f in /usr/local/arm-none-eabi/bin/arm-none-eabi-*; do \
29+
ln -sf "$f" /usr/local/bin/$(basename "$f"); \
30+
done
31+
32+
# Install ARM toolchain (ELF) based on architecture
33+
RUN ARCH=$(dpkg --print-architecture) && \
34+
if [ "$ARCH" = "arm64" ]; then \
35+
TOOLCHAIN_URL="https://developer.arm.com/-/media/Files/downloads/gnu/$ARM_TOOLCHAIN_ELF_VERSION/binrel/arm-gnu-toolchain-$ARM_TOOLCHAIN_ELF_VERSION-aarch64-aarch64-none-elf.tar.xz"; \
36+
elif [ "$ARCH" = "amd64" ]; then \
37+
TOOLCHAIN_URL="https://developer.arm.com/-/media/Files/downloads/gnu/$ARM_TOOLCHAIN_ELF_VERSION/binrel/arm-gnu-toolchain-$ARM_TOOLCHAIN_ELF_VERSION-x86_64-aarch64-none-elf.tar.xz"; \
38+
else \
39+
echo "Unsupported architecture: $ARCH"; \
40+
exit 1; \
41+
fi && \
42+
mkdir -p /usr/local/arm-none-elf && \
43+
curl -fsSL "$TOOLCHAIN_URL" | tar -xJ -C /usr/local/arm-none-elf --strip-components=1 && \
44+
for f in /usr/local/arm-none-elf/bin/arm-none-elf-*; do \
45+
ln -sf "$f" /usr/local/bin/$(basename "$f"); \
46+
done
47+
48+
FROM base AS repo
49+
ARG BUILD_REPO="https://github.com/adafruit/circuitpython.git"
50+
ARG BUILD_REF="main"
51+
ARG BUILD_FORK_REPO="https://github.com/fobe-projects/circuitpython.git"
52+
ARG BUILD_FORK_REF="main"
53+
ARG BUILD_PLATFORM
54+
55+
WORKDIR /workspace
56+
57+
RUN git config --global --add safe.directory /workspace
58+
RUN git clone --depth 1 --filter=tree:0 "${BUILD_REPO}" /workspace
59+
RUN git checkout "${BUILD_REF}"
60+
RUN git fetch --no-recurse-submodules --shallow-since="2021-07-01" --tags "${BUILD_REPO}" HEAD
61+
RUN git fetch --no-recurse-submodules --shallow-since="2021-07-01" origin
62+
RUN git repack -d
63+
RUN git remote add fork "${BUILD_FORK_REPO}" && git fetch fork --filter=tree:0
64+
RUN git checkout -b fork-branch "fork/${BUILD_FORK_REF}"
65+
66+
RUN pip3 install --upgrade -r requirements-dev.txt && pip3 install --upgrade -r requirements-doc.txt
67+
RUN pip3 install --upgrade huffman
68+
69+
RUN python tools/ci_fetch_deps.py ${BUILD_PLATFORM}
70+
71+
COPY entrypoint.sh /entrypoint.sh
72+
ENTRYPOINT [ "/entrypoint.sh" ]

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Containerfile

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# circuitpython

entrypoint.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Define vars
5+
GITHUB_ACTIONS=${GITHUB_ACTIONS:-false}
6+
GITHUB_SHA=${GITHUB_SHA:-"main"}
7+
8+
# Inputs
9+
CPY_TARGET=${CPY_TARGET:-"build"}
10+
CPY_PLATFORM=${CPY_PLATFORM}
11+
CPY_BOARD=${CPY_BOARD}
12+
13+
git checkout "$GITHUB_SHA"
14+
python tools/ci_fetch_deps.py ${CPY_PLATFORM}
15+
pip3 install --upgrade -r requirements-dev.txt
16+
pip3 install --upgrade -r requirements-doc.txt
17+
make -j$(nproc) -C mpy-cross
18+
19+
# Build
20+
if [ "$CPY_TARGET" = "build" ]; then
21+
echo "Building CircuitPython: $CPY_PLATFORM:$CPY_BOARD"
22+
make -j$(nproc) -C ports/"$CPY_PLATFORM" BOARD="$CPY_BOARD"
23+
mkdir -p .build
24+
mv ports/"$CPY_PLATFORM"/build-"$CPY_BOARD"/* .build/
25+
echo "Build artifacts are located at: .build"
26+
fi

0 commit comments

Comments
 (0)