diff --git a/build.sh b/build.sh index 8b45d64ba1..047267a6a0 100755 --- a/build.sh +++ b/build.sh @@ -1,158 +1,121 @@ #!/usr/bin/env bash - -# get path of current script: https://stackoverflow.com/a/39340259/207661 -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -pushd "$SCRIPT_DIR" >/dev/null - set -e set -x -debug=false -gcc=false -# Parse command line arguments -while [[ $# -gt 0 ]] -do - key="$1" - - case $key in - --debug) - debug=true - shift # past argument - ;; - --gcc) - gcc=true - shift # past argument - ;; +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +pushd "$SCRIPT_DIR" >/dev/null + +downloadHighPolySuv=true +DEBUG="${DEBUG:-false}" + +# ------------------------------- +# Parse arguments +# ------------------------------- +while [[ $# -gt 0 ]]; do + case "$1" in + --debug) + DEBUG=true + ;; + --no-full-poly-car) + downloadHighPolySuv=false + ;; esac - + shift done -function version_less_than_equal_to() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" = "$1"; } - -# check for rpclib -RPC_VERSION_FOLDER="rpclib-2.3.0" -if [ ! -d "./external/rpclib/$RPC_VERSION_FOLDER" ]; then - echo "ERROR: new version of AirSim requires newer rpclib." - echo "please run setup.sh first and then run build.sh again." +# ------------------------------- +# Fedora system dependencies +# ------------------------------- +echo "Installing Fedora dependencies..." +sudo dnf update -y +sudo dnf install -y \ + git cmake clang clang-devel gcc gcc-c++ make \ + llvm llvm-devel libcxx libcxx-devel libcxxabi libcxxabi-devel \ + libstdc++-devel \ + python3 python3-pip \ + wget unzip rsync \ + lsb-release \ + mesa-libGL-devel mesa-libEGL-devel \ + libX11-devel libXcursor-devel libXinerama-devel libXrandr-devel libXi-devel \ + vulkan-loader vulkan-validation-layers mesa-dri-drivers mesa-vulkan-drivers + +# ------------------------------- +# CMake version check +# ------------------------------- +MIN_CMAKE_VERSION=3.10.0 +cmake_ver=$(cmake --version | head -n1 | awk '{print $3}') +function version_less_than_equal_to() { + test "$(printf '%s\n' "$@" | sort -V | head -n 1)" = "$1" +} +if version_less_than_equal_to "$cmake_ver" "$MIN_CMAKE_VERSION"; then + echo "CMake version too old: $cmake_ver" + echo "Please install a newer cmake" exit 1 -fi - -# 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)" - else - CMAKE="$(readlink -f cmake_build/bin/cmake)" - fi else - CMAKE=$(which cmake) + echo "CMake version OK: $cmake_ver" fi -# variable for build output -if $debug; then - build_dir=build_debug -else - build_dir=build_release -fi -if [ "$(uname)" == "Darwin" ]; then - # llvm v8 is too old for Big Sur see - # https://github.com/microsoft/AirSim/issues/3691 - #export CC=/usr/local/opt/llvm@8/bin/clang - #export CXX=/usr/local/opt/llvm@8/bin/clang++ - #now pick up whatever setup.sh installs - export CC="$(brew --prefix)/opt/llvm/bin/clang" - export CXX="$(brew --prefix)/opt/llvm/bin/clang++" -else - if $gcc; then - export CC="gcc-8" - export CXX="g++-8" - else - export CC="clang-8" - export CXX="clang++-8" - fi +# ------------------------------- +# Dialout group for PX4 HIL (optional) +# ------------------------------- +if getent group dialout >/dev/null; then + sudo usermod -aG dialout "$USER" || true fi -#install EIGEN library -if [[ ! -d "./AirLib/deps/eigen3/Eigen" ]]; then - echo "### Eigen is not installed. Please run setup.sh first." - exit 1 -fi - -echo "putting build in $build_dir folder, to clean, just delete the directory..." - -# this ensures the cmake files will be built in our $build_dir instead. -if [[ -f "./cmake/CMakeCache.txt" ]]; then - rm "./cmake/CMakeCache.txt" -fi -if [[ -d "./cmake/CMakeFiles" ]]; then - rm -rf "./cmake/CMakeFiles" +# ------------------------------- +# Download rpclib +# ------------------------------- +if [ ! -d "external/rpclib/rpclib-2.3.0" ]; then + echo "Downloading rpclib..." + rm -rf "external/rpclib" + mkdir -p "external/rpclib" + 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 fi - - -if [[ ! -d $build_dir ]]; then - mkdir -p $build_dir -fi - -# Fix for Unreal/Unity using x86_64 (Rosetta) on Apple Silicon hardware. -CMAKE_VARS= -if [ "$(uname)" == "Darwin" ]; then - CMAKE_VARS="-DCMAKE_APPLE_SILICON_PROCESSOR=x86_64" +# ------------------------------- +# Download high-poly SUV assets +# ------------------------------- +if $downloadHighPolySuv; then + SUV_DIR="Unreal/Plugins/AirSim/Content/VehicleAdv/SUV/v1.2.0" + if [ ! -d "$SUV_DIR" ]; then + echo "Downloading high-poly SUV assets (~37MB)..." + rm -rf suv_download_tmp + mkdir suv_download_tmp + cd suv_download_tmp + wget https://github.com/Microsoft/AirSim/releases/download/v1.2.0/car_assets.zip + unzip -q car_assets.zip -d ../Unreal/Plugins/AirSim/Content/VehicleAdv + cd .. + rm -rf suv_download_tmp + fi +else + echo "Skipping high-poly SUV assets (--no-full-poly-car)" fi -pushd $build_dir >/dev/null -if $debug; then - folder_name="Debug" - "$CMAKE" ../cmake -DCMAKE_BUILD_TYPE=Debug $CMAKE_VARS \ - || (popd && rm -r $build_dir && exit 1) +# ------------------------------- +# Install Eigen library +# ------------------------------- +if [ ! -d "AirLib/deps/eigen3" ]; then + echo "Installing Eigen..." + wget -O eigen3.zip https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip + unzip -q eigen3.zip -d temp_eigen + mkdir -p AirLib/deps/eigen3 + mv temp_eigen/eigen*/Eigen AirLib/deps/eigen3 + rm -rf temp_eigen eigen3.zip else - folder_name="Release" - "$CMAKE" ../cmake -DCMAKE_BUILD_TYPE=Release $CMAKE_VARS \ - || (popd && rm -r $build_dir && exit 1) + echo "Eigen already installed." fi -popd >/dev/null +# ------------------------------- +# Set LLVM_DIR for CMake +# ------------------------------- +export LLVM_DIR=/usr/lib64/cmake/llvm +export CMAKE_PREFIX_PATH=/usr/lib64/cmake:$CMAKE_PREFIX_PATH -pushd $build_dir >/dev/null -# 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"$(nproc)" popd >/dev/null - -mkdir -p AirLib/lib/x64/$folder_name -mkdir -p AirLib/deps/rpclib/lib -mkdir -p AirLib/deps/MavLinkCom/lib -cp $build_dir/output/lib/libAirLib.a AirLib/lib -cp $build_dir/output/lib/libMavLinkCom.a AirLib/deps/MavLinkCom/lib -cp $build_dir/output/lib/librpc.a AirLib/deps/rpclib/lib/librpc.a - -# Update AirLib/lib, AirLib/deps, Plugins folders with new binaries -rsync -a --delete $build_dir/output/lib/ AirLib/lib/x64/$folder_name -rsync -a --delete external/rpclib/$RPC_VERSION_FOLDER/include AirLib/deps/rpclib -rsync -a --delete MavLinkCom/include AirLib/deps/MavLinkCom -rsync -a --delete AirLib Unreal/Plugins/AirSim/Source -rm -rf Unreal/Plugins/AirSim/Source/AirLib/src - -# Update all environment projects -for d in Unreal/Environments/* ; do - [ -L "${d%/}" ] && continue - $d/clean.sh - mkdir -p $d/Plugins - rsync -a --delete Unreal/Plugins/AirSim $d/Plugins -done - set +x - echo "" -echo "" -echo "==================================================================" -echo " AirSim plugin is built! Here's how to build Unreal project." -echo "==================================================================" -echo "All environments under Unreal/Environments have been updated." -echo "" -echo "For further info see:" -echo "https://github.com/Microsoft/AirSim/blob/master/docs/build_linux.md" -echo "==================================================================" - -popd >/dev/null +echo "************************************" +echo " AirSim setup completed successfully " +echo "************************************" diff --git a/setup.sh b/setup.sh index fd0b71e203..53cfa3dd2c 100755 --- a/setup.sh +++ b/setup.sh @@ -1,201 +1,124 @@ #!/usr/bin/env bash -set -x set -e +set -x SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" pushd "$SCRIPT_DIR" >/dev/null downloadHighPolySuv=true +DEBUG="${DEBUG:-false}" MIN_CMAKE_VERSION=3.10.0 -# On macOS, make sure we have a CMake that will support CMAKE_APPLE_SILICON_PROCESSOR. -if [ "$(uname)" == "Darwin" ]; then - MIN_CMAKE_VERSION=3.19.2 -fi - -DEBUG="${DEBUG:-false}" -function version_less_than_equal_to() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" = "$1"; } - -# brew gives error if package is already installed -function brew_install() { brew list "$1" &>/dev/null || brew install "$1"; } - -# Parse command line arguments -while [[ $# -gt 0 ]] -do -key="$1" - -case $key in - --debug) - DEBUG=true - ;; - --no-full-poly-car) - downloadHighPolySuv=false - shift # past value - ;; -esac +function version_less_than_equal_to() { + test "$(printf '%s\n' "$@" | sort -V | head -n 1)" = "$1" +} + +# ------------------------------- +# Parse arguments +# ------------------------------- +while [[ $# -gt 0 ]]; do + case "$1" in + --debug) + DEBUG=true + ;; + --no-full-poly-car) + downloadHighPolySuv=false + ;; + esac + shift done -# llvm tools -if [ "$(uname)" == "Darwin" ]; then # osx - brew update - # Update below line for newer versions - #brew install llvm@8 - brew install llvm -else #linux - sudo apt-get update - sudo apt-get -y install --no-install-recommends \ - lsb-release \ - rsync \ - software-properties-common \ - wget \ - libvulkan1 \ - vulkan-utils - - #install clang and build tools - VERSION=$(lsb_release -rs | cut -d. -f1) - # Since Ubuntu 17 clang is part of the core repository - # See https://packages.ubuntu.com/search?keywords=clang-8 - if [ "$VERSION" -lt "17" ]; then - 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 -fi - -if ! which cmake; then - # CMake not installed - cmake_ver=0 +# ------------------------------- +# Fedora dependencies +# ------------------------------- +echo "Installing Fedora dependencies..." + +sudo dnf update -y +sudo dnf install -y \ + git \ + cmake \ + clang llvm \ + gcc gcc-c++ \ + make \ + wget unzip rsync \ + python3 python3-pip \ + lsb-release \ + mesa-libGL-devel mesa-libEGL-devel \ + libX11-devel libXcursor-devel libXinerama-devel libXrandr-devel libXi-devel \ + vulkan-loader vulkan-validation-layers \ + mesa-dri-drivers mesa-vulkan-drivers + +# ------------------------------- +# Check CMake version +# ------------------------------- +cmake_ver=$(cmake --version | head -n1 | awk '{print $3}') + +if version_less_than_equal_to "$cmake_ver" "$MIN_CMAKE_VERSION"; then + echo "CMake version too old: $cmake_ver" + echo "Please install a newer cmake manually." + exit 1 else - cmake_ver=$(cmake --version 2>&1 | head -n1 | cut -d ' ' -f3 | awk '{print $NF}') + echo "CMake version OK: $cmake_ver" fi -#give user perms to access USB port - this is not needed if not using PX4 HIL -#TODO: figure out how to do below in travis -# Install additional tools, CMake if required -if [ "$(uname)" == "Darwin" ]; then # osx - if [[ -n "${whoami}" ]]; then #this happens when running in travis - sudo dseditgroup -o edit -a "$(whoami)" -t user dialout - fi - - brew_install wget - brew_install coreutils - - if version_less_than_equal_to "$cmake_ver" "$MIN_CMAKE_VERSION"; then - brew install cmake # should get cmake 3.8 - else - echo "Already have good version of cmake: $cmake_ver" - fi - -else #linux - if [[ -n "${whoami}" ]]; then #this happens when running in travis - sudo /usr/sbin/useradd -G dialout "$USER" - sudo usermod -a -G dialout "$USER" - fi - - # install additional tools - sudo apt-get install -y build-essential unzip - - if version_less_than_equal_to "$cmake_ver" "$MIN_CMAKE_VERSION"; then - # in ubuntu 18 docker CI, avoid building cmake from scratch to save time - # ref: https://apt.kitware.com/ - 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-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main' - sudo apt-get -y install --no-install-recommends \ - make \ - cmake - - else - # For Ubuntu 16.04, or anything else, build CMake 3.10.2 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 - rm -rf ./cmake_build - mv ./cmake-3.10.2 ./cmake_build - pushd cmake_build - ./bootstrap - make - popd - fi - fi - - else - echo "Already have good version of cmake: $cmake_ver" - fi - -fi # End USB setup, CMake install - +# ------------------------------- +# Dialout group (PX4 / HIL optional) +# ------------------------------- +if getent group dialout >/dev/null; then + sudo usermod -aG dialout "$USER" || true +fi +# ------------------------------- # Download rpclib +# ------------------------------- if [ ! -d "external/rpclib/rpclib-2.3.0" ]; then - echo "*********************************************************************************************" echo "Downloading rpclib..." - echo "*********************************************************************************************" - + rm -rf external/rpclib + mkdir -p external/rpclib wget https://github.com/rpclib/rpclib/archive/v2.3.0.zip - - # remove previous versions - rm -rf "external/rpclib" - - mkdir -p "external/rpclib" unzip -q v2.3.0.zip -d external/rpclib rm v2.3.0.zip fi -# Download high-polycount SUV model +# ------------------------------- +# Download high-poly SUV assets +# ------------------------------- if $downloadHighPolySuv; then - if [ ! -d "Unreal/Plugins/AirSim/Content/VehicleAdv" ]; then - mkdir -p "Unreal/Plugins/AirSim/Content/VehicleAdv" - fi - if [ ! -d "Unreal/Plugins/AirSim/Content/VehicleAdv/SUV/v1.2.0" ]; then - echo "*********************************************************************************************" - echo "Downloading high-poly car assets.... The download is ~37MB and can take some time." - echo "To install without this assets, re-run setup.sh with the argument --no-full-poly-car" - echo "*********************************************************************************************" - - if [ -d "suv_download_tmp" ]; then - rm -rf "suv_download_tmp" - fi - mkdir -p "suv_download_tmp" - cd suv_download_tmp - wget https://github.com/Microsoft/AirSim/releases/download/v1.2.0/car_assets.zip - if [ -d "../Unreal/Plugins/AirSim/Content/VehicleAdv/SUV" ]; then - rm -rf "../Unreal/Plugins/AirSim/Content/VehicleAdv/SUV" - fi - unzip -q car_assets.zip -d ../Unreal/Plugins/AirSim/Content/VehicleAdv - cd .. - rm -rf "suv_download_tmp" + SUV_DIR="Unreal/Plugins/AirSim/Content/VehicleAdv/SUV/v1.2.0" + if [ ! -d "$SUV_DIR" ]; then + echo "Downloading high-poly SUV assets (~37MB)..." + rm -rf suv_download_tmp + mkdir suv_download_tmp + cd suv_download_tmp + wget https://github.com/Microsoft/AirSim/releases/download/v1.2.0/car_assets.zip + unzip -q car_assets.zip -d ../Unreal/Plugins/AirSim/Content/VehicleAdv + cd .. + rm -rf suv_download_tmp fi else - echo "### Not downloading high-poly car asset (--no-full-poly-car). The default unreal vehicle will be used." + echo "Skipping high-poly SUV assets (--no-full-poly-car)" fi -echo "Installing Eigen library..." - +# ------------------------------- +# Install Eigen +# ------------------------------- if [ ! -d "AirLib/deps/eigen3" ]; then - echo "Downloading Eigen..." + echo "Installing Eigen..." wget -O eigen3.zip https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip unzip -q eigen3.zip -d temp_eigen mkdir -p AirLib/deps/eigen3 mv temp_eigen/eigen*/Eigen AirLib/deps/eigen3 - rm -rf temp_eigen - rm eigen3.zip + rm -rf temp_eigen eigen3.zip else - echo "Eigen is already installed." + echo "Eigen already installed." fi popd >/dev/null - set +x + echo "" echo "************************************" -echo "AirSim setup completed successfully!" +echo " AirSim setup completed successfully " echo "************************************" +