Skip to content

Commit

Permalink
Merge pull request #12 from kassane/zig
Browse files Browse the repository at this point in the history
Zig + IDF support
  • Loading branch information
georgik authored Mar 28, 2024
2 parents 0d67bfa + 14eac99 commit c7562a5
Show file tree
Hide file tree
Showing 13 changed files with 475 additions and 54 deletions.
201 changes: 201 additions & 0 deletions .github/workflows/build-zig-esp-idf-hello-world.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
name: Build ESP32 (ZIG) ESP-IDF binaries and upload to GitHub Release

on:
workflow_dispatch:
inputs:
release_tag:
description: "Upload to specific release"
required: true
default: 'v0.1.0'
skip_projects:
description: "Skip projects during build (e.g. esp32-c3-devkit-rust)"
required: false
default: ''

jobs:
get_release:
name: Get release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.get_upload_url.outputs.url }}
steps:
- uses: octokit/[email protected]
id: get_release
with:
route: GET /repos/{owner}/{repo}/releases/tags/${{ github.event.inputs.release_tag }}
owner: georgik
repo: esp32-lang-lab
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: get upload url
id: get_upload_url
run: |
url=$(echo "$response" | jq -r '.upload_url' | sed 's/{?name,label}//')
echo "url=$url" >> $GITHUB_OUTPUT
env:
response: ${{ steps.get_release.outputs.data }}

