From 88f0b7e4bc81a54a5d864086514e62788ead77d0 Mon Sep 17 00:00:00 2001 From: JingyuYan Date: Mon, 6 May 2024 17:16:05 +0800 Subject: [PATCH] AdD auto-build ci --- .../workflows/built_release_from_docker.yaml | 68 +++++++++++++++ CMakeLists.txt | 1 + command/build.sh | 82 +++++++++++++++++-- command/build_cross_armv7_armhf.sh | 51 ++++++++++++ command/build_cross_rv1109rv1126_armhf.sh | 36 +++++++- command/build_linux_cuda.sh | 34 +++++++- command/build_linux_ubuntu18.sh | 44 ++++++++++ command/build_linux_ubuntu18_opencv.sh | 15 ---- cpp/inspireface/CMakeLists.txt | 1 + docker-compose.yml | 26 ++++++ docker/Dockerfile.arm-linux-gnueabihf | 37 +++++++++ docker/Dockerfile.ubuntu18 | 39 +++++++++ 12 files changed, 407 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/built_release_from_docker.yaml create mode 100644 command/build_cross_armv7_armhf.sh create mode 100644 command/build_linux_ubuntu18.sh delete mode 100644 command/build_linux_ubuntu18_opencv.sh create mode 100644 docker-compose.yml create mode 100644 docker/Dockerfile.arm-linux-gnueabihf create mode 100644 docker/Dockerfile.ubuntu18 diff --git a/.github/workflows/built_release_from_docker.yaml b/.github/workflows/built_release_from_docker.yaml new file mode 100644 index 00000000..c6a1cdb1 --- /dev/null +++ b/.github/workflows/built_release_from_docker.yaml @@ -0,0 +1,68 @@ +name: Build and Release SDKs + +on: + push: + tags: + - "v*" # 当推送符合 "v*" 模式的标签时触发 + +jobs: + build: + name: Compile and Package SDKs + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + # Step 2: Update Git submodules recursively + - name: Update submodules + run: | + git submodule sync --recursive # Ensure submodule paths are up-to-date + git submodule update --init --recursive # Initialize and update all submodules + + # 使用 Docker Compose 构建项目 + - name: Build SDKs with Docker Compose + run: docker-compose up + + # 压缩每个 SDK 目录 + - name: Zip SDK Files + run: | + zip -r linux_armv7_armhf.zip build/linux_armv7_armhf/ + zip -r linux_rv1109rv1126_armhf.zip build/linux_rv1109rv1126_armhf/ + zip -r linux_ubuntu18.zip build/linux_ubuntu18/ + + # 上传打包文件以供发布任务使用 + - name: Upload SDK Artifacts + uses: actions/upload-artifact@v2 + with: + name: sdk_files + path: | + linux_armv7_armhf.zip + linux_rv1109rv1126_armhf.zip + linux_ubuntu18.zip + + release: + name: Release SDKs to GitHub + needs: build + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + # 下载上一个步骤上传的 SDK 文件 + - name: Download SDK Artifacts + uses: actions/download-artifact@v2 + with: + name: sdk_files + + # 创建 GitHub Release 并上传 SDK 文件 + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + files: | + linux_armv7_armhf.zip + linux_rv1109rv1126_armhf.zip + linux_ubuntu18.zip + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/CMakeLists.txt b/CMakeLists.txt index ea57ac8e..8cc70b4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,7 @@ else() endif () if(ISF_BUILD_LINUX_ARM7) set(PLAT linux-arm7) + message("The OpenCV that builds the gnueabihf version depends on is specialized!") set(OpenCV_DIR ${ISF_THIRD_PARTY_DIR}/inspireface-precompile/opencv/3.4.5/opencv-linux-armhf/share/OpenCV) set(OpenCV_STATIC_INCLUDE_DIR ${PATH_3RDPARTY}/inspireface-precompile/opencv/3.4.5/opencv-linux-armhf/include/) elseif(ISF_BUILD_LINUX_AARCH64) diff --git a/command/build.sh b/command/build.sh index 93e4e851..6e0f8689 100644 --- a/command/build.sh +++ b/command/build.sh @@ -1,14 +1,84 @@ -mkdir -p build/local -# shellcheck disable=SC2164 -cd build/local -# export cross_compile_toolchain=/home/s4129/software/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf +#!/bin/bash + +# Reusable function to handle 'install' directory operations +move_install_files() { + local root_dir="$1" + local install_dir="$root_dir/install" + + # Step 1: Check if the 'install' directory exists + if [ ! -d "$install_dir" ]; then + echo "Error: 'install' directory does not exist in $root_dir" + exit 1 + fi + + # Step 2: Delete all other files/folders except 'install' + find "$root_dir" -mindepth 1 -maxdepth 1 -not -name "install" -exec rm -rf {} + + + # Step 3: Move all files from 'install' to the root directory + mv "$install_dir"/* "$root_dir" 2>/dev/null + + # Step 4: Remove the empty 'install' directory + rmdir "$install_dir" + + echo "Files from 'install' moved to $root_dir, and 'install' directory deleted." +} + +# Detect the operating system +OS_NAME=$(uname) +BUILD_DIR="build" +SCRIPT_DIR=$(pwd) # Project dir + + + +# Determine the appropriate build directory based on the OS +case "$OS_NAME" in + Darwin) + # macOS system + BUILD_DIR="${BUILD_DIR}/macos" + ;; + Linux) + # Linux system, further identify the distribution if necessary + if [ -f /etc/os-release ]; then + . /etc/os-release + case "$ID" in + ubuntu) + BUILD_DIR="${BUILD_DIR}/linux_ubuntu" + ;; + centos) + BUILD_DIR="${BUILD_DIR}/linux_centos" + ;; + *) + # If an unknown Linux distribution, default to generic 'linux' + BUILD_DIR="${BUILD_DIR}/linux" + ;; + esac + else + # If unable to detect Linux distribution, default to 'linux' + BUILD_DIR="${BUILD_DIR}/linux" + fi + ;; + *) + # If OS is not recognized, default to 'generic' + BUILD_DIR="${BUILD_DIR}/generic" + ;; +esac + +# Create the build directory and navigate into it +mkdir -p "$BUILD_DIR" +cd "$BUILD_DIR" || exit 1 + +# Run CMake configuration (adjust the options as needed) cmake -DCMAKE_BUILD_TYPE=Release \ -DISF_BUILD_WITH_SAMPLE=ON \ -DISF_BUILD_WITH_TEST=OFF \ -DISF_ENABLE_BENCHMARK=OFF \ -DISF_ENABLE_USE_LFW_DATA=OFF \ -DISF_ENABLE_TEST_EVALUATION=OFF \ - -DISF_BUILD_SHARED_LIBS=ON ../../ + -DISF_BUILD_SHARED_LIBS=ON "$SCRIPT_DIR" +# Compile and install make -j4 -make install \ No newline at end of file +make install + +# Move 'install' files to the build root directory using an absolute path +move_install_files "$(pwd)" diff --git a/command/build_cross_armv7_armhf.sh b/command/build_cross_armv7_armhf.sh new file mode 100644 index 00000000..0683b9a1 --- /dev/null +++ b/command/build_cross_armv7_armhf.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# Reusable function to handle 'install' directory operations +move_install_files() { + local root_dir="$1" + local install_dir="$root_dir/install" + + # Step 1: Check if the 'install' directory exists + if [ ! -d "$install_dir" ]; then + echo "Error: 'install' directory does not exist in $root_dir" + exit 1 + fi + + # Step 2: Delete all other files/folders except 'install' + find "$root_dir" -mindepth 1 -maxdepth 1 -not -name "install" -exec rm -rf {} + + + # Step 3: Move all files from 'install' to the root directory + mv "$install_dir"/* "$root_dir" 2>/dev/null + + # Step 4: Remove the empty 'install' directory + rmdir "$install_dir" + + echo "Files from 'install' moved to $root_dir, and 'install' directory deleted." +} + +SCRIPT_DIR=$(pwd) # Project dir + +mkdir -p build/linux_armv7_armhf +# shellcheck disable=SC2164 +cd build/linux_armv7_armhf +# export cross_compile_toolchain=/home/jingyuyan/software/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf +cmake -DCMAKE_SYSTEM_NAME=Linux \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_SYSTEM_VERSION=1 \ + -DCMAKE_SYSTEM_PROCESSOR=armv7 \ + -DCMAKE_C_COMPILER=$ARM_CROSS_COMPILE_TOOLCHAIN/bin/arm-linux-gnueabihf-gcc \ + -DCMAKE_CXX_COMPILER=$ARM_CROSS_COMPILE_TOOLCHAIN/bin/arm-linux-gnueabihf-g++ \ + -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -flax-vector-conversions" \ + -DTARGET_PLATFORM=armlinux \ + -DISF_BUILD_LINUX_ARM7=ON \ + -DISF_BUILD_WITH_SAMPLE=OFF \ + -DISF_BUILD_WITH_TEST=OFF \ + -DISF_ENABLE_BENCHMARK=OFF \ + -DISF_ENABLE_USE_LFW_DATA=OFF \ + -DISF_ENABLE_TEST_EVALUATION=OFF \ + -DISF_BUILD_SHARED_LIBS=ON ${SCRIPT_DIR} + +make -j4 +make install + +move_install_files "$(pwd)" diff --git a/command/build_cross_rv1109rv1126_armhf.sh b/command/build_cross_rv1109rv1126_armhf.sh index af645c57..88e4b0ec 100644 --- a/command/build_cross_rv1109rv1126_armhf.sh +++ b/command/build_cross_rv1109rv1126_armhf.sh @@ -1,7 +1,34 @@ -mkdir -p build/rv1109rv1126_armhf +#!/bin/bash + +# Reusable function to handle 'install' directory operations +move_install_files() { + local root_dir="$1" + local install_dir="$root_dir/install" + + # Step 1: Check if the 'install' directory exists + if [ ! -d "$install_dir" ]; then + echo "Error: 'install' directory does not exist in $root_dir" + exit 1 + fi + + # Step 2: Delete all other files/folders except 'install' + find "$root_dir" -mindepth 1 -maxdepth 1 -not -name "install" -exec rm -rf {} + + + # Step 3: Move all files from 'install' to the root directory + mv "$install_dir"/* "$root_dir" 2>/dev/null + + # Step 4: Remove the empty 'install' directory + rmdir "$install_dir" + + echo "Files from 'install' moved to $root_dir, and 'install' directory deleted." +} + +SCRIPT_DIR=$(pwd) # Project dir + +mkdir -p build/linux_rv1109rv1126_armhf # shellcheck disable=SC2164 -cd build/rv1109rv1126_armhf -# export cross_compile_toolchain=/home/s4129/software/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf +cd build/linux_rv1109rv1126_armhf +# export cross_compile_toolchain=/home/jingyuyan/software/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf cmake -DCMAKE_SYSTEM_NAME=Linux \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_SYSTEM_VERSION=1 \ @@ -18,8 +45,9 @@ cmake -DCMAKE_SYSTEM_NAME=Linux \ -DISF_ENABLE_BENCHMARK=OFF \ -DISF_ENABLE_USE_LFW_DATA=OFF \ -DISF_ENABLE_TEST_EVALUATION=OFF \ - -DISF_BUILD_SHARED_LIBS=ON ../.. + -DISF_BUILD_SHARED_LIBS=ON ${SCRIPT_DIR} make -j4 make install +move_install_files "$(pwd)" \ No newline at end of file diff --git a/command/build_linux_cuda.sh b/command/build_linux_cuda.sh index 9dc118ea..3a5a14da 100644 --- a/command/build_linux_cuda.sh +++ b/command/build_linux_cuda.sh @@ -1,7 +1,35 @@ +#!/bin/bash + +# Reusable function to handle 'install' directory operations +move_install_files() { + local root_dir="$1" + local install_dir="$root_dir/install" + + # Step 1: Check if the 'install' directory exists + if [ ! -d "$install_dir" ]; then + echo "Error: 'install' directory does not exist in $root_dir" + exit 1 + fi + + # Step 2: Delete all other files/folders except 'install' + find "$root_dir" -mindepth 1 -maxdepth 1 -not -name "install" -exec rm -rf {} + + + # Step 3: Move all files from 'install' to the root directory + mv "$install_dir"/* "$root_dir" 2>/dev/null + + # Step 4: Remove the empty 'install' directory + rmdir "$install_dir" + + echo "Files from 'install' moved to $root_dir, and 'install' directory deleted." +} + + +SCRIPT_DIR=$(pwd) # Project dir + mkdir -p build/linux_cuda # shellcheck disable=SC2164 cd build/linux_cuda -# export cross_compile_toolchain=/home/s4129/software/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf + cmake -DCMAKE_SYSTEM_NAME=Linux \ -DCMAKE_BUILD_TYPE=Release \ -DISF_BUILD_WITH_SAMPLE=OFF \ @@ -11,6 +39,8 @@ cmake -DCMAKE_SYSTEM_NAME=Linux \ -DISF_ENABLE_TEST_EVALUATION=OFF \ -DISF_GLOBAL_INFERENCE_BACKEND_USE_MNN_CUDA=ON \ -DISF_LINUX_MNN_CUDA=/home/tunm/software/MNN-2.7.0/build_cuda/install \ - -DISF_BUILD_SHARED_LIBS=ON ../.. + -DISF_BUILD_SHARED_LIBS=ON ${SCRIPT_DIR} make -j4 + +move_install_files "$(pwd)" diff --git a/command/build_linux_ubuntu18.sh b/command/build_linux_ubuntu18.sh new file mode 100644 index 00000000..9befc1c7 --- /dev/null +++ b/command/build_linux_ubuntu18.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Reusable function to handle 'install' directory operations +move_install_files() { + local root_dir="$1" + local install_dir="$root_dir/install" + + # Step 1: Check if the 'install' directory exists + if [ ! -d "$install_dir" ]; then + echo "Error: 'install' directory does not exist in $root_dir" + exit 1 + fi + + # Step 2: Delete all other files/folders except 'install' + find "$root_dir" -mindepth 1 -maxdepth 1 -not -name "install" -exec rm -rf {} + + + # Step 3: Move all files from 'install' to the root directory + mv "$install_dir"/* "$root_dir" 2>/dev/null + + # Step 4: Remove the empty 'install' directory + rmdir "$install_dir" + + echo "Files from 'install' moved to $root_dir, and 'install' directory deleted." +} + +SCRIPT_DIR=$(pwd) # Project dir + +mkdir -p build/linux_ubuntu18/ +# shellcheck disable=SC2164 +cd build/linux_ubuntu18/ + +cmake -DCMAKE_BUILD_TYPE=Release \ + -DISF_BUILD_WITH_SAMPLE=ON \ + -DISF_BUILD_WITH_TEST=OFF \ + -DISF_ENABLE_BENCHMARK=OFF \ + -DISF_ENABLE_USE_LFW_DATA=OFF \ + -DISF_ENABLE_TEST_EVALUATION=OFF \ + -DOpenCV_DIR=3rdparty/inspireface-precompile/opencv/4.5.1/opencv-ubuntu18-x86/lib/cmake/opencv4 \ + -DISF_BUILD_SHARED_LIBS=ON ${SCRIPT_DIR} + +make -j4 +make install + +move_install_files "$(pwd)" \ No newline at end of file diff --git a/command/build_linux_ubuntu18_opencv.sh b/command/build_linux_ubuntu18_opencv.sh deleted file mode 100644 index f44270b0..00000000 --- a/command/build_linux_ubuntu18_opencv.sh +++ /dev/null @@ -1,15 +0,0 @@ -mkdir -p build/linux_x86_ubuntu18_opencv/ -# shellcheck disable=SC2164 -cd build/linux_x86_ubuntu18_opencv -# export cross_compile_toolchain=/home/s4129/software/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf -cmake -DCMAKE_BUILD_TYPE=Release \ - -DISF_BUILD_WITH_SAMPLE=ON \ - -DISF_BUILD_WITH_TEST=OFF \ - -DISF_ENABLE_BENCHMARK=OFF \ - -DISF_ENABLE_USE_LFW_DATA=OFF \ - -DISF_ENABLE_TEST_EVALUATION=OFF \ - -DOpenCV_DIR=3rdparty/inspireface-precompile/opencv/4.5.1/opencv-ubuntu18-x86/lib/cmake/opencv4 \ - -DISF_BUILD_SHARED_LIBS=ON ../../ - -make -j4 -make install \ No newline at end of file diff --git a/cpp/inspireface/CMakeLists.txt b/cpp/inspireface/CMakeLists.txt index 7d3d74ff..ac861341 100644 --- a/cpp/inspireface/CMakeLists.txt +++ b/cpp/inspireface/CMakeLists.txt @@ -71,6 +71,7 @@ if (ISF_ENABLE_RKNN) set(NEED_INCLUDE ${NEED_INCLUDE} ${ISF_RKNN_API_INCLUDE_DIRS}) endif () if (ISF_BUILD_LINUX_ARM7) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon") set(NEED_INCLUDE ${NEED_INCLUDE} ${OpenCV_STATIC_INCLUDE_DIR}) endif () diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..1a583e8e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: '3' +services: + build-ubuntu18: + build: + context: . + dockerfile: docker/Dockerfile.ubuntu18 # Use the Ubuntu18.04 + working_dir: /workspace + volumes: + - .:/workspace # Mount the project root directory to the container + command: bash command/build_linux_ubuntu18.sh + build-cross-rv1109rv1126-armhf: + build: + context: . + dockerfile: docker/Dockerfile.arm-linux-gnueabihf # Use the arm-linux-gnueabihf tool chain + working_dir: /workspace + volumes: + - .:/workspace # Mount the project root directory to the container + command: bash command/build_cross_rv1109rv1126_armhf.sh + build-cross-armv7-armhf: + build: + context: . + dockerfile: docker/Dockerfile.arm-linux-gnueabihf # Use the arm-linux-gnueabihf tool chain + working_dir: /workspace + volumes: + - .:/workspace # Mount the project root directory to the container + command: bash command/build_cross_armv7_armhf.sh diff --git a/docker/Dockerfile.arm-linux-gnueabihf b/docker/Dockerfile.arm-linux-gnueabihf new file mode 100644 index 00000000..3b2a3637 --- /dev/null +++ b/docker/Dockerfile.arm-linux-gnueabihf @@ -0,0 +1,37 @@ +# Use Ubuntu 18.04 as the base image +FROM ubuntu:18.04 + +# Update the package list and install basic development tools +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + build-essential \ + software-properties-common \ + wget \ + curl \ + git \ + vim + +# Install CMake +RUN apt-get install -y --no-install-recommends cmake + +# Set the URL and installation path for the Linaro toolchain +ARG LINARO_URL="https://releases.linaro.org/components/toolchain/binaries/6.3-2017.05/arm-linux-gnueabihf/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf.tar.xz" +ARG TOOLCHAIN_PATH="/opt/linaro-toolchain" + +# Create the installation path, download, and extract the Linaro toolchain +RUN mkdir -p ${TOOLCHAIN_PATH} && \ + wget -qO- ${LINARO_URL} | tar -xJ -C ${TOOLCHAIN_PATH} --strip-components=1 + +# Set environment variables to point to the toolchain directory +ENV ARM_CROSS_COMPILE_TOOLCHAIN=${TOOLCHAIN_PATH} +ENV PATH="${TOOLCHAIN_PATH}/bin:${PATH}" + +# Clean temporary files to reduce image size +RUN apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Set the working directory +WORKDIR /workspace + +# Default to running Bash +CMD ["/bin/bash"] diff --git a/docker/Dockerfile.ubuntu18 b/docker/Dockerfile.ubuntu18 new file mode 100644 index 00000000..204eaafd --- /dev/null +++ b/docker/Dockerfile.ubuntu18 @@ -0,0 +1,39 @@ +# Use Ubuntu 18.04 as the base image +# FROM ubuntu:18.04 +FROM skybro/ubuntu-cn:18 + +ARG https_proxy +ARG http_proxy +ARG all_proxy + +RUN apt-get update + +# Install OpenCV dependency +RUN apt-get install -y --no-install-recommends libgtk-3-dev +RUN apt-get install -y --no-install-recommends libavcodec-dev +RUN apt-get install -y --no-install-recommends libavformat-dev +RUN apt-get install -y --no-install-recommends libswscale-dev +RUN apt-get install -y --no-install-recommends libjpeg-dev +RUN apt-get install -y --no-install-recommends libpng-dev + +# Update the package list and install basic development tools +RUN apt-get install -y --no-install-recommends build-essential +RUN apt-get install -y --no-install-recommends software-properties-common +RUN apt-get install -y --no-install-recommends wget +RUN apt-get install -y --no-install-recommends curl +RUN apt-get install -y --no-install-recommends git +RUN apt-get install -y --no-install-recommends vim + +# Install CMake +RUN apt-get install -y --no-install-recommends cmake + + +# Clean temporary files to reduce image size +RUN apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Set the working directory +WORKDIR /workspace + +# Default to running Bash +CMD ["/bin/bash"]