Skip to content

Commit

Permalink
chore: Arduino CLIやMbed CLIをインストールする #204 (#239)
Browse files Browse the repository at this point in the history
* chore: Arduino CLIやMbed CLIをインストールする #204

* chore: CSellの辞書を更新した #204

* chore: Arduino CLIやMbed CLIをインストール #204

* chore: Arduino CLIやMbed CLIでのビルドテストを追加 #204

* fix: mbedコマンドではなくmbed-cliコマンドを利用する #204

* fix: devcontainer exec を利用する #204

* chore: Dev Container CLIのバージョンを0.50.0に固定する #204

0.50.1ではエラーが発生したため、その前のバージョンに固定する

* feat: Mbed CLI 1でのビルドをtmpディレクトリ中で行う #204

* feat: devcontainers/ci を利用したワークフローに変更 #204

* fix: CIの git の safe.directory の設定時のエラーを修正 #204

* chore: テスト中のコマンドの終了ステータスが0以外のときに中断する #204

* fix: コンパイルエラーを修正 #204

* fix: 用意したソースコードでビルドテストするように変更 #204

* chore: multiplatform build #204

* Revert "chore: multiplatform build #204"

This reverts commit 4875af0.

* chore: ビルド成功時にイメージをpushする #204

* chore: Arduino CLIでのビルド中にログを出力する #204

* fix: `No space left on device`対策を実施 #204

* chore: 削除する容量を増やした #204
  • Loading branch information
yutotnh authored Jul 29, 2023
1 parent 7dc7c30 commit 1eeeb90
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
"DIGITALOUT",
"Doxyfile",
"DUTYCYCLE",
"EABI",
"endfunction",
"envie",
"esptool",
"fqbn",
"googletest",
"gtest",
Expand All @@ -39,6 +41,7 @@
"pwmh",
"pwml",
"PWMOUT",
"pySerial",
"regextype",
"twxs",
"USBRX",
Expand Down
12 changes: 12 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,16 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
clang-format \
nodejs \
npm \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& npm -g install cspell

USER vscode

