about summary refs log tree commit diff homepage
path: root/scripts/build
diff options
context:
space:
mode:
authorMartin Nowack <m.nowack@imperial.ac.uk>2019-03-12 09:51:31 +0000
committerCristian Cadar <c.cadar@imperial.ac.uk>2019-03-17 15:43:21 +0000
commit3b6f5e52d0cec5e8018c590c9feccb39bb03206c (patch)
treeccb28b664837ccbb8e536995520d4f3e256b4efd /scripts/build
parente06ab0db462c1c64bf26f856f4a8448d1ebf199d (diff)
downloadklee-3b6f5e52d0cec5e8018c590c9feccb39bb03206c.tar.gz
Add support for libc++ as part of the build.sh scripts
Diffstat (limited to 'scripts/build')
-rw-r--r--scripts/build/p-libcxx-linux-ubuntu-16.04.inc22
-rw-r--r--scripts/build/p-libcxx-osx.inc7
-rw-r--r--scripts/build/p-libcxx.inc118
-rw-r--r--scripts/build/v-libcxx.inc17
4 files changed, 164 insertions, 0 deletions
diff --git a/scripts/build/p-libcxx-linux-ubuntu-16.04.inc b/scripts/build/p-libcxx-linux-ubuntu-16.04.inc
new file mode 100644
index 00000000..40909f21
--- /dev/null
+++ b/scripts/build/p-libcxx-linux-ubuntu-16.04.inc
@@ -0,0 +1,22 @@
+install_build_dependencies_libcxx() { 
+  apt-get update -y
+
+  dependencies=(
+    build-essential
+    ca-certificates
+    git
+    python3
+    cmake
+    curl
+    
+    file # Needed for wllvm
+  )
+
+  #Install essential dependencies
+  apt -y --no-install-recommends install "${dependencies[@]}"
+
+  curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
+  python3 get-pip.py --user
+  export PATH="${HOME}/.local/bin:$PATH"
+  pip3 install wllvm
+}
\ No newline at end of file
diff --git a/scripts/build/p-libcxx-osx.inc b/scripts/build/p-libcxx-osx.inc
new file mode 100644
index 00000000..c53ac37f
--- /dev/null
+++ b/scripts/build/p-libcxx-osx.inc
@@ -0,0 +1,7 @@
+# Build dependencies
+install_build_dependencies_libcxx() {
+  set +e
+  brew upgrade python               # upgrade to Python 3
+  set -e
+  pip3 install wllvm
+}
\ No newline at end of file
diff --git a/scripts/build/p-libcxx.inc b/scripts/build/p-libcxx.inc
new file mode 100644
index 00000000..41ca4cc4
--- /dev/null
+++ b/scripts/build/p-libcxx.inc
@@ -0,0 +1,118 @@
+# Build scripts for libc++
+setup_build_variables_libcxx() {
+  LIBCXX_SRC="${BASE}/libc++-${LLVM_VERSION_SHORT}"
+  LIBCXX_BUILD="${BASE}/libc++-build-${LLVM_VERSION_SHORT}"
+  LIBCXX_INSTALL="${BASE}/libc++-install-${LLVM_VERSION_SHORT}"
+}
+
+download_libcxx() {
+  # Skip step if we already checked out code
+  [[ -f "${LIBCXX_SRC}/.src_checked_out" ]] && return 0
+
+  local LLVM_VERSION_MAJOR="${LLVM_VERSION/.*/}"
+
+  local version=""
+  [[ "${LLVM_VERSION_MAJOR}" -le 3 ]] && version="release/${LLVM_VERSION}.x"
+  [[ "${LLVM_VERSION_MAJOR}" -ge 4 ]] && version="release/${LLVM_VERSION_MAJOR}.x"
+
+
+  git clone --single-branch --branch "${version}" --depth 1 "https://github.com/llvm/llvm-project.git" "${LIBCXX_SRC}"
+  
+  # Prepare LLVM subprojects for older LLVM versions
+  cd "${LIBCXX_SRC}/llvm/projects"
+  ln -s ../../libcxx .
+  ln -s ../../libcxxabi .
+
+  touch "${LIBCXX_SRC}/.src_checked_out" 
+}
+
+build_libcxx() { 
+  mkdir -p "${LIBCXX_BUILD}"
+  cd "${LIBCXX_BUILD}"
+  local LLVM_VERSION_MAJOR="${LLVM_VERSION/.*/}"
+
+  local cmake_flags=(
+   "-DLLVM_ENABLE_PROJECTS=libcxx;libcxxabi"
+   "-DLLVM_ENABLE_THREADS:BOOL=OFF"
+   "-DLIBCXX_ENABLE_THREADS:BOOL=OFF"
+   "-DLIBCXX_ENABLE_SHARED:BOOL=ON"
+   "-DLIBCXXABI_ENABLE_THREADS:BOOL=OFF"
+   "-DCMAKE_BUILD_TYPE:STRING=Release"
+   "-DCMAKE_INSTALL_PREFIX=${LIBCXX_INSTALL}"
+  )
+
+  # Static ABI libraries are not supported under OS X
+  if [[ "${OS}" == "osx" ]]; then
+    cmake_flags+=("-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY:BOOL=OFF")
+  else
+    cmake_flags+=("-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY:BOOL=ON")
+  fi
+
+  (
+    export CC=wllvm
+    export CXX=wllvm++
+    export LLVM_COMPILER=clang
+    export LLVM_COMPILER_PATH="$(dirname "${BITCODE_CC}")"
+
+    cmake "${cmake_flags[@]}" "${LIBCXX_SRC}/llvm"
+    make cxx
+  )
+}
+
+install_libcxx() {
+  cd "${LIBCXX_BUILD}"
+  (
+    export CC=wllvm
+    export CXX=wllvm++
+    export LLVM_COMPILER=clang
+    export LLVM_COMPILER_PATH="$(dirname "${BITCODE_CC}")"
+
+    cd "${LIBCXX_BUILD}/projects"
+    make install
+
+    local libraries
+
+    if [[ "${OS}" == "osx" ]]; then
+      libraries=("${LIBCXX_INSTALL}"/lib/lib*.dylib)
+    else
+      libraries=("${LIBCXX_INSTALL}"/lib/lib*.so)
+    fi
+
+    local LLVM_VERSION_MAJOR="${LLVM_VERSION/.*/}"
+    [[ "${LLVM_VERSION_MAJOR}" -ge 6 ]] && libraries+=("${LIBCXX_INSTALL}"/lib/lib*.a)
+
+
+    for p in "${libraries[@]}" ; do
+      extract-bc "$p"
+    done
+
+    touch "${LIBCXX_INSTALL}"/.is_installed
+  )
+  return 0
+}
+
+# Check if the binary artifact is installed
+is_installed_libcxx() {
+  (
+    setup_build_variables_libcxx
+    [[ -f "${LIBCXX_INSTALL}"/.is_installed ]]
+  ) || return 1
+}
+
+get_docker_config_id_libcxx() {
+  (
+    echo "${LLVM_VERSION_SHORT}"
+  )
+}
+
+get_build_artifacts_libcxx() {
+  (
+    setup_build_variables_libcxx
+    echo "${LIBCXX_SRC}"
+    echo "${LIBCXX_INSTALL}"
+  )
+}
+
+setup_artifact_variables_libcxx() {
+  setup_build_variables_libcxx
+}
\ No newline at end of file
diff --git a/scripts/build/v-libcxx.inc b/scripts/build/v-libcxx.inc
new file mode 100644
index 00000000..669bb536
--- /dev/null
+++ b/scripts/build/v-libcxx.inc
@@ -0,0 +1,17 @@
+required_variables_libcxx=(
+  "LLVM_VERSION"
+)
+
+required_variables_check_libcxx() {
+  local LLVM_VERSION_MAJOR="${LLVM_VERSION/.*/}"
+  local LLVM_VERSION_MINOR="${LLVM_VERSION/*./}"
+  # Check versions: no support for LLVM < 3.8
+#  if [[ "${LLVM_VERSION_MAJOR}" -eq 3 ]]; then
+#    [[ "${LLVM_VERSION_MINOR}" -lt 8 ]] && { echo "Version <= 3.7 not supported"; return 1; }
+#  fi
+  return 0
+}
+
+artifact_dependency_libcxx(){
+  echo "clang"
+}
\ No newline at end of file