From 7f1bee6c4dd3ef4fb11e71c7334b442e37500a6a Mon Sep 17 00:00:00 2001 From: Marcin Anforowicz Date: Mon, 16 Sep 2024 12:02:45 -0700 Subject: [PATCH 1/6] Added files required for ESP-IDF component. --- .github/workflows/esp_dry_run.yml | 24 ++++++++++++++++++++++++ .github/workflows/esp_publish.yml | 23 +++++++++++++++++++++++ CMakeLists.txt | 17 +++++++++++++++++ Kconfig | 23 +++++++++++++++++++++++ idf_component.yml | 9 +++++++++ 5 files changed, 96 insertions(+) create mode 100644 .github/workflows/esp_dry_run.yml create mode 100644 .github/workflows/esp_publish.yml create mode 100644 CMakeLists.txt create mode 100644 Kconfig create mode 100644 idf_component.yml diff --git a/.github/workflows/esp_dry_run.yml b/.github/workflows/esp_dry_run.yml new file mode 100644 index 0000000..2883883 --- /dev/null +++ b/.github/workflows/esp_dry_run.yml @@ -0,0 +1,24 @@ +# 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 ESP-IDF component upload. +on: + workflow_dispatch: + +jobs: + upload_components: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: "recursive" + + - name: Dry-run upload to the ESP component registry + uses: espressif/upload-components-ci-action@v1 + with: + dry_run: True + name: "libcanard" + version: ${{ github.event.release.tag_name }} + namespace: "opencyphal" + api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }} diff --git a/.github/workflows/esp_publish.yml b/.github/workflows/esp_publish.yml new file mode 100644 index 0000000..9111d89 --- /dev/null +++ b/.github/workflows/esp_publish.yml @@ -0,0 +1,23 @@ +# This workflow gets triggered when a GitHub release is published. +# It publishes this project to the ESP component registry. + +name: Publish component to https://components.espressif.com +on: + release: + types: [published] + +jobs: + upload_components: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: "recursive" + + - name: Upload to the ESP component registry + uses: espressif/upload-components-ci-action@v1 + with: + name: "libcanard" + version: ${{ github.event.release.tag_name }} + namespace: "opencyphal" + api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ac7ab6f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,17 @@ +# This file sets up builds if libcanard is used +# as an ESP-IDF component. + +idf_component_register(SRCS "libcanard/canard.c" + INCLUDE_DIRS "libcanard/") + +# 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/Kconfig b/Kconfig new file mode 100644 index 0000000..63f96e1 --- /dev/null +++ b/Kconfig @@ -0,0 +1,23 @@ +# This file defines customizable build options +# if libcanard is used as an ESP-IDF component. +# Configure these values by running 'idf.py menuconfig' in this +# directory. + +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 \ No newline at end of file diff --git a/idf_component.yml b/idf_component.yml new file mode 100644 index 0000000..965cbcc --- /dev/null +++ b/idf_component.yml @@ -0,0 +1,9 @@ +# Metadata for using libcanard as an ESP-IDF component. + +# Note: Version is not specified in this file, +# because the 'esp_publish.yml' GitHub action +# automatically sets it based on the release version. + +description: "OpenCyphal for embedded systems." +url: "https://github.com/OpenCyphal/libcanard" +license: "MIT" From 8ba46ab22c38a0176b36e7d2bd9323070313ced8 Mon Sep 17 00:00:00 2001 From: Marcin Anforowicz Date: Mon, 16 Sep 2024 12:16:13 -0700 Subject: [PATCH 2/6] Added files necessary for ESP component. --- .github/workflows/esp_dry_run.yml | 3 ++- idf_component.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/esp_dry_run.yml b/.github/workflows/esp_dry_run.yml index 2883883..55118fb 100644 --- a/.github/workflows/esp_dry_run.yml +++ b/.github/workflows/esp_dry_run.yml @@ -19,6 +19,7 @@ jobs: with: dry_run: True name: "libcanard" - version: ${{ github.event.release.tag_name }} + # Meaningless version for the purpose of dry run. + version: "0.0.0" namespace: "opencyphal" api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }} diff --git a/idf_component.yml b/idf_component.yml index 965cbcc..6718053 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -6,4 +6,4 @@ description: "OpenCyphal for embedded systems." url: "https://github.com/OpenCyphal/libcanard" -license: "MIT" +license: "MIT" \ No newline at end of file From 3943a03c3498ac28af5582f169948e21c7e3ab10 Mon Sep 17 00:00:00 2001 From: Marcin Anforowicz Date: Tue, 17 Sep 2024 09:16:27 -0700 Subject: [PATCH 3/6] Update idf_component.yml description to mention CAN. Co-authored-by: Pavel Kirienko --- idf_component.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component.yml b/idf_component.yml index 6718053..04cb224 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -4,6 +4,6 @@ # because the 'esp_publish.yml' GitHub action # automatically sets it based on the release version. -description: "OpenCyphal for embedded systems." +description: "Cyphal/CAN for embedded systems." url: "https://github.com/OpenCyphal/libcanard" license: "MIT" \ No newline at end of file From 562d4433a867e4562e6fcca759dd73305e20e79e Mon Sep 17 00:00:00 2001 From: Marcin Anforowicz Date: Tue, 17 Sep 2024 10:40:19 -0700 Subject: [PATCH 4/6] Switched to script to package ESP-IDF component. --- .github/workflows/esp_dry_run.yml | 17 +++++------- .github/workflows/esp_publish.yml | 19 +++++++------- .github/workflows/package_esp_component.sh | 26 +++++++++++++++++++ CMakeLists.txt => esp_metadata/CMakeLists.txt | 9 ++++--- Kconfig => esp_metadata/Kconfig | 10 ++++--- .../idf_component.yml | 7 +++-- 6 files changed, 58 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/package_esp_component.sh rename CMakeLists.txt => esp_metadata/CMakeLists.txt (64%) rename Kconfig => esp_metadata/Kconfig (66%) rename idf_component.yml => esp_metadata/idf_component.yml (56%) diff --git a/.github/workflows/esp_dry_run.yml b/.github/workflows/esp_dry_run.yml index 55118fb..6387511 100644 --- a/.github/workflows/esp_dry_run.yml +++ b/.github/workflows/esp_dry_run.yml @@ -2,12 +2,12 @@ # It does a dry-run of publishing this project to the ESP component registry. # The project won't actually be published. -name: Dry-run ESP-IDF component upload. +name: Dry-run upload to the ESP component registry on: workflow_dispatch: jobs: - upload_components: + upload_component: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -15,11 +15,8 @@ jobs: submodules: "recursive" - name: Dry-run upload to the ESP component registry - uses: espressif/upload-components-ci-action@v1 - with: - dry_run: True - name: "libcanard" - # Meaningless version for the purpose of dry run. - version: "0.0.0" - namespace: "opencyphal" - api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }} + run: | + bash .github/workflows/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 index 9111d89..391a42a 100644 --- a/.github/workflows/esp_publish.yml +++ b/.github/workflows/esp_publish.yml @@ -1,23 +1,22 @@ # This workflow gets triggered when a GitHub release is published. -# It publishes this project to the ESP component registry. +# It publishes this project to the public ESP-IDF component registry. -name: Publish component to https://components.espressif.com +name: Publish component to the ESP-IDF registry on: release: types: [published] jobs: - upload_components: + upload_component: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: submodules: "recursive" - - name: Upload to the ESP component registry - uses: espressif/upload-components-ci-action@v1 - with: - name: "libcanard" - version: ${{ github.event.release.tag_name }} - namespace: "opencyphal" - api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }} + - name: Publish component to the ESP-IDF registry + run: | + bash .github/workflows/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/.github/workflows/package_esp_component.sh b/.github/workflows/package_esp_component.sh new file mode 100644 index 0000000..2500956 --- /dev/null +++ b/.github/workflows/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 "Component successfully packaged ESP component into package/libcanard:" +find package/libcanard +echo diff --git a/CMakeLists.txt b/esp_metadata/CMakeLists.txt similarity index 64% rename from CMakeLists.txt rename to esp_metadata/CMakeLists.txt index ac7ab6f..1593ec9 100644 --- a/CMakeLists.txt +++ b/esp_metadata/CMakeLists.txt @@ -1,8 +1,9 @@ -# This file sets up builds if libcanard is used -# as an ESP-IDF component. +# This file is used when packaging libcanard +# for the ESP-IDF component registry: +# https://components.espressif.com/ -idf_component_register(SRCS "libcanard/canard.c" - INCLUDE_DIRS "libcanard/") +idf_component_register(SRCS "canard.c" + INCLUDE_DIRS "include") # Apply the Kconfig options to the source file. diff --git a/Kconfig b/esp_metadata/Kconfig similarity index 66% rename from Kconfig rename to esp_metadata/Kconfig index 63f96e1..a55c3ab 100644 --- a/Kconfig +++ b/esp_metadata/Kconfig @@ -1,7 +1,9 @@ -# This file defines customizable build options -# if libcanard is used as an ESP-IDF component. -# Configure these values by running 'idf.py menuconfig' in this -# directory. +# 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" diff --git a/idf_component.yml b/esp_metadata/idf_component.yml similarity index 56% rename from idf_component.yml rename to esp_metadata/idf_component.yml index 04cb224..fe3930e 100644 --- a/idf_component.yml +++ b/esp_metadata/idf_component.yml @@ -1,9 +1,12 @@ -# Metadata for using libcanard as an ESP-IDF component. +# 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" -license: "MIT" \ No newline at end of file +repository: "https://github.com/OpenCyphal/libcanard" From cbf9f5dc56f08d9cacf79664a0b039d5b346dab1 Mon Sep 17 00:00:00 2001 From: Marcin Anforowicz Date: Tue, 17 Sep 2024 10:42:05 -0700 Subject: [PATCH 5/6] --amend --- .github/workflows/package_esp_component.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/package_esp_component.sh b/.github/workflows/package_esp_component.sh index 2500956..1a6dbcb 100644 --- a/.github/workflows/package_esp_component.sh +++ b/.github/workflows/package_esp_component.sh @@ -21,6 +21,6 @@ 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 "Component successfully packaged ESP component into package/libcanard:" +echo "Successfully packaged ESP component into package/libcanard:" find package/libcanard echo From 6c7bb6c7262347fb7bcef04f46718a21b3afa4d9 Mon Sep 17 00:00:00 2001 From: Marcin Anforowicz Date: Tue, 17 Sep 2024 14:02:38 -0700 Subject: [PATCH 6/6] Moved script to esp_metadata and added new line. --- .github/workflows/esp_dry_run.yml | 2 +- .github/workflows/esp_publish.yml | 2 +- esp_metadata/Kconfig | 3 +-- {.github/workflows => esp_metadata}/package_esp_component.sh | 0 4 files changed, 3 insertions(+), 4 deletions(-) rename {.github/workflows => esp_metadata}/package_esp_component.sh (100%) diff --git a/.github/workflows/esp_dry_run.yml b/.github/workflows/esp_dry_run.yml index 6387511..695e708 100644 --- a/.github/workflows/esp_dry_run.yml +++ b/.github/workflows/esp_dry_run.yml @@ -16,7 +16,7 @@ jobs: - name: Dry-run upload to the ESP component registry run: | - bash .github/workflows/package_esp_component.sh + 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 index 391a42a..90b7016 100644 --- a/.github/workflows/esp_publish.yml +++ b/.github/workflows/esp_publish.yml @@ -16,7 +16,7 @@ jobs: - name: Publish component to the ESP-IDF registry run: | - bash .github/workflows/package_esp_component.sh + 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/Kconfig b/esp_metadata/Kconfig index a55c3ab..8e89e7f 100644 --- a/esp_metadata/Kconfig +++ b/esp_metadata/Kconfig @@ -21,5 +21,4 @@ config CANARD_CRC_TABLE Doing so is expected to save ca. 500 bytes of ROM and increase the cost of RX/TX transfer processing by ~half. - -endmenu \ No newline at end of file +endmenu diff --git a/.github/workflows/package_esp_component.sh b/esp_metadata/package_esp_component.sh similarity index 100% rename from .github/workflows/package_esp_component.sh rename to esp_metadata/package_esp_component.sh