COPY ./script/* /tmp/

RUN /tmp/install-arduino-cli.sh && \
# PATHを設定しているため現行環境でシェルを実行する
. /tmp/install-gcc-arm-none-eabi.sh && \
/tmp/install-mbed-cli-1.sh && \
/tmp/install-mbed-cli-2.sh
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "git config --global --add safe.directory /workspaces/*"
"postCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}"

// Configure tool-specific properties.
// "customizations": {},
Expand Down
43 changes: 43 additions & 0 deletions .devcontainer/script/install-arduino-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
#
# Arduino CLI のインストールとセットアップをする
#
# 参考: https://arduino.github.io/arduino-cli/0.33/installation/

set -eu

# Arduino CLI に必要なパッケージをインストール
sudo apt-get update
sudo apt-get -y install --no-install-recommends python3 \
python3-dev \
python-is-python3 \
python3-pip

sudo apt-get clean
sudo rm -rf /var/lib/apt/lists/*

pip3 install pyserial \
esptool

# Installing Arduino CLI
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sudo BINDIR=/usr/local/bin sh

# Setup bash completion
echo 'source <(arduino-cli completion bash)' >>~/.bashrc

# Install supported boards
arduino-cli config init

# ESP32
arduino-cli config add board_manager.additional_urls https://dl.espressif.com/dl/package_esp32_index.json
arduino-cli core update-index
arduino-cli core install esp32:esp32

# STM32
arduino-cli config add board_manager.additional_urls https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
arduino-cli core update-index
arduino-cli core install STMicroelectronics:stm32

# Mbed
arduino-cli core update-index
arduino-cli core install arduino:mbed
32 changes: 32 additions & 0 deletions .devcontainer/script/install-gcc-arm-none-eabi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
#
# GNU Arm Embedded Toolchain のインストール
#
# 参考: https://developer.arm.com/downloads/-/gnu-rm

set -eu

# GNU Arm Embedded Toolchain のバージョン
GCC_ARM_VERSION='10.3-2021.07'

machine=$(uname -m)
if [ "${machine}" = "x86_64" ] || [ "${machine}" = "aarch64" ]; then
url="https://developer.arm.com/-/media/Files/downloads/gnu-rm/${GCC_ARM_VERSION}/gcc-arm-none-eabi-${GCC_ARM_VERSION}-${machine}-linux.tar.bz2"
else
echo "Unsupported architecture: ${machine}"
exit 1
fi

# Check if the file already exists
if [ -f "/usr/local/gcc-arm-none-eabi-${GCC_ARM_VERSION}/bin/arm-none-eabi-gcc" ]; then
echo "gcc-arm-none-eabi-${GCC_ARM_VERSION} is already installed."
exit 0
fi

wget "${url}" -P /tmp/
tar -xvf /tmp/gcc-arm-none-eabi-${GCC_ARM_VERSION}-*-linux.tar.bz2 -C /tmp/
sudo mv /tmp/gcc-arm-none-eabi-${GCC_ARM_VERSION} /usr/local/
rm /tmp/gcc-arm-none-eabi-${GCC_ARM_VERSION}-*-linux.tar.bz2

echo 'export PATH=${PATH}:/usr/local/gcc-arm-none-eabi-'${GCC_ARM_VERSION}'/bin' >> ~/.bashrc
export PATH=/usr/local/gcc-arm-none-eabi-${GCC_ARM_VERSION}/bin:${PATH}
28 changes: 28 additions & 0 deletions .devcontainer/script/install-mbed-cli-1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
#
# Mbed CLI 1 のインストール
#
# 参考: https://os.mbed.com/docs/mbed-os/v6.16/build-tools/install-and-set-up.html

set -eu

# Check if gcc-arm-none-eabi is installed
if ! command -v arm-none-eabi-gcc &> /dev/null
then
echo "Error: gcc-arm-none-eabi is not installed. Please install it and try again."
exit 1
fi

# Mbed CLI 1 に必要なパッケージをインストール
sudo apt-get update
sudo apt-get -y install --no-install-recommends python3 \
python3-pip \
python3-dev \
git \
mercurial

sudo apt-get clean
sudo rm -rf /var/lib/apt/lists/*

# Installing Mbed CLI 1
python3 -m pip install mbed-cli
29 changes: 29 additions & 0 deletions .devcontainer/script/install-mbed-cli-2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
#
# Mbed CLI 2 のインストール
#
# 参考: https://os.mbed.com/docs/mbed-os/v6.16/build-tools/install-or-upgrade.html
#

set -eu

# Check if gcc-arm-none-eabi is installed
if ! command -v arm-none-eabi-gcc &> /dev/null
then
echo "Error: gcc-arm-none-eabi is not installed. Please install it and try again."
exit 1
fi

# Mbed CLI 2 に必要なパッケージをインストール
sudo apt-get update
sudo apt-get -y install --no-install-recommends python3 \
python3-pip \
python3-dev \
ninja-build \
cmake

sudo apt-get clean
sudo rm -rf /var/lib/apt/lists/*

# Installing Mbed CLI 2
python3 -m pip install mbed-tools
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ jobs:
- name: Compile sketch
run: |
arduino-cli compile --fqbn ${{ matrix.fqbn }} --library . .github/workflows/build-arduino-cli
arduino-cli compile --fqbn ${{ matrix.fqbn }} --library . --verbose .github/workflows/build-arduino-cli
52 changes: 43 additions & 9 deletions .github/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ on:
push:
branches:
- main
paths:
- ".devcontainer/**"
pull_request:
branches:
- "main"
paths:
- ".devcontainer/**"
workflow_dispatch:

jobs:
Expand All @@ -16,16 +20,46 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
node-version: 18.x
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Install Dev Container CLI
run: npm install -g @devcontainers/cli
- name: Build and run dev container task
uses: devcontainers/ci@v0.3
with:
imageName: ghcr.io/${{ github.repository }}
cacheFrom: ghcr.io/${{ github.repository }}
push: filter
refFilterForPush: refs/heads/main
runCmd: |
# In runCmd, processing continues except for the last command, even if the exit status is not 0.
set -e
# Arduino CLI
arduino-cli compile --fqbn esp32:esp32:esp32 --library . --verbose .github/workflows/build-arduino-cli
arduino-cli compile --fqbn STMicroelectronics:stm32:GenF3 --library . --verbose .github/workflows/build-arduino-cli
arduino-cli compile --fqbn arduino:mbed:pico --library . --verbose .github/workflows/build-arduino-cli
- name: Building image
run: devcontainer build --workspace-folder .
# Mbed CLI 1
mkdir /tmp/mbed-cli-1
cd /tmp/mbed-cli-1
mbed new .
mbed deploy
ln -s /workspaces/spirit
cp /workspaces/spirit/.github/workflows/build-mbed/main.cpp .
mbed compile -t GCC_ARM -m NUCLEO_F303K8 --profile release
# Remove build directory to save disk space
rm -rf /tmp/mbed-cli-1
- name: Spins up containers
run: devcontainer up --workspace-folder .
# Mbed CLI 2
mkdir /tmp/mbed-cli-2
cd /tmp/mbed-cli-2
mbed-tools new .
mbed-tools deploy
ln -s /workspaces/spirit
cp /workspaces/spirit/.github/workflows/build-mbed/main.cpp .
cp /workspaces/spirit/.github/workflows/build-mbed-tools/CMakeLists.txt .
mbed-tools compile -t GCC_ARM -m NUCLEO_F303K8 --profile release

0 comments on commit 1eeeb90

Please sign in to comment.