From ac7fa231afffbc778d858dd9e7226c4f62ff9e04 Mon Sep 17 00:00:00 2001
From: Ivan Grokhotkov <ivan@espressif.com>
Date: Wed, 3 Nov 2021 17:23:56 +0100
Subject: [PATCH 1/5] cmake: error out of IDF version is outside of supported
 range

---
 CMakeLists.txt | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d70ac76938d..4923791f946 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,3 +1,27 @@
+# Check ESP-IDF version and error out if it is not in the supported range.
+#
+# Note for arduino-esp32 developers: to bypass the version check locally,
+# set ARDUINO_SKIP_IDF_VERSION_CHECK environment variable to 1. For example:
+#   export ARDUINO_SKIP_IDF_VERSION_CHECK=1
+#   idf.py build
+
+set(min_supported_idf_version "4.4.0")
+set(max_supported_idf_version "4.4.99")
+set(idf_version "${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}.${IDF_VERSION_PATCH}")
+
+if ("${idf_version}" AND NOT "$ENV{ARDUINO_SKIP_IDF_VERSION_CHECK}")
+  if (idf_version VERSION_LESS min_supported_idf_version)
+    message(FATAL_ERROR "Arduino-esp32 can be used with ESP-IDF versions "
+                        "between ${min_supported_idf_version} and ${max_supported_idf_version}, "
+                        "but an older version is detected: ${idf_version}.")
+  endif()
+  if (idf_version VERSION_GREATER max_supported_idf_version)
+    message(FATAL_ERROR "Arduino-esp32 can be used with ESP-IDF versions "
+                        "between ${min_supported_idf_version} and ${max_supported_idf_version}, "
+                        "but a newer version is detected: ${idf_version}.")
+  endif()
+endif()
+
 set(CORE_SRCS
   cores/esp32/base64.cpp
   cores/esp32/cbuf.cpp

From 23765b7f3a092c8e51ee001e1984c400753186bd Mon Sep 17 00:00:00 2001
From: Ivan Grokhotkov <ivan@espressif.com>
Date: Wed, 3 Nov 2021 17:40:39 +0100
Subject: [PATCH 2/5] ci: run CMake in script mode when finding source files

---
 .github/scripts/check-cmakelists.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/scripts/check-cmakelists.sh b/.github/scripts/check-cmakelists.sh
index 8495667ba3c..89141ac6e3f 100755
--- a/.github/scripts/check-cmakelists.sh
+++ b/.github/scripts/check-cmakelists.sh
@@ -15,7 +15,7 @@ git submodule update --init --recursive
 REPO_SRCS=`find cores/esp32/ libraries/ -name 'examples' -prune -o -name '*.c' -print -o -name '*.cpp' -print | sort`
 
 # find all source files named in CMakeLists.txt COMPONENT_SRCS
-CMAKE_SRCS=`cmake --trace-expand -C CMakeLists.txt 2>&1 | grep set\(srcs | cut -d'(' -f3 | sed 's/ )//' | sed 's/srcs //' | tr ' ;' '\n' | sort`
+CMAKE_SRCS=`cmake --trace-expand -P CMakeLists.txt 2>&1 | grep set\(srcs | cut -d'(' -f3 | sed 's/ )//' | sed 's/srcs //' | tr ' ;' '\n' | sort`
 
 if ! diff -u0 --label "Repo Files" --label "srcs" <(echo "$REPO_SRCS") <(echo "$CMAKE_SRCS"); then
     echo "Source files in repo (-) and source files in CMakeLists.txt (+) don't match"

From b65b9563a3a9c45ffa12f10f4b402daf3999d3de Mon Sep 17 00:00:00 2001
From: Ivan Grokhotkov <ivan@espressif.com>
Date: Wed, 3 Nov 2021 17:23:32 +0100
Subject: [PATCH 3/5] ci: validate building as ESP-IDF component

---
 .github/workflows/push.yml | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml
index e8aec98166c..2224d5bb9f9 100644
--- a/.github/workflows/push.yml
+++ b/.github/workflows/push.yml
@@ -56,3 +56,30 @@ jobs:
         python-version: '3.x'
     - name: Build Sketches
       run: bash ./.github/scripts/on-push.sh 1 1 #equal and non-zero to trigger PIO
+
+  build-esp-idf-component:
+    name: Build with ESP-IDF ${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
+    runs-on: ubuntu-20.04
+    strategy:
+      matrix:
+        # The version names here correspond to the versions of espressif/idf Docker image.
+        # See https://hub.docker.com/r/espressif/idf/tags and
+        # https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-docker-image.html
+        # for details.
+        idf_ver: ["release-v4.4"]
+        idf_target: ["esp32", "esp32s2", "esp32c3"]
+    container: espressif/idf:${{ matrix.idf_ver }}
+    steps:
+      - name: Check out arduino-esp32 as a component
+        uses: actions/checkout@v2
+        with:
+          submodules: recursive
+          path: components/arduino-esp32
+      - name: Build
+        env:
+          IDF_TARGET: ${{ matrix.idf_target }}
+        shell: bash
+        run: |
+          . ${IDF_PATH}/export.sh
+          idf.py create-project test
+          idf.py -C test -DEXTRA_COMPONENT_DIRS=$PWD/../components build

From 300777bd6b593475ab1fd2160a694e943ceb2af1 Mon Sep 17 00:00:00 2001
From: Me No Dev <me-no-dev@users.noreply.github.com>
Date: Mon, 22 Nov 2021 17:18:47 +0200
Subject: [PATCH 4/5] Fix component path

---
 .github/workflows/push.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml
index 2224d5bb9f9..3fd9475e1d5 100644
--- a/.github/workflows/push.yml
+++ b/.github/workflows/push.yml
@@ -82,4 +82,4 @@ jobs:
         run: |
           . ${IDF_PATH}/export.sh
           idf.py create-project test
-          idf.py -C test -DEXTRA_COMPONENT_DIRS=$PWD/../components build
+          idf.py -C test -DEXTRA_COMPONENT_DIRS=$PWD/components build

From bb1c169501750acc5e9709ff3dc28f0d6d82f093 Mon Sep 17 00:00:00 2001
From: Me No Dev <me-no-dev@users.noreply.github.com>
Date: Tue, 26 Apr 2022 14:15:06 +0300
Subject: [PATCH 5/5] Add ESP32-S3 to the test targets

---
 .github/workflows/push.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml
index 3fd9475e1d5..c63e9cdc33d 100644
--- a/.github/workflows/push.yml
+++ b/.github/workflows/push.yml
@@ -67,7 +67,7 @@ jobs:
         # https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-docker-image.html
         # for details.
         idf_ver: ["release-v4.4"]
-        idf_target: ["esp32", "esp32s2", "esp32c3"]
+        idf_target: ["esp32", "esp32s2", "esp32s3", "esp32c3"]
     container: espressif/idf:${{ matrix.idf_ver }}
     steps:
       - name: Check out arduino-esp32 as a component