Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add esp32 build document and ci Refs #5536 #5567

Merged
merged 5 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/esp32.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: ESP32
on:
push:
branches: [master]
paths:
- '.github/workflows/esp32.yml'
- 'CMakeLists.txt'
- 'cmake/**'
- 'src/*'
- 'src/layer/*'
pull_request:
branches: [master]
paths:
- '.github/workflows/esp32.yml'
- 'CMakeLists.txt'
- 'cmake/**'
- 'src/*'
- 'src/layer/*'

concurrency:
group: esp32-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
build:
name: ESP32
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.8'

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake ninja-build ccache

- name: Checkout ESP-IDF
uses: actions/checkout@v4
with:
repository: espressif/esp-idf
path: esp-idf-install
ref: release/v5.3

- name: Install ESP-IDF
run: |
cd esp-idf-install
git submodule update --init --recursive
./install.sh

- name: Set environment and build NCNN for ESP32
run: |
source esp-idf-install/export.sh
echo "IDF_PATH=$IDF_PATH" >> $GITHUB_ENV
echo "${IDF_PATH}/tools" >> $GITHUB_PATH
echo "${IDF_PATH}/components" >> $GITHUB_PATH
mkdir -p build-esp32 && cd build-esp32
cmake -DCMAKE_TOOLCHAIN_FILE="../toolchains/esp32.toolchain.cmake" -DCMAKE_BUILD_TYPE=Release -DNCNN_BUILD_EXAMPLES=OFF ..
make -j 4
make install
29 changes: 29 additions & 0 deletions docs/how-to-build/how-to-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ git submodule update --init
- [Build for QNX](#build-for-qnx)
- [Build for Nintendo 3DS Homebrew Launcher](#build-for-nintendo-3ds-homebrew-launcher)
- [Build for HarmonyOS with cross-compiling](#build-for-harmonyos-with-cross-compiling)
- [Build for ESP32 with cross-compiling](#build-for-esp32-with-cross-compiling)

***

Expand Down Expand Up @@ -866,3 +867,31 @@ ${HM_SDK}/native/build-tools/cmake/bin/cmake -DOHOS_STL=c++_static -DOHOS_ARCH=a
make -j$(nproc)
make install
```

***

### Build for ESP32 with cross-compiling
Download esp-idf sdk
```shell
git clone https://github.com/espressif/esp-idf
cd esp-idf
git submodule update --init --recursive
```
Install esp-idf sdk and configure the environment
```shell
sudo sh install.sh
source export.sh
```
Note: python>=3.8, cmake>=3.24.0

Build ncnn library:
```shell
mkdir build-esp32
cd build-esp32
cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/esp32.toolchain.cmake -DCMAKE_BUILD_TYPE=Release ..
make -j 4
make install
```
Note: Make sure to compile in esp-idf environment.

The compiled ncnn library and headers can be put to the esp32 project to test.
16 changes: 16 additions & 0 deletions toolchains/esp32.toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
set(CMAKE_SYSTEM_NAME freertos)
set(CMAKE_SYSTEM_PROCESSOR xtensa-esp32)

include($ENV{IDF_PATH}/tools/cmake/toolchain-esp32.cmake)

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags")

option(NCNN_BUILD_BENCHMARK "" OFF)
Loading