build:
runs-on: ubuntu-22.04
container:
image: espressif/idf:release-v5.1
needs: get_release
steps:
- name: Clone repository with specific branch
shell: bash
run: |
export HOME=/home/esp
mkdir -p /home/esp
cd /home/esp
pwd
git clone --depth 1 --branch ${{ github.ref_name }} https://github.com/georgik/esp32-lang-lab.git esp32-lang-lab
set +e # Workaround for Exit code 2 exit code installation
curl -L https://wokwi.com/ci/install.sh | sh
exit_code=$?
if [ $exit_code -eq 2 ]; then
echo "Received exit code 2 from install script, overriding to 0"
exit_code=0
else
exit $exit_code
fi
set -e
- name: Build and upload binaries
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WOKWI_CLI_TOKEN: ${{ secrets.WOKWI_CLI_TOKEN }}
shell: bash
run: |
source /opt/esp/idf/export.sh
# Workaround GitHub issue with setting HOME in container https://github.com/actions/runner/issues/863
export HOME=/home/esp
export SUPPORT_DIR="${HOME}/esp32-lang-lab/support"
export PROJECT="${HOME}/esp32-lang-lab/examples/zig/esp-idf-v5/get-started/hello_world/"
cd /home/esp
source /opt/esp/idf/export.sh
# Install jq - workaround when running in the image without jq
apt-get update && apt-get install -y jq
echo "Project path: ${PROJECT}"
cd ${PROJECT}
# Prepare report
echo '[]' > results.json
for TARGET in esp32 esp32s2 esp32s3 esp32c3 esp32c6 esp32h2; do
echo "Building $TARGET"
OUTPUT_PREFIX="zig-esp-idf-v5-hello-world-${TARGET}-${{ github.event.inputs.release_tag }}"
OUTPUT_BIN="build/hello_world_zig.bin"
OUTPUT_TXT="${OUTPUT_PREFIX}.txt"
# If TARGET is a substring in SKIP_PROJECTS, skip it
#if echo "${{ github.event.inputs.skip_projects }}" | grep -q "${TARGET}"; then
# echo "Skipping $TARGET"
# continue
#fi
idf.py set-target "${TARGET}"
idf.py build
# Prepare Wokwi test
cp ${SUPPORT_DIR}/wokwi/diagram-${TARGET}.json diagram.json
echo '[wokwi]' > wokwi.toml
echo 'version = 1' >> wokwi.toml
echo 'elf = "build/hello_world_zig.elf"' >> wokwi.toml
echo 'firmware = "build/hello_world_zig.bin"' >> wokwi.toml
# Run Wokwi test
/home/esp/bin/wokwi-cli --timeout 5000 \
--timeout-exit-code 0 \
--serial-log-file ${PROJECT}/${OUTPUT_TXT} \
--elf ${OUTPUT_BIN} \
"."
# Upload binary
asset_path="${PROJECT}/${OUTPUT_BIN}"
asset_name="${OUTPUT_PREFIX}.bin"
curl \
--request POST \
--header "authorization: Bearer $GITHUB_TOKEN" \
--header "Content-Type: application/octet-stream" \
--data-binary "@$asset_path" \
--url "${{ needs.get_release.outputs.upload_url }}?name=${asset_name}"
# Upload log
asset_path="${PROJECT}/${OUTPUT_TXT}"
asset_name="${OUTPUT_TXT}"
curl \
--request POST \
--header "authorization: Bearer $GITHUB_TOKEN" \
--header "Content-Type: application/octet-stream" \
--data-binary "@$asset_path" \
--url "${{ needs.get_release.outputs.upload_url }}?name=${asset_name}"
# Extract heap size (you might need to adjust the parsing command)
HEAP_SIZE=$(grep 'Minimum free heap size' ${OUTPUT_TXT} | sed -e 's/Minimum free heap size: //' -e 's/ bytes//')
# Add a new record to the JSON database
jq --arg target "$TARGET" \
--arg language "ZIG" \
--arg flavor "ESP-IDF" \
--arg example "hello-world" \
--arg property "heap" \
--arg value "$HEAP_SIZE" \
--arg unit "bytes" \
--arg note "" \
--arg version "4.4.6" \
--arg timestamp "$(date -Iseconds)" \
'. += [{
target: $target,
language: $language,
flavor: $flavor,
example: $example,
property: $property,
value: $value,
unit: $unit,
note: $note,
version: $version,
timestamp: $timestamp
}]' results.json > temp.json && mv temp.json results.json
# If skip-wokwi-test.toml exists, skip Wokwi test
#if [ ! -f "skip-wokwi-test.toml" ]; then
# asset_path="/home/esp/project/${TARGET}/screenshot.png"
# asset_name="spooky-maze-${TARGET}-${{ github.event.inputs.release_tag }}.png"
# curl \
# --request POST \
# --header "authorization: Bearer $GITHUB_TOKEN" \
# --header "Content-Type: application/octet-stream" \
# --data-binary "@$asset_path" \
# --url "${{ needs.get_release.outputs.upload_url }}?name=${asset_name}"
#fi
done
# Generate report
echo "| Target | Language | Flavor | Example | Property | Value | Unit | Note | Version | Timestamp |" > report.md
echo "|--------|----------|--------|---------|----------|-------|------|------|---------|-----------|" >> report.md
jq -r '.[] | "| \(.target) | \(.language) | \(.flavor) | \(.example) | \(.property) | \(.value) | \(.unit) | \(.note) | \(.version) | \(.timestamp) |"' results.json >> report.md
asset_path="report.md"
asset_name="zig-esp-idf-hello-world-report.md"
curl \
--request POST \
--header "authorization: Bearer $GITHUB_TOKEN" \
--header "Content-Type: application/octet-stream" \
--data-binary "@$asset_path" \
--url "${{ needs.get_release.outputs.upload_url }}?name=${asset_name}"
asset_path="results.json"
asset_name="zig-esp-idf-hello-world-results.json"
curl \
--request POST \
--header "authorization: Bearer $GITHUB_TOKEN" \
--header "Content-Type: application/octet-stream" \
--data-binary "@$asset_path" \
--url "${{ needs.get_release.outputs.upload_url }}?name=${asset_name}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build/
managed_components/
target/
zig-*/
98 changes: 49 additions & 49 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,74 +9,74 @@ Then the application waits for 10 seconds before rebooting.

### Results for ESP32:

