diff --git a/.github/workflows/test_windows.yml b/.github/workflows/test_windows.yml index caa6d108..62d48390 100644 --- a/.github/workflows/test_windows.yml +++ b/.github/workflows/test_windows.yml @@ -62,4 +62,4 @@ jobs: shell: pwsh run: | # Set-PSDebug -Trace 1 - .\scripts\build.ps1 -BuildMode 'Release' -IntegrateDeploy + .\scripts\build.ps1 -BuildMode 'Release' -Automate diff --git a/scripts/build.sh b/scripts/build.sh index 01b40043..7a834335 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -46,12 +46,19 @@ function version_less_than_equal_to { ### Variables ### -# Static variables +# Script directory. +SCRIPT_DIR="$(realpath ${BASH_SOURCE[0]})" + +# Static variables. DEBUG='false' GCC='false' + +CMAKE_VERSION='3.10.2' +EIGEN_VERSION='3.4.0' RPCLIB_VERSION='2.3.0' +UNREAL_ASSET_VERSION='1.2.0' -# Dynamic variables +# Dynamic variables. SYSTEM_INFO="$(system_info)" SYSTEM_PLATFORM="$(system_architecture)" SYSTEM_CPU_MAX="$(( $(nproc) - 2 ))" @@ -61,11 +68,9 @@ SYSTEM_OS_VERSION="$(system_os_version)" ### Main ### -# change into directory containing this script. -SCRIPT_DIR="$(realpath ${BASH_SOURCE[0]})" -pushd "${SCRIPT_DIR}" > /dev/null # push script directory onto the stack +#pushd "${SCRIPT_DIR}" >/dev/null # push script directory onto the stack -# Parse command line arguments +# Parse command line arguments. while [ $# -gt 0 ]; do key="$1" case $key in @@ -80,14 +85,14 @@ while [ $# -gt 0 ]; do esac done -# check for existing rpclib installation +# Check for existing rpclib installation. if [ ! -d "./external/rpclib/rpclib-${RPCLIB_VERSION}" ]; then echo "ERROR: new version of AutonomySim requires newer rpclib." echo "please run setup.sh first and then run build.sh again." exit 1 fi -# check for local cmake build created by setup.sh +# Check for local cmake build created by setup.sh. if [ -d "./cmake_build" ]; then if [ "$(uname)" = "Darwin" ]; then CMAKE="$(greadlink -f cmake_build/bin/cmake)" @@ -98,14 +103,14 @@ else CMAKE="$(which cmake)" fi -# variable for build output +# Variable for build output. if [ "${DEBUG}" = 'true' ]; then build_dir='build_debug' else build_dir='build_release' fi -# configure compiler +# Configure compiler. if [ "$(uname)" = 'Darwin' ]; then export CC="$(brew --prefix)/opt/llvm/bin/clang" export CXX="$(brew --prefix)/opt/llvm/bin/clang++" @@ -122,7 +127,7 @@ else exit 1 fi -# install Eigen3 C++ library +# Install Eigen C++ library. if [ ! -d "./AutonomyLib/deps/eigen3/Eigen" ]; then echo 'ERROR: Eigen is not installed. Please run `setup.sh` first.' exit 1 @@ -130,16 +135,16 @@ fi echo "Moving build into ${build_dir} directory. To clean, delete the directory." -# Ensure CMake files will be built in our build directory +# Ensure CMake files will be built in our build directory. [ -f "./cmake/CMakeCache.txt" ] && rm "./cmake/CMakeCache.txt" [ -d "./cmake/CMakeFiles" ] && rm -rf "./cmake/CMakeFiles" [ ! -d "$build_dir" ] && mkdir -p "$build_dir" -# Fix for Unreal on Apple/ARM silicon using x86_64 (Rosetta) +# Fix for Unreal on Apple/ARM silicon using x86_64 (Rosetta). CMAKE_VARS='' [ "$(uname)" = 'Darwin' ] && CMAKE_VARS='-DCMAKE_APPLE_SILICON_PROCESSOR=x86_64' -pushd "$build_dir" > /dev/null # push directory onto stack +pushd "$build_dir" >/dev/null # push directory onto stack if [ "${DEBUG}" = 'true' ]; then folder_name='Debug' @@ -149,18 +154,19 @@ else "$CMAKE" ../cmake -DCMAKE_BUILD_TYPE=Release $CMAKE_VARS || (popd && rm -r "$build_dir" && exit 1) fi -#popd > /dev/null # pop directory from stack -#pushd "$build_dir" > /dev/null # push directory onto stack +#popd >/dev/null # pop directory from stack +#pushd "$build_dir" >/dev/null # push directory onto stack # final linking of the binaries can fail due to a missing libc++abi library # (happens on Fedora, see https://bugzilla.redhat.com/show_bug.cgi?id=1332306). # So we only build the libraries here for now make -j"${SYSTEM_CPU_MAX}" -popd > /dev/null # pop directory from stack +popd > /dev/null # pop directory from stack mkdir -p "AutonomyLib/lib/x64/${folder_name}" mkdir -p 'AutonomyLib/deps/rpclib/lib' mkdir -p 'AutonomyLib/deps/MavLinkCom/lib' + cp "${build_dir}/output/lib/libAutonomyLib.a AutonomyLib/lib" cp "${build_dir}/output/lib/libMavLinkCom.a AutonomyLib/deps/MavLinkCom/lib" cp "${build_dir}/output/lib/librpc.a AutonomyLib/deps/rpclib/lib/librpc.a" @@ -170,6 +176,7 @@ rsync -a --delete "${build_dir}/output/lib/ AutonomyLib/lib/x64/${folder_name}" rsync -a --delete "external/rpclib/rpclib-${RPCLIB_VERSION}/include AutonomyLib/deps/rpclib" rsync -a --delete 'MavLinkCom/include AutonomyLib/deps/MavLinkCom' rsync -a --delete 'AutonomyLib Unreal/Plugins/AutonomySim/Source' + rm -rf 'Unreal/Plugins/AutonomySim/Source/AutonomyLib/src' # Update all environment projects @@ -182,16 +189,14 @@ done set +x -echo '' echo '-----------------------------------------------------------------------------------------' echo ' AutonomySim plugin built successfully.' echo '-----------------------------------------------------------------------------------------' echo ' All environments under Unreal/Environments have been updated.' -echo '' echo ' For further info see:' -echo ' https://github.com/nervosys/AutonomySim/blob/master/docs/build_linux.md' +echo ' https://github.com/nervosys/AutonomySim/blob/master/docs/build_linux.md' echo '-----------------------------------------------------------------------------------------' -popd > /dev/null # pop directory from stack +popd >/dev/null # pop directory from stack exit 0 diff --git a/scripts/setup.sh b/scripts/setup.sh index 1b9f6ac7..8f01d83f 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -21,8 +21,8 @@ # - Update: ensure script runs on recent Linux distributions, MacOS, Windows. #---------------------------------------------------------------------------------------- -set -x # print shell commands before executing (for debugging) -set -e # exit on error return code +set -x # print shell commands before executing (for debugging) +set -e # exit on error return code ### ### Functions @@ -38,22 +38,27 @@ function version_less_than_equal_to { } ### -### Parameters +### Variables ### -# change into directory containing this script. +# Script directory. SCRIPT_DIR="$(realpath ${BASH_SOURCE[0]})" -pushd "${SCRIPT_DIR}" > /dev/null # push script directory onto the stack -# download high-polycount SUV model -HIGH_POLYCOUNT_SUV='false' - -# Ensure CMake supports CMAKE_APPLE_SILICON_PROCESSOR for MacOS +# Ensure CMake supports CMAKE_APPLE_SILICON_PROCESSOR for MacOS. if [ "$(uname)" = 'Darwin' ]; then - MIN_CMAKE_VERSION='3.19.2' + CMAKE_VERSION_MIN='3.19.2' else - MIN_CMAKE_VERSION='3.10.0' + CMAKE_VERSION_MIN='3.10.0' fi +CMAKE_VERSION_MIN_MAJ_MIN='3.10' + +CMAKE_VERSION='3.10.2' +EIGEN_VERSION='3.4.0' +RPCLIB_VERSION='2.3.0' +UNREAL_ASSET_VERSION='1.2.0' + +# download high-polycount SUV model. +HIGH_POLYCOUNT_SUV='false' DEBUG="${DEBUG:-false}" @@ -61,6 +66,8 @@ DEBUG="${DEBUG:-false}" ### Main ### +# pushd "${SCRIPT_DIR}" >/dev/null # push script directory onto the stack + # Parse command-line interface (CLI) arguments. while [ $# -gt 0 ]; do key="$1" @@ -90,7 +97,7 @@ else vulkan-utils VERSION=$(lsb_release -rs | cut -d. -f1) if [ "$VERSION" -lt '17' ]; then - wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + wget -O - 'http://apt.llvm.org/llvm-snapshot.gpg.key' | sudo apt-key add - sudo apt-get update fi sudo apt-get install -y clang-8 clang++-8 libc++-8-dev libc++abi-8-dev @@ -104,8 +111,8 @@ else fi # Give user permissions to access USB port, not needed if not using PX4 HIL. -# TODO: figure out how to do below in travis -# Install additional tools, CMake if required +# TODO: figure out how to do below in travis. +# Install additional tools, CMake if required. if [ "$(uname)" = 'Darwin' ]; then if [ -n "${whoami}" ]; then # travis sudo dseditgroup -o edit -a "$(whoami)" -t user dialout @@ -113,8 +120,8 @@ if [ "$(uname)" = 'Darwin' ]; then brew update brew_install wget brew_install coreutils - # Conditionally install lower CMake version - if version_less_than_equal_to "$cmake_ver" "$MIN_CMAKE_VERSION"; then + # Conditionally install lower CMake version. + if version_less_than_equal_to "$cmake_ver" "$CMAKE_VERSION_MIN"; then brew install cmake else echo "Compatible version of CMake already installed: $cmake_ver" @@ -125,26 +132,23 @@ else sudo usermod -a -G dialout "$USER" fi sudo apt-get install -y build-essential unzip - if version_less_than_equal_to "$cmake_ver" "$MIN_CMAKE_VERSION"; then + if version_less_than_equal_to "$cmake_ver" "$CMAKE_VERSION_MIN"; then if [ "$(lsb_release -rs)" = "18.04" ]; then - sudo apt-get -y install \ - apt-transport-https \ - ca-certificates \ - gnupg - wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null + sudo apt-get -y install apt-transport-https ca-certificates gnupg + wget -O - 'https://apt.kitware.com/keys/kitware-archive-latest.asc' 2>/dev/null | + gpg --dearmor - | + sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main' - sudo apt-get -y install --no-install-recommends \ - make \ - cmake + sudo apt-get -y install --no-install-recommends make cmake else - # If CMake binary not found, build it from source - if [ ! -d "cmake_build/bin" ]; then - echo "Downloading CMake..." - wget https://cmake.org/files/v3.10/cmake-3.10.2.tar.gz -O cmake.tar.gz - tar -xzf cmake.tar.gz - rm cmake.tar.gz + # If CMake binary not found, build it from source. + if [ ! -d './cmake_build/bin' ]; then + echo 'Downloading CMake...' + wget "https://cmake.org/files/v${CMAKE_VERSION_MIN_MAJ_MIN}/cmake-${CMAKE_VERSION}.tar.gz" -O cmake.tar.gz + tar -xzf ./cmake.tar.gz + rm ./cmake.tar.gz rm -rf ./cmake_build - mv ./cmake-3.10.2 ./cmake_build + mv "./cmake-${CMAKE_VERSION}" ./cmake_build pushd cmake_build # push directory onto stack ./bootstrap make @@ -157,65 +161,61 @@ else fi # Download and unpack RPCLib. -if [ ! -d "external/rpclib/rpclib-2.3.0" ]; then +if [ ! -d "./external/rpclib/rpclib-${RPCLIB_VERSION}" ]; then # remove previous versions and create empty directory - rm -rf "external/rpclib" - mkdir -p "external/rpclib" - echo '' + rm -rf "./external/rpclib" + mkdir -p "./external/rpclib" echo '-----------------------------------------------------------------------------------------' echo ' Downloading RPCLib...' echo '-----------------------------------------------------------------------------------------' - wget https://github.com/rpclib/rpclib/archive/v2.3.0.zip - unzip -q v2.3.0.zip -d external/rpclib - rm v2.3.0.zip + wget "https://github.com/rpclib/rpclib/archive/v${RPCLIB_VERSION}.zip" + unzip -q "v${RPCLIB_VERSION}.zip" -d ./external/rpclib + rm "v${RPCLIB_VERSION}.zip" fi # Download and unpack high-polycount SUV asset for Unreal Engine. if [ "${HIGH_POLYCOUNT_SUV}" = 'true' ]; then - if [ ! -d "Unreal/Plugins/AutonomySim/Content/VehicleAdv" ]; then - mkdir -p "Unreal/Plugins/AutonomySim/Content/VehicleAdv" + if [ ! -d './Unreal/Plugins/AutonomySim/Content/VehicleAdv' ]; then + mkdir -p './Unreal/Plugins/AutonomySim/Content/VehicleAdv' fi - if [ ! -d "Unreal/Plugins/AutonomySim/Content/VehicleAdv/SUV/v1.2.0" ]; then - echo '' + if [ ! -d "./Unreal/Plugins/AutonomySim/Content/VehicleAdv/SUV/v${UNREAL_ASSET_VERSION}" ]; then echo '-----------------------------------------------------------------------------------------' - echo ' Downloading high-polycount SUV asset...' - echo ' To install with this asset, re-run with `setup.sh --high-polycount-suv`' + echo ' Downloading Unreal high-polycount SUV asset...' echo '-----------------------------------------------------------------------------------------' - if [ -d "suv_download_tmp" ]; then - rm -rf "suv_download_tmp" + if [ -d ./suv_download_tmp ]; then + rm -rf ./suv_download_tmp fi - mkdir -p "suv_download_tmp" + mkdir -p ./suv_download_tmp cd suv_download_tmp - wget https://github.com/nervosys/AutonomySim/releases/download/v2.0.0-beta.0/car_assets.zip - if [ -d "../Unreal/Plugins/AutonomySim/Content/VehicleAdv/SUV" ]; then - rm -rf "../Unreal/Plugins/AutonomySim/Content/VehicleAdv/SUV" + wget 'https://github.com/microsoft/AirSim/releases/download/v2.0.0-beta.0/car_assets.zip' + if [ -d '../Unreal/Plugins/AutonomySim/Content/VehicleAdv/SUV' ]; then + rm -rf ../Unreal/Plugins/AutonomySim/Content/VehicleAdv/SUV fi - unzip -q car_assets.zip -d ../Unreal/Plugins/ASim/Content/VehicleAdv + unzip -q ./car_assets.zip -d ../Unreal/Plugins/ASim/Content/VehicleAdv cd .. - rm -rf "suv_download_tmp" + rm -rf ./suv_download_tmp fi else - echo "High-poly count SUV asset download skipped. The default Unreal Engine vehicle will be used." + echo "Skipped: Download of Unreal high-polycount SUV asset. The default Unreal Engine vehicle will be used." fi # Download and unpack Eigen3 C++ library. -if [ ! -d "AutonomyLib/deps/eigen3" ]; then +if [ ! -d './AutonomyLib/deps/eigen3' ]; then echo 'Installing Eigen3 C++ library. Downloading Eigen...' - wget -O eigen3.zip https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.zip - unzip -q eigen3.zip -d temp_eigen - mkdir -p AutonomyLib/deps/eigen3 - mv temp_eigen/eigen*/Eigen AutonomyLib/deps/eigen3 + wget -O eigen3.zip "https://gitlab.com/libeigen/eigen/-/archive/${EIGEN_VERSION}/eigen-${EIGEN_VERSION}.zip" + unzip -q eigen3.zip -d ./temp_eigen + mkdir -p ./AutonomyLib/deps/eigen3 + mv ./temp_eigen/eigen*/Eigen ./AutonomyLib/deps/eigen3 rm -rf temp_eigen rm eigen3.zip else - echo "Eigen3 is already installed." + echo "Skipped: Eigen is already installed." fi -popd > /dev/null # pop script directory off of the stack +# popd >/dev/null # pop script directory off of the stack -set +x # disable printing shell commands before executing +set +x # disable printing shell commands before executing -echo '' echo '-----------------------------------------------------------------------------------------' -echo ' AutonomySim plugin setup successfully.' +echo ' Success: AutonomySim setup complete.' echo '-----------------------------------------------------------------------------------------'