diff --git a/.github/workflows/esp_dry_run.yml b/.github/workflows/esp_dry_run.yml new file mode 100644 index 0000000..695e708 --- /dev/null +++ b/.github/workflows/esp_dry_run.yml @@ -0,0 +1,22 @@ +# This workflow only runs when it is manually dispatched using GitHub. +# It does a dry-run of publishing this project to the ESP component registry. +# The project won't actually be published. + +name: Dry-run upload to the ESP component registry +on: + workflow_dispatch: + +jobs: + upload_component: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: "recursive" + + - name: Dry-run upload to the ESP component registry + run: | + bash esp_metadata/package_esp_component.sh + export IDF_COMPONENT_API_TOKEN="${{ secrets.IDF_COMPONENT_API_TOKEN }}" + cd package/libcanard + compote component upload --namespace opencyphal --name libcanard --version 0.0.0 --dry-run diff --git a/.github/workflows/esp_publish.yml b/.github/workflows/esp_publish.yml new file mode 100644 index 0000000..90b7016 --- /dev/null +++ b/.github/workflows/esp_publish.yml @@ -0,0 +1,22 @@ +# This workflow gets triggered when a GitHub release is published. +# It publishes this project to the public ESP-IDF component registry. + +name: Publish component to the ESP-IDF registry +on: + release: + types: [published] + +jobs: + upload_component: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: "recursive" + + - name: Publish component to the ESP-IDF registry + run: | + bash esp_metadata/package_esp_component.sh + export IDF_COMPONENT_API_TOKEN="${{ secrets.IDF_COMPONENT_API_TOKEN }}" + cd package/libcanard + compote component upload --namespace opencyphal --name libcanard --version ${{ github.event.release.tag_name }} diff --git a/esp_metadata/CMakeLists.txt b/esp_metadata/CMakeLists.txt new file mode 100644 index 0000000..1593ec9 --- /dev/null +++ b/esp_metadata/CMakeLists.txt @@ -0,0 +1,18 @@ +# This file is used when packaging libcanard +# for the ESP-IDF component registry: +# https://components.espressif.com/ + +idf_component_register(SRCS "canard.c" + INCLUDE_DIRS "include") + +# Apply the Kconfig options to the source file. + +if(NOT CONFIG_CANARD_ASSERTIONS) + target_compile_definitions(${COMPONENT_LIB} PRIVATE "CANARD_ASSERT=(void)") +endif() + +if(CONFIG_CANARD_CRC_TABLE) + target_compile_definitions(${COMPONENT_LIB} PRIVATE CANARD_CRC_TABLE=1) +else() + target_compile_definitions(${COMPONENT_LIB} PRIVATE CANARD_CRC_TABLE=0) +endif() diff --git a/esp_metadata/Kconfig b/esp_metadata/Kconfig new file mode 100644 index 0000000..8e89e7f --- /dev/null +++ b/esp_metadata/Kconfig @@ -0,0 +1,24 @@ +# This file is used when packaging libcanard +# for the ESP-IDF component registry: +# https://components.espressif.com/ + +# This file defines customizable ESP-IDF build options +# that can be configured by running 'idf.py menuconfig'. + +menu "Libcanard" + +config CANARD_ASSERTIONS + bool "Enable libcanard assertions." + default y + help + Set to 'n' to disable libcanard assertions. + +config CANARD_CRC_TABLE + bool "Enable libcanard CRC table" + default y + help + Set to 'n' to use slow but ROM-efficient transfer-CRC computation algorithm. + Doing so is expected to save ca. 500 bytes of ROM and + increase the cost of RX/TX transfer processing by ~half. + +endmenu diff --git a/esp_metadata/idf_component.yml b/esp_metadata/idf_component.yml new file mode 100644 index 0000000..fe3930e --- /dev/null +++ b/esp_metadata/idf_component.yml @@ -0,0 +1,12 @@ +# This file is used when packaging libcanard +# for the ESP-IDF component registry: +# https://components.espressif.com/ + +# Note: Version is not specified in this file, +# because the 'esp_publish.yml' GitHub action +# automatically sets it based on the release version. + +description: "Cyphal/CAN for embedded systems." +license: "MIT" +url: "https://github.com/OpenCyphal/libcanard" +repository: "https://github.com/OpenCyphal/libcanard" diff --git a/esp_metadata/package_esp_component.sh b/esp_metadata/package_esp_component.sh new file mode 100644 index 0000000..1a6dbcb --- /dev/null +++ b/esp_metadata/package_esp_component.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -e + +# This script must be called from the root of this repository. +# It packages up libcanard as an ESP-IDF component in package/libcanard. + +mkdir -p package/libcanard/include + +cp CONTRIBUTING.md package/libcanard/CONTRIBUTING.md +cp LICENSE package/libcanard/LICENSE +cp README.md package/libcanard/README.md + +cp libcanard/canard.c package/libcanard/canard.c +cp libcanard/_canard_cavl.h package/libcanard/_canard_cavl.h +cp libcanard/canard.h package/libcanard/include/canard.h + +cp esp_metadata/CMakeLists.txt package/libcanard/CMakeLists.txt +cp esp_metadata/Kconfig package/libcanard/Kconfig +cp esp_metadata/idf_component.yml package/libcanard/idf_component.yml + +# Install compote, a tool for uploading ESP-IDF components. +python3 -m pip install --upgrade idf-component-manager + +echo "Successfully packaged ESP component into package/libcanard:" +find package/libcanard +echo