From eaf5ac08e5caa21a3e42a2924fb121435a340763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 9 Oct 2020 13:31:32 +0300 Subject: [PATCH] Build lldb-mi Building this tool requires having a full LLVM build available; either by installing without LLVM_INSTALL_TOOLCHAIN_ONLY (and not stripping the llvm installation yet) or by pointing it at the LLVM build directory instead. The latter works better for our normal build flows. --- .dockerignore | 1 + .gitignore | 1 + Dockerfile | 3 +- Dockerfile.cross | 4 ++ Dockerfile.dev | 4 ++ build-all.sh | 1 + build-cross-tools.sh | 1 + build-lldb-mi.sh | 118 +++++++++++++++++++++++++++++++++++++++++++ strip-llvm.sh | 2 +- 9 files changed, 133 insertions(+), 2 deletions(-) create mode 100755 build-lldb-mi.sh diff --git a/.dockerignore b/.dockerignore index ff519e3..efa0786 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,7 @@ llvm-project mingw-w64 libssp +lldb-mi make-* **/*.exe **/*.dll diff --git a/.gitignore b/.gitignore index 4efc857..69c6256 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /llvm-project /mingw-w64 /libssp +/lldb-mi /make-* diff --git a/Dockerfile b/Dockerfile index 28daee8..d30797c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,9 +45,10 @@ ARG TOOLCHAIN_ARCHS="i686 x86_64 armv7 aarch64" ARG DEFAULT_CRT=ucrt # Build everything that uses the llvm monorepo. We need to build the mingw runtime before the compiler-rt/libunwind/libcxxabi/libcxx runtimes. -COPY build-llvm.sh strip-llvm.sh install-wrappers.sh build-mingw-w64.sh build-mingw-w64-tools.sh build-compiler-rt.sh build-mingw-w64-libraries.sh build-libcxx.sh build-openmp.sh ./ +COPY build-llvm.sh build-lldb-mi.sh strip-llvm.sh install-wrappers.sh build-mingw-w64.sh build-mingw-w64-tools.sh build-compiler-rt.sh build-mingw-w64-libraries.sh build-libcxx.sh build-openmp.sh ./ COPY wrappers/*.sh wrappers/*.c wrappers/*.h ./wrappers/ RUN ./build-llvm.sh $TOOLCHAIN_PREFIX && \ + ./build-lldb-mi.sh $TOOLCHAIN_PREFIX && \ ./strip-llvm.sh $TOOLCHAIN_PREFIX && \ ./install-wrappers.sh $TOOLCHAIN_PREFIX && \ ./build-mingw-w64.sh $TOOLCHAIN_PREFIX --with-default-msvcrt=$DEFAULT_CRT && \ diff --git a/Dockerfile.cross b/Dockerfile.cross index 9405173..84071e1 100644 --- a/Dockerfile.cross +++ b/Dockerfile.cross @@ -20,6 +20,10 @@ ARG FULL_LLVM COPY build-llvm.sh . RUN ./build-llvm.sh $CROSS_TOOLCHAIN_PREFIX --host=$HOST + +COPY build-lldb-mi.sh . +RUN ./build-lldb-mi.sh $CROSS_TOOLCHAIN_PREFIX --host=$HOST + COPY strip-llvm.sh . RUN ./strip-llvm.sh $CROSS_TOOLCHAIN_PREFIX --host=$HOST diff --git a/Dockerfile.dev b/Dockerfile.dev index a34aa3f..a615a52 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -46,6 +46,10 @@ ARG FULL_LLVM COPY build-llvm.sh ./ RUN ./build-llvm.sh $TOOLCHAIN_PREFIX +# Build LLDB-MI +COPY build-lldb-mi.sh ./ +RUN ./build-lldb-mi.sh $TOOLCHAIN_PREFIX + # Strip the LLVM install output immediately. (This doesn't reduce the # total docker image size as long as it is in a separate RUN layer though, # but reduces build times if tweaking the contents of strip-llvm.sh.) diff --git a/build-all.sh b/build-all.sh index c1ce818..0a9c63a 100755 --- a/build-all.sh +++ b/build-all.sh @@ -30,6 +30,7 @@ for dep in git curl cmake; do done ./build-llvm.sh $PREFIX +./build-lldb-mi.sh $PREFIX ./install-wrappers.sh $PREFIX ./build-mingw-w64.sh $PREFIX ./build-mingw-w64-tools.sh $PREFIX diff --git a/build-cross-tools.sh b/build-cross-tools.sh index c73fe87..f5ef76c 100755 --- a/build-cross-tools.sh +++ b/build-cross-tools.sh @@ -28,6 +28,7 @@ export PATH="$NATIVE/bin:$PATH" HOST=$CROSS_ARCH-w64-mingw32 ./build-llvm.sh $PREFIX --host=$HOST +./build-lldb-mi.sh $PREFIX --host=$HOST ./strip-llvm.sh $PREFIX --host=$HOST ./build-mingw-w64-tools.sh $PREFIX --skip-include-triplet-prefix --host=$HOST ./install-wrappers.sh $PREFIX --host=$HOST diff --git a/build-lldb-mi.sh b/build-lldb-mi.sh new file mode 100755 index 0000000..e738587 --- /dev/null +++ b/build-lldb-mi.sh @@ -0,0 +1,118 @@ +#!/bin/sh +# +# Copyright (c) 2020 Martin Storsjo +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +set -e + +: ${LLDB_MI_VERSION:=89945aa323c82125ee5d5b841988db17fc357dd6} +BUILDDIR=build +unset HOST + +while [ $# -gt 0 ]; do + case "$1" in + --host=*) + HOST="${1#*=}" + ;; + *) + PREFIX="$1" + ;; + esac + shift +done +if [ -z "$PREFIX" ]; then + echo $0 [--host=] dest + exit 1 +fi + +mkdir -p "$PREFIX" +PREFIX="$(cd "$PREFIX" && pwd)" + +if [ ! -d lldb-mi ]; then + git clone https://github.com/lldb-tools/lldb-mi.git + CHECKOUT=1 +fi + +if [ -n "$SYNC" ] || [ -n "$CHECKOUT" ]; then + cd lldb-mi + [ -z "$SYNC" ] || git fetch + git checkout $LLDB_MI_VERSION + cd .. +fi + +if [ -n "$(which ninja)" ]; then + CMAKE_GENERATOR="Ninja" + NINJA=1 + BUILDCMD=ninja +else + : ${CORES:=$(nproc 2>/dev/null)} + : ${CORES:=$(sysctl -n hw.ncpu 2>/dev/null)} + : ${CORES:=4} + + case $(uname) in + MINGW*) + CMAKE_GENERATOR="MSYS Makefiles" + ;; + *) + ;; + esac + BUILDCMD=make +fi + +export LLVM_DIR="$PREFIX" + +# Try to find/guess the builddir under the llvm buildtree next by. +# If LLVM was built without LLVM_INSTALL_TOOLCHAIN_ONLY, and the LLVM +# installation directory hasn't been stripped, we should point the build there. +# But as this isn't necessarily the case, point to the LLVM build directory +# instead (which hopefully hasn't been removed yet). +LLVM_SRC="$(pwd)/llvm-project/llvm" +if [ -d "$LLVM_SRC" ]; then + SUFFIX=${HOST+-}$HOST + for base in build build-asserts; do + if [ -d "$LLVM_SRC/$base$SUFFIX" ]; then + export LLVM_DIR="$LLVM_SRC/$base$SUFFIX" + break + fi + done +fi + +if [ -n "$HOST" ]; then + BUILDDIR=$BUILDDIR-$HOST + + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_NAME=Windows" + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CROSSCOMPILING=TRUE" + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=$HOST-gcc" + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER=$HOST-g++" + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_RC_COMPILER=$HOST-windres" + + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH=$LLVM_DIR" + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER" + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY" + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY" +fi + +cd lldb-mi + +[ -z "$CLEAN" ] || rm -rf $BUILDDIR +mkdir -p $BUILDDIR +cd $BUILDDIR +cmake \ + ${CMAKE_GENERATOR+-G} "$CMAKE_GENERATOR" \ + -DCMAKE_INSTALL_PREFIX="$PREFIX" \ + -DCMAKE_BUILD_TYPE=Release \ + $CMAKEFLAGS \ + .. + +$BUILDCMD ${CORES+-j$CORES} install/strip diff --git a/strip-llvm.sh b/strip-llvm.sh index e2ff275..3df8e18 100755 --- a/strip-llvm.sh +++ b/strip-llvm.sh @@ -84,7 +84,7 @@ for i in bugpoint c-index-test clang-* diagtool dsymutil git-clang-format hmapto rm $i fi ;; - lldb|lldb-server|lldb-argdumper|lldb-instr) + lldb|lldb-server|lldb-argdumper|lldb-instr|lldb-mi) ;; *) if [ -f $i ]; then