| | ESP-IDF C | Arduino | CircuitPython | MicroPython | Rust no_std | Rust std | Toit |
|-------------|------------|------------|---------------|-------------|-------------|----------|------|
| Chip Target | ESP32 | n/a | n/a | n/a | n/a | | n/a |
| CPU Cores | 2 | 2 | n/a | n/a | n/a | | n/a |
| Features | WiFi/BTBLE | WiFi/BTBLE | n/a | n/a | n/a | | n/a |
| Flash size | 2MB [^1] | 4MB | 8192 (?)[^4] | 4 MB | n/a | | n/a |
| Free heap | 300892 | 237568 | 113424 | 164064 | 179200 [^2] | 296028 | n/a |
| | ESP-IDF C | Arduino | CircuitPython | MicroPython | Rust no_std | Rust std | Toit |ESP-IDF ZIG |
|-------------|------------|------------|---------------|-------------|-------------|----------|------|------------|
| Chip Target | ESP32 | n/a | n/a | n/a | n/a | | n/a | |
| CPU Cores | 2 | 2 | n/a | n/a | n/a | | n/a | |
| Features | WiFi/BTBLE | WiFi/BTBLE | n/a | n/a | n/a | | n/a | |
| Flash size | 2MB [^1] | 4MB | 8192 (?)[^4] | 4 MB | n/a | | n/a | |
| Free heap | 300892 | 237568 | 113424 | 164064 | 179200 [^2] | 296028 | n/a | |

### Results for ESP32-S2:

| | ESP-IDF C | Arduino | CircuitPython | MicroPython | Rust no_std | Rust std | Toit |
|-------------|------------|------------|---------------|-------------|-------------|----------|------|
| Chip Target | esp32s2 | n/a | | | | | |
| CPU Cores | 1 | 1 | | | | | |
| Features | WiFi | WiFi | | | | | |
| Flash size | 2MB [^1] | 4MB | | | | | |
| Free heap | 246696 | 229688 | 70848 | 2059520 | 178176 [^3] | 246844 | |
| | ESP-IDF C | Arduino | CircuitPython | MicroPython | Rust no_std | Rust std | Toit |ESP-IDF ZIG |
|-------------|------------|------------|---------------|-------------|-------------|----------|------|------------|
| Chip Target | esp32s2 | n/a | | | | | | |
| CPU Cores | 1 | 1 | | | | | | |
| Features | WiFi | WiFi | | | | | | |
| Flash size | 2MB [^1] | 4MB | | | | | | |
| Free heap | 246696 | 229688 | 70848 | 2059520 | 178176 [^3] | 246844 | | |


### Results for ESP32-S3:

| | ESP-IDF C | Arduino | CircuitPython | MicroPython | Rust no_std | Rust std | Toit |
|-------------|------------|------------|---------------|-------------|-------------|----------|------|
| Chip Target | esp32s3 | n/a | | | | | |
| CPU Cores | 2 | 2 | | | | | |
| Features | WiFi/BLE | WiFi/BLE | | | | | |
| Flash size | 2MB [^1] | 8MB external | | | | | |
| Free heap | 386744 | 36992 | 150432 | | 332800 | 388016 | |
| | ESP-IDF C | Arduino | CircuitPython | MicroPython | Rust no_std | Rust std | Toit |ESP-IDF ZIG |
|-------------|------------|------------|---------------|-------------|-------------|----------|------|------------|
| Chip Target | esp32s3 | n/a | | | | | | |
| CPU Cores | 2 | 2 | | | | | | |
| Features | WiFi/BLE | WiFi/BLE | | | | | | |
| Flash size | 2MB [^1] | 8MB external | | | | | | |
| Free heap | 386744 | 36992 | 150432 | | 332800 | 388016 | | |

### Results for ESP32-C3:

| | ESP-IDF C | Arduino | CircuitPython | MicroPython | Rust no_std | Rust std | Toit |
|-------------|------------|------------|---------------|-------------|-------------|----------|------|
| Chip Target | esp32c3 | | | | | | |
| CPU Cores | 1 | | | | | | |
| Features | WiFi/BLE | | | | | | |
| Flash size | 2MB [^1] | | | | | | |
| Free heap | 327840 | | 129808 | | 322556 | 327124 | |
| | ESP-IDF C | Arduino | CircuitPython | MicroPython | Rust no_std | Rust std | Toit |ESP-IDF ZIG |
|-------------|------------|------------|---------------|-------------|-------------|----------|------|------------|
| Chip Target | esp32c3 | | | | | | | |
| CPU Cores | 1 | | | | | | | |
| Features | WiFi/BLE | | | | | | | |
| Flash size | 2MB [^1] | | | | | | | |
| Free heap | 327840 | | 129808 | | 322556 | 327124 | | |

### Results for ESP32-C6:

| | ESP-IDF C | Arduino | CircuitPython | MicroPython | Rust no_std | Rust std | Toit |
|-------------|------------|------------|---------------|-------------|-------------|----------|------|
| Chip Target | esp32c6 | Not supported | | | | | |
| CPU Cores | 1 | | | | | | |
| Features | WiFi/BLE 802.15.4 (Zigbee/Thread) | | | | | | |
| Flash size | 2MB (1.) | | | | | | |
| Free heap | 468852 | | | | 440316 | 471068 | |
| | ESP-IDF C | Arduino | CircuitPython | MicroPython | Rust no_std | Rust std | Toit |ESP-IDF ZIG |
|-------------|------------|------------|---------------|-------------|-------------|----------|------|------------|
| Chip Target | esp32c6 | Not supported | | | | | | |
| CPU Cores | 1 | | | | | | | |
| Features | WiFi/BLE 802.15.4 (Zigbee/Thread) | | | | | | | |
| Flash size | 2MB (1.) | | | | | | | |
| Free heap | 468852 | | | | 440316 | 471068 | | |

### Results for ESP32-H2:

| | ESP-IDF C | Arduino | CircuitPython | MicroPython | Rust no_std | Rust std | Toit |
|-------------|------------|------------|---------------|-------------|-------------|----------|------|
| Chip Target | esp32h2 | Not supported | | | | | |
| CPU Cores | 1 | | | | | | |
| Features | BLE, 802.15.4 (Zigbee/Thread) | | | | | | |
| Flash size | 2MB [^1] | | | | | | |
| Free heap | 262644 | | | | 252924 | 265060 | |
| | ESP-IDF C | Arduino | CircuitPython | MicroPython | Rust no_std | Rust std | Toit |ESP-IDF ZIG |
|-------------|------------|------------|---------------|-------------|-------------|----------|------|------------|
| Chip Target | esp32h2 | Not supported | | | | | | |
| CPU Cores | 1 | | | | | | | |
| Features | BLE, 802.15.4 (Zigbee/Thread) | | | | | | | |
| Flash size | 2MB [^1] | | | | | | | |
| Free heap | 262644 | | | | 252924 | 265060 | | |

### Results for ESP32-P4:

| | ESP-IDF C | Arduino | CircuitPython | MicroPython | Rust no_std | Rust std | Toit |
|-------------|------------|------------|---------------|-------------|-------------|----------|------|
| Chip Target | esp32p4 | Not supported | | | | | |
| CPU Cores | 2 | | | | | | |
| Features | none | | | | | | |
| Flash size | 2MB [^1] | | | | | | |
| Free heap | 618680 | | | | | | |
| | ESP-IDF C | Arduino | CircuitPython | MicroPython | Rust no_std | Rust std | Toit |ESP-IDF ZIG |
|-------------|------------|------------|---------------|-------------|-------------|----------|------|------------|
| Chip Target | esp32p4 | Not supported | | | | | | |
| CPU Cores | 2 | | | | | | | |
| Features | none | | | | | | | |
| Flash size | 2MB [^1] | | | | | | | |
| Free heap | 618680 | | | | | | | |


## Notes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(BUILD_PATH ${CMAKE_CURRENT_SOURCE_DIR})
project(hello_world_zig)
Loading

0 comments on commit c7562a5

Please sign in to comment.