From 090a044a3b45e70f4fbda6ae19d3cfd1ad47b3d2 Mon Sep 17 00:00:00 2001 From: johnny9 <985648+johnny9@users.noreply.github.com> Date: Sat, 23 Sep 2023 19:17:13 -0400 Subject: [PATCH] main: Build the web ui dist as an ExternalProject This integrates the generation of the web distribution into the cmake build system. The ExternalProject will call npm i and npm run build. Resolves #34 --- .github/workflows/build.yml | 9 ++++---- main/CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d4a4d1036..57acbcf4e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,23 +5,24 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: 'recursive' - name: Setup Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: - node-version: '16' + node-version: '20' - name: Build web dist working-directory: ./main/http_server/axe-os run: | - npm ci + npm i npm run build - name: esp-idf build uses: espressif/esp-idf-ci-action@v1 with: esp_idf_version: v5.1 target: esp32s2 + command: GITHUB_ACTIONS="true" idf.py build path: '.' - name: upload esp-miner.bin uses: actions/upload-artifact@v3 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 3d7644711..200b8c691 100755 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -26,10 +26,46 @@ INCLUDE_DIRS "../components/connect/include" ) +set(CARGO_PROJECT_DIR "${CMAKE_CURRENT_LIST_DIR}") +set(CARGO_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}") +set(CARGO_TARGET_DIR "${CARGO_BUILD_DIR}/target") + +set(RUST_INCLUDE_DIR "${CARGO_TARGET_DIR}") +set(RUST_STATIC_LIBRARY "${CARGO_TARGET_DIR}/${RUST_TARGET}/${CARGO_BUILD_TYPE}/librust_excavator.a") + set(WEB_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/http_server/axe-os") -if(EXISTS ${WEB_SRC_DIR}/dist/axe-os) + + +if("$ENV{GITHUB_ACTIONS}" STREQUAL "true") + message(STATUS "Running on GitHub Actions. Web ui will be prebuilt.") + spiffs_create_partition_image(www ${WEB_SRC_DIR}/dist/axe-os FLASH_IN_PROJECT) else() - message(FATAL_ERROR "${WEB_SRC_DIR}/dist doesn't exit. Please run 'npm i && npm run build' in ${WEB_SRC_DIR}") + find_program(NPM_EXECUTABLE npm) + if(NOT NPM_EXECUTABLE AND NOT EXISTS ${WEB_SRC_DIR}/dist) + message(FATAL_ERROR "npm is not found! Please install it to proceed.") + endif() + + ExternalProject_Add( + web_ui_dist + PREFIX ${CMAKE_BINARY_DIR}/web_ui_dist + SOURCE_DIR ${WEB_SRC_DIR} + DOWNLOAD_COMMAND "" + CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env + PATH=$ENV{PATH} + ${NPM_EXECUTABLE} i + USES_TERMINAL_BUILD true + BUILD_COMMAND ${CMAKE_COMMAND} -E env + PATH=$ENV{PATH} + ${NPM_EXECUTABLE} run build + INSTALL_COMMAND "" + BUILD_ALWAYS OFF + BUILD_IN_SOURCE TRUE + BUILD_BYPRODUCTS + "${WEB_SRC_DIR}/dist/axe-os/index.html" + ) + + add_dependencies(${COMPONENT_LIB} web_ui_dist) -endif() \ No newline at end of file + spiffs_create_partition_image(www ${WEB_SRC_DIR}/dist/axe-os FLASH_IN_PROJECT DEPENDS web_ui_dist) +endif()