From ae3946e650a7048476019e60199f575d2882095e Mon Sep 17 00:00:00 2001 From: EricX-Zhao Date: Sat, 25 Apr 2026 12:16:54 +0000 Subject: [PATCH] Add build script and devcontainer configurations for VIO development --- build.sh | 114 +++++++++++++++++++++++++++++ devcontainer/common.yaml | 33 +++++++++ devcontainer/vio/devcontainer.json | 34 +++++++++ devcontainer/vio/vio.yaml | 8 ++ 4 files changed, 189 insertions(+) create mode 100755 build.sh create mode 100644 devcontainer/common.yaml create mode 100644 devcontainer/vio/devcontainer.json create mode 100644 devcontainer/vio/vio.yaml diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..5c5f8fb --- /dev/null +++ b/build.sh @@ -0,0 +1,114 @@ +#!/bin/bash + +set -x +# ./build.sh -t DESKTOP -p "vins_estimator" -b RelWithDebInfo +# ./build.sh -t RK3588 -p "depthai_examples" -b RelWithDebInfo +# ./build.sh -t DESKTOP -p "device_manager" -b RelWithDebInfo +# ./build.sh -t RK3588 -p "depthai_examples vins_estimator" -b Release +# ./build.sh -t RK3588 -p "svo_ros" -b Release +# ./build.sh -t DESKTOP -p "ov_core ov_init ov_msckf" -b RelWithDebInfo -l 1 + +# export WORKSPACE="$(dirname "$(realpath "$BASH_SOURCE")")" +# export WORKSPACE="$(realpath "$BASH_SOURCE")" +export WORKSPACE="$(dirname "$0")" + +TARGET_PLATFORM="" +BUILD_TYPE=Release +PACKAGE_UP_TO="" +TOOLCHAIN_FILE="" +INSTALL_METHOD="--merge-install" +CMAKE_FORCE_CONFIG="" + +CMAKE_ARGS='-DBUILD_TESTING=OFF + -DDEPTHAI_ENABLE_CURL=OFF + -DBUILD_SHARED_LIBS=ON + -DCMAKE_POSITION_INDEPENDENT_CODE=ON' + +# if number of arguments is less than 2, add -h to list of args +if [ $# -lt 2 ]; then + set -- "$@" -h +fi + +usage() { + echo "Usage: build.bash [-h] [-b ] -t -p [-c] " + echo "Options:" + echo " -h : show this help text" + echo " -b : build type to use (default is RelWithDebInfo for platform=PC and Release for others)" + echo " -t : platform to build for (DESKTOP/RK3588)" + echo " -p : Build select package" + echo " -c : Do a clean build" + echo " -f : Force cmake configure" + exit 0 +} + +# Parse the build options. +while getopts ":hb:t:p:m:f:d:l:c" opt; do + case $opt in + h) usage;; + b) BUILD_TYPE="$OPTARG";; + t) TARGET_PLATFORM="$OPTARG";; + p) PACKAGE_UP_TO="--packages-up-to $OPTARG";; + d) PRODUCT="$OPTARG";; + c) CLEAN_BUILD="true";; + f) CMAKE_FORCE_CONFIG="--cmake-force-configure";; + l) INSTALL_METHOD='--symlink-install';; + ?) usage;; + esac +done + +if [[ "${TARGET_PLATFORM}" = "" ]]; then + echo "Please specify the platform to build for" + exit 1 +fi + +CMAKE_ARGS+=" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON " + +if [[ "${BUILD_TYPE}" = "" ]];then + if [[ "${TARGET_PLATFORM}" = "PC" ]]; then + BUILD_TYPE=RelWithDebInfo + else + BUILD_TYPE=Release + fi +fi +CMAKE_ARGS+=" -DCMAKE_BUILD_TYPE=${BUILD_TYPE}" + +if [[ ${CLEAN_BUILD} = "true" ]]; then + rm -rf ${WORKSPACE}/output/${TARGET_PLATFORM} +fi + +if [[ "${TARGET_PLATFORM}" = "RK3588" ]]; then + # in rk3588_dev container + TOOLCHAIN_FILE=/opt/cmake/rk3588.toolchain.cmake + CMAKE_ARGS+=" -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FILE}" + export ARM_ARCHITECTURE=arm64 +fi + +export TARGET=${TARGET_PLATFORM} + +INSTALL_DIR=${WORKSPACE}/output/${TARGET_PLATFORM}/install +BUILD_DIR=${WORKSPACE}/output/${TARGET_PLATFORM}/build +LOG_DIR=${WORKSPACE}/output/${TARGET_PLATFORM}/log + +# CMAKE_ARGS+=" -DCMAKE_FIND_USE_CMAKE_SYSTEM_PATH=OFF" +CMAKE_ARGS+=" -DCMAKE_EXE_LINKER_FLAGS="-Wl,-rpath-link,/workspace/output/RK3588/install/lib"" + + +echo "TARGET: ${TARGET_PLATFORM}" +echo "TOOLCHAIN_FILE: ${TOOLCHAIN_FILE}" +echo "PACKAGE_UP_TO: ${PACKAGE_UP_TO}" + +MAKEFLAGS="-j8" colcon --log-base ${LOG_DIR} build \ + --build-base ${BUILD_DIR} \ + --install-base ${INSTALL_DIR} \ + --parallel-workers 8 \ + ${INSTALL_METHOD} \ + ${PACKAGE_UP_TO} \ + ${CMAKE_FORCE_CONFIG} \ + --cmake-args \ + --no-warn-unused-cli \ + ${CMAKE_ARGS} + +if [ $? -eq 0 ]; then + mkdir -p "${INSTALL_DIR}" + echo "Build: $(date "+%Y-%m-%d %H:%M:%S")" > "${INSTALL_DIR}/version" +fi diff --git a/devcontainer/common.yaml b/devcontainer/common.yaml new file mode 100644 index 0000000..606707d --- /dev/null +++ b/devcontainer/common.yaml @@ -0,0 +1,33 @@ +services: + pc-dev-base: + # image: sim_dev:gz_harmonic + # container_name: ${PROJECT}-pc-dev + runtime: nvidia # 启用 NVIDIA GPU 支持 + stdin_open: true # 保持标准输入打开 + tty: true # 分配一个伪终端 + privileged: true # 特权模式,允许访问所有 /dev 设备 + extra_hosts: + - "host.docker.internal:host-gateway" + environment: + - DISPLAY=${DISPLAY} + - NVIDIA_DRIVER_CAPABILITIES=all + volumes: + - /dev/dri:/dev/dri + # - ${WORKSPACE}:/workspace + # - ${DATASET}:/dataset + - /tmp/.X11-unix:/tmp/.X11-unix + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: all + capabilities: [gpu] + + rk3588-dev-base: + image: rk3588_dev:jazzy + # container_name: ${PROJECT}-rk3588-dev + stdin_open: true # 保持标准输入打开 + tty: true # 分配一个伪终端 + # volumes: + # - ${WORKSPACE}:/workspace diff --git a/devcontainer/vio/devcontainer.json b/devcontainer/vio/devcontainer.json new file mode 100644 index 0000000..b64a985 --- /dev/null +++ b/devcontainer/vio/devcontainer.json @@ -0,0 +1,34 @@ +{ + "name": "VIO Dev Container", + "dockerComposeFile": [ + "vio.yaml" + ], + "service": "vio-dev", + "runServices": [ + "vio-dev" + ], + "workspaceFolder": "/workspace", + "mounts": [ + "source=${localWorkspaceFolder},target=/workspace,type=bind", + "source=/mnt/d/dataset,target=/dataset,type=bind" + ], + "shutdownAction": "none", + + "containerEnv": { + "http_proxy": "http://host.docker.internal:7897", + "https_proxy": "http://host.docker.internal:7897", + "no_proxy": "localhost,127.0.0.1" + }, + + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python", + "llvm-vs-code-extensions.vscode-clangd", + "twxs.cmake" + ] + } + }, + + "remoteUser": "root" +} diff --git a/devcontainer/vio/vio.yaml b/devcontainer/vio/vio.yaml new file mode 100644 index 0000000..daa3ea4 --- /dev/null +++ b/devcontainer/vio/vio.yaml @@ -0,0 +1,8 @@ +name: vio-dev +services: + vio-dev: + extends: + file: ../common.yaml + service: pc-dev-base + image: sim_dev:gz_harmonic + container_name: vio-dev-pc