Skip to content

Install ROSE with Clang as frontend

Anjia Wang edited this page Jul 20, 2020 · 2 revisions

1. Prerequisite

OS: Ubuntu 18.04 Packages:

sudo apt update
sudo apt install -y openjdk-8-jdk
sudo apt install -y \
    automake \
    bison \
    build-essential \
    cmake \
    curl \
    flex \
    g++ \
    gcc \
    gcc-multilib \
    gdb \
    gfortran \
    ghostscript \
    git \
    graphviz \
    iputils-ping \
    libtinfo-dev \
    libtool \
    ninja-build \
    python-pip \
    util-linux \
    vim \
    wget \
    zlib1g-dev

2. Install Clang/LLVM

At the moment, only Clang 9.x built from source works with ROSE develop branch. The support of Clang 10.x is work-in-progress.

# These three locations should be modified accordingly.
export LLVM_SRC=$HOME/Projects/llvm9/llvm_src
export LLVM_PATH=$HOME/Projects/llvm9/llvm_install
export LLVM_BUILD=$HOME/Projects/llvm9/llvm_build

mkdir -p $LLVM_SRC
mkdir -p $LLVM_PATH
mkdir -p $LLVM_BUILD
cd $LLVM_SRC
git clone -b release/9.x https://github.com/llvm/llvm-project .
cd $LLVM_BUILD
cmake -G Ninja  -DLLVM_USE_LINKER=gold  -DLLVM_ENABLE_RTTI=ON -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$LLVM_PATH -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;compiler-rt;openmp;libcxx;libcxxabi" $LLVM_SRC/llvm
ninja install -j6 -l6

export PATH=$LLVM_PATH/bin:$PATH
export LD_LIBRARY_PATH=$LLVM_PATH/libexec:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$LLVM_PATH/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=$LLVM_PATH/libexec:$LIBRARY_PATH
export LIBRARY_PATH=$LLVM_PATH/lib:$LIBRARY_PATH
export MANPATH=$LLVM_PATH/share/man:$MANPATH
export C_INCLUDE_PATH=$LLVM_PATH/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=$LLVM_PATH/include:CPLUS_INCLUDE_PATH

3. Install Boost

We could build the latest Boost from source. Boost 1.65 coming from Ubuntu official packages also works well, but please DO NOT do both.

Install from source

export BOOST_SRC=$HOME/Projects/boost/boost_src
export BOOST_PATH=$HOME/Projects/boost/boost_install

mkdir -p $BOOST_PATH
cd $BOOST_PATH/..
wget https://dl.bintray.com/boostorg/release/1.73.0/source/boost_1_73_0.tar.bz2
tar --bzip2 -xf boost_1_73_0.tar.bz2
mv boost_1_73_0 boost_src
rm boost_1_73_0.tar.bz2
cd $BOOST_SRC
./bootstrap.sh --with-toolset=clang --prefix=$BOOST_PATH
CC=clang CXX=clang++ ./b2 install --prefix=$BOOST_PATH

Install from Ubuntu package

sudo apt install libboost-all-dev

4. Install ROSE

Please make sure the environment variables are set as shown above.

# Setup environment
export ROSE_SRC=$HOME/Projects/rose/rose_src
export ROSE_PATH=$HOME/Projects/rose/rose_install
export ROSE_BUILD=$HOME/Projects/rose/rose_build
export PATH=$ROSE_PATH/bin:$PATH
export LD_LIBRARY_PATH=$ROSE_PATH/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=$ROSE_PATH/lib:$LIBRARY_PATH

mkdir -p $ROSE_BUILD
git clone -b develop https://github.com/rose-compiler/rose.git $ROSE_SRC
cd $ROSE_SRC
./build
cd $ROSE_BUILD
$ROSE_SRC/configure --with-boost=$BOOST_PATH --enable-clang-frontend --enable-tests-directory --enable-languages=c,c++,fortran --prefix=$ROSE_PATH CXXFLAGS=-std=c++11 CC=clang CXX=clang++
# If Boost is installed from Ubuntu package, the following line should be used instead.
# $ROSE_SRC/configure --with-boost=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu --enable-clang-frontend --enable-tests-directory --enable-languages=c,c++,fortran --prefix=$ROSE_PATH CXXFLAGS=-std=c++11 CC=clang CXX=clang++
make core -j6
make install-core

5. Usage

After building ROSE with Clang and setting up the environment variables, the following code could be executed to compile a program foo.c. As usual, other compilation parameters may be used accordingly. Clang frontend hasn't been fully supported in ROSE. Please check the latest source code of Clang module in ROSE here.

rose-compiler foo.c

6. Docker

Two docker images are created for quick usage.

Full version

In this image, Clang 9.x, Boost 1.65 and ROSE are installed and ready for use. It can be pulled from Docker Hub.

docker pull ouankou/rose:clang-develop
docker run -it ouankou/rose:clang-develop bash

The dockerfile can be found here.

Base version

Only Clang 9.x and Boost 1.65 are installed. User could download ROSE source and make some changes before building. The whole development environment has been properly configured.

docker pull ouankou/rose:clang-base
docker run -it ouankou/rose:clang-base bash

The dockerfile can be found here.