diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1226fe3..a0edb27 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,37 +8,11 @@ jobs: fail-fast: false matrix: runs-on: [ubuntu-latest] + target: [esp32, esp32s2, esp32s3, esp32c3, esp32h2, esp32p4] runs-on: ${{ matrix.runs-on }} steps: - uses: actions/checkout@v4 - - uses: korandoru/setup-zig@v1 + - uses: espressif/esp-idf-ci-action@v1 with: - zig-version: master - - - name: prepare-linux - run: | - sudo apt-get update - sudo apt-get install -y cmake - git clone --recursive https://github.com/espressif/esp-idf -b v5.3-dev --depth 1 - cd esp-idf && chmod +x ./install.sh && ./install.sh - chmod +x ./export.sh && source ./export.sh - cd .. - - - name: Build for esp32-c3 - run: | - idf.py set-target esp32c3 - idf.py build - idf.py size - idf.py fullclean - - name: Build for esp32-h2 - run: | - idf.py set-target esp32h2 - idf.py build - idf.py size - idf.py fullclean - - name: Build for esp32-p4 - run: | - idf.py --preview set-target esp32p4 - idf.py build - idf.py size - idf.py fullclean + esp_idf_version: v5.2 + target: ${{ matrix.target }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ea3896..a529ac2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,5 +3,5 @@ cmake_minimum_required(VERSION 3.5) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -set(SDKCONFIG_DEFAULTS sdkconfig.defaults) +set(BUILD_PATH ${CMAKE_CURRENT_SOURCE_DIR}) project(zig-sample-idf) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 1445977..1ae9e8b 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -6,6 +6,45 @@ idf_component_register(SRCS "placeholder.c" set(include_dirs $ ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}) set(link_libs $ ${CMAKE_C_IMPLICIT_LINK_LIBRARIES}) + +# Detect target architecture and platform +if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + set(TARGET_ARCH "x86_64") +elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64") + set(TARGET_ARCH "aarch64") +else() + message(FATAL_ERROR "Unsupported architecture") +endif() + +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + set(TARGET_PLATFORM "linux-musl") +elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + set(TARGET_PLATFORM "windows-gnu") +elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + set(TARGET_PLATFORM "macos-none") +else() + message(FATAL_ERROR "Unsupported platform") +endif() + +if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/zig-${TARGET_ARCH}-relsafe-espressif-${TARGET_PLATFORM}-baseline") + file(DOWNLOAD "https://github.com/kassane/zig-espressif-bootstrap/releases/download/0.12.0-dev/zig-${TARGET_ARCH}-relsafe-espressif-${TARGET_PLATFORM}-baseline.tar.xz" + "${CMAKE_CURRENT_BINARY_DIR}/zig.tar.xz") + + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + execute_process( + COMMAND powershell -Command "Expand-Archive -Path ${CMAKE_CURRENT_BINARY_DIR}/zig.tar.xz -DestinationPath ${CMAKE_CURRENT_BINARY_DIR}" + ) + else() + execute_process( + COMMAND ${CMAKE_COMMAND} -E tar xf ${CMAKE_CURRENT_BINARY_DIR}/zig.tar.xz + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + endif() +else() + message(STATUS "Zig already downloaded. Skipping zig install.") +endif() +set(ZIG_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/zig-${TARGET_ARCH}-relsafe-espressif-${TARGET_PLATFORM}-baseline) + if(CONFIG_IDF_TARGET_ARCH_RISCV) set(ZIG_TARGET "riscv32-freestanding-none") if(CONFIG_IDF_TARGET_ESP32C6 OR CONFIG_IDF_TARGET_ESP32C5 OR CONFIG_IDF_TARGET_ESP32H2) @@ -32,15 +71,15 @@ endif() if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(ZIG_BUILD_TYPE "Debug") else() - set(ZIG_BUILD_TYPE "ReleaseSmall") + set(ZIG_BUILD_TYPE "ReleaseSafe") endif() add_custom_target(zig_build COMMAND ${CMAKE_COMMAND} -E env "INCLUDE_DIRS=${include_dirs}" "LIBRARIES=${link_libs}" - zig build - --build-file ${CMAKE_CURRENT_SOURCE_DIR}/../build.zig + ${ZIG_INSTALL}/zig build + --build-file ${BUILD_PATH}/build.zig -Doptimize=${ZIG_BUILD_TYPE} -Dtarget=${ZIG_TARGET} -Dcpu=${TARGET_CPU_MODEL}