Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux build improvements - clang8, no custom libcxx #2500

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ jobs:

- name: MacOS
os: osx
env:
- TOOL="cmake"
- DESCRIPTION="OS X build/test via CMake"
- LLVM_PACKAGE="clang+llvm-5.0.2-x86_64-apple-darwin"
- CIINSTALL=yes


before_install:
Expand All @@ -34,9 +29,7 @@ before_install:
sudo apt-get -y install git wget unzip;
sudo apt-get -y install build-essential software-properties-common cmake rsync libboost-all-dev;
elif [[ "$TRAVIS_OS_NAME" == "osx" ]] && [[ "$TOOL" == "cmake" ]]; then
wget http://releases.llvm.org/5.0.2/${LLVM_PACKAGE}.tar.xz;
tar -xf ${LLVM_PACKAGE}.tar.xz;
export LLVM_DIR=${TRAVIS_BUILD_DIR}/${LLVM_PACKAGE};
echo "No before_install actions for OSX";
fi

script:
Expand Down
36 changes: 4 additions & 32 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,40 +62,14 @@ if $gccBuild; then
export CXX="g++"
fi
else
#check for correct verion of llvm
if [[ ! -d "llvm-source-50" ]]; then
if [[ -d "llvm-source-39" ]]; then
echo "Hello there! We just upgraded AirSim to Unreal Engine 4.24."
echo "Here are few easy steps for upgrade so everything is new and shiny :)"
echo "https://github.com/Microsoft/AirSim/blob/master/docs/unreal_upgrade.md"
exit 1
else
echo "The llvm-souce-50 folder was not found! Mystery indeed."
fi
fi

# check for libc++
if [[ !(-d "./llvm-build/output/lib") ]]; then
echo "ERROR: clang++ and libc++ is necessary to compile AirSim and run it in Unreal engine"
echo "Please run setup.sh first."
exit 1
fi

# variable for build output
build_dir=build_debug
if [ "$(uname)" == "Darwin" ]; then

if [[ -n $CIINSTALL ]]; then # use downloaded binaries on Travis
export CC=${LLVM_DIR}/bin/clang
export CXX=${LLVM_DIR}/bin/clang++
else
export CC=/usr/local/opt/llvm-5.0/bin/clang-5.0
export CXX=/usr/local/opt/llvm-5.0/bin/clang++-5.0
fi

export CC=/usr/local/opt/llvm@8/bin/clang
export CXX=/usr/local/opt/llvm@8/bin/clang++
else
export CC="clang-5.0"
export CXX="clang++-5.0"
export CC="clang-8"
export CXX="clang++-8"
fi
fi

Expand Down Expand Up @@ -131,7 +105,6 @@ pushd $build_dir >/dev/null
make -j`nproc`
popd >/dev/null


mkdir -p AirLib/lib/x64/Debug
mkdir -p AirLib/deps/rpclib/lib
mkdir -p AirLib/deps/MavLinkCom/lib
Expand Down Expand Up @@ -165,5 +138,4 @@ echo "For help see:"
echo "https://github.com/Microsoft/AirSim/blob/master/docs/build_linux.md"
echo "=================================================================="


popd >/dev/null
27 changes: 1 addition & 26 deletions cmake/cmake-modules/CommonSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ macro(CommonSetup)
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/output/bin)
SET(LIBRARY_OUTPUT_PATH ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})

#libcxx which we will use with specific version of clang
SET(LIBCXX_INC_PATH ${AIRSIM_ROOT}/llvm-build/output/include/c++/v1)
SET(LIBCXX_LIB_PATH ${AIRSIM_ROOT}/llvm-build/output/lib)

#setup include and lib for rpclib which will be referenced by other projects
set(RPCLIB_VERSION_FOLDER rpclib-2.2.1)
set(RPC_LIB_INCLUDES " ${AIRSIM_ROOT}/external/rpclib/${RPCLIB_VERSION_FOLDER}/include")
Expand All @@ -58,36 +54,15 @@ macro(CommonSetup)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__CLANG__")
else ()
# other flags used in Unreal: -funwind-tables -fdiagnostics-format=msvc -fno-inline -Werror -fno-omit-frame-pointer -fstack-protector -O2
# TODO: add back -Wunused-parameter -Wno-documentation after rpclib can be compiled
set(CMAKE_CXX_FLAGS "\
-std=c++14 -ggdb -Wall -Wextra -Wstrict-aliasing -Wunreachable-code -Wcast-qual -Wctor-dtor-privacy \
-std=c++14 -stdlib=libc++ -ggdb -Wall -Wextra -Wstrict-aliasing -Wunreachable-code -Wcast-qual -Wctor-dtor-privacy \
-Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-include-dirs -Wswitch-default \
-Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wstrict-overflow=5 -Wswitch-default -Wundef \
-Wno-variadic-macros -Wno-parentheses -Wno-unused-function -Wno-unused -Wno-documentation -fdiagnostics-show-option \
-pthread \
${RPC_LIB_DEFINES} ${CMAKE_CXX_FLAGS}")

if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
# make sure to match the compiler flags with which the Unreal
# Engine is built with
set(CMAKE_CXX_FLAGS "\
-nostdinc++ -ferror-limit=10 -isystem ${LIBCXX_INC_PATH} \
-D__CLANG__ ${CMAKE_CXX_FLAGS}")

# removed -lsupc++ from below (Git issue # 678)
set(CMAKE_EXE_LINKER_FLAGS "\
${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++ -lc++abi -lm -lc \
-L ${LIBCXX_LIB_PATH} -rpath ${LIBCXX_LIB_PATH}")

#do not use experimental as it might potentially cause ABI issues
#set(CXX_EXP_LIB "-lc++experimental")

if("${BUILD_TYPE}" STREQUAL "debug")
# set same options that Unreal sets in debug builds
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funwind-tables -fdiagnostics-format=msvc -fno-inline -fno-omit-frame-pointer -fstack-protector")
endif()

else()
set(CXX_EXP_LIB "-lstdc++fs -fmax-errors=10 -Wnoexcept -Wstrict-null-sentinel")
endif ()
Expand Down
83 changes: 7 additions & 76 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
#! /bin/bash

if [[ -d "llvm-source-39" ]]; then
echo "Hello there! We just upgraded AirSim to Unreal Engine 4.24."
echo "Here are few easy steps for upgrade so everything is new and shiny :)"
echo "https://github.com/Microsoft/AirSim/blob/master/docs/unreal_upgrade.md"
exit 1
fi

set -x
# set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
pushd "$SCRIPT_DIR" >/dev/null
Expand Down Expand Up @@ -60,33 +51,19 @@ if $gccBuild; then
else
# llvm tools
if [ "$(uname)" == "Darwin" ]; then # osx

if [[ -n $CIINSTALL ]]; then # use downloaded binaries on Travis
export C_COMPILER=${LLVM_DIR}/bin/clang
export COMPILER=${LLVM_DIR}/bin/clang++
else
brew update

# brew install llvm@3.9
brew tap llvm-hs/homebrew-llvm
brew install llvm-5.0
export C_COMPILER=/usr/local/opt/llvm-5.0/bin/clang-5.0
export COMPILER=/usr/local/opt/llvm-5.0/bin/clang++-5.0
fi

brew update
brew tap llvm-hs/homebrew-llvm
brew install llvm@8
else #linux
#install clang and build tools

VERSION=$(lsb_release -rs | cut -d. -f1)
# Since Ubuntu 17 clang-5.0 is part of the core repository
# See https://packages.ubuntu.com/search?keywords=clang-5.0
# 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 -
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-5.0 clang++-5.0
export C_COMPILER=clang-5.0
export COMPILER=clang++-5.0
sudo apt-get install -y clang-8 clang++-8 libc++-8-dev libc++abi-8-dev
fi
fi

Expand Down Expand Up @@ -134,15 +111,8 @@ if version_less_than_equal_to $cmake_ver $MIN_CMAKE_VERSION; then
make
popd
fi

if [ "$(uname)" == "Darwin" ]; then
CMAKE="$(greadlink -f cmake_build/bin/cmake)"
else
CMAKE="$(readlink -f cmake_build/bin/cmake)"
fi
else
echo "Already have good version of cmake: $cmake_ver"
CMAKE=$(which cmake)
fi

# Download rpclib
Expand Down Expand Up @@ -189,45 +159,6 @@ else
echo "### Not downloading high-poly car asset (--no-full-poly-car). The default unreal vehicle will be used."
fi

# Below is alternative way to get clang by downloading binaries
# get clang, libc++
# sudo rm -rf llvm-build
# mkdir -p llvm-build/output
# wget "http://releases.llvm.org/4.0.1/clang+llvm-4.0.1-x86_64-linux-gnu-debian8.tar.xz"
# tar -xf "clang+llvm-4.0.1-x86_64-linux-gnu-debian8.tar.xz" -C llvm-build/output

# #other packages - not need for now
# #sudo apt-get install -y clang-3.9-doc libclang-common-3.9-dev libclang-3.9-dev libclang1-3.9 libclang1-3.9-dbg libllvm-3.9-ocaml-dev libllvm3.9 libllvm3.9-dbg lldb-3.9 llvm-3.9 llvm-3.9-dev llvm-3.9-doc llvm-3.9-examples llvm-3.9-runtime clang-format-3.9 python-clang-3.9 libfuzzer-3.9-dev

#get libc++ source
if ! $gccBuild; then
echo "### Installing llvm 5 libc++ library..."
if [[ ! -d "llvm-source-50" ]]; then
git clone --depth=1 -b release_50 https://github.com/llvm-mirror/llvm.git llvm-source-50
git clone --depth=1 -b release_50 https://github.com/llvm-mirror/libcxx.git llvm-source-50/projects/libcxx
git clone --depth=1 -b release_50 https://github.com/llvm-mirror/libcxxabi.git llvm-source-50/projects/libcxxabi
else
echo "folder llvm-source-50 already exists, skipping git clone..."
fi

# build libc++
rm -rf llvm-build
mkdir -p llvm-build
pushd llvm-build >/dev/null

"$CMAKE" -DCMAKE_C_COMPILER=${C_COMPILER} -DCMAKE_CXX_COMPILER=${COMPILER} \
-LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF -DLIBCXX_INSTALL_EXPERIMENTAL_LIBRARY=OFF \
-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=./output \
../llvm-source-50

make cxx -j`nproc`

# install libc++ locally in output folder
make install-libcxx install-libcxxabi

popd >/dev/null
fi

echo "Installing EIGEN library..."

rm -rf ./AirLib/deps/eigen3/Eigen
Expand Down