Skip to content

Commit

Permalink
Attempt to use ccache, stage correct llvm packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Mobarak committed Jun 11, 2018
1 parent e56f084 commit 2fe5fd2
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 31 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ branches:
services:
- docker

cache:
directories:
- output/ccache

matrix:
include:
- env:
Expand Down
13 changes: 6 additions & 7 deletions Dockerfile → Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ RUN apt-get update \
&& wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \
&& echo "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-4.0 main" \
>/etc/apt/sources.list.d/llvm40.list \
&& echo "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main" \
>/etc/apt/sources.list.d/llvm60.list \
&& apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y libcurl4-openssl-dev \
build-essential \
bison \
flex \
ninja-build \
llvm-4.0 \
llvm-4.0-dev \
clang-4.0 \
git \
m4 \
gperf \
Expand All @@ -45,6 +44,7 @@ RUN apt-get update \
libtinfo-dev \
python \
python-dev \
ccache \
binutils-multiarch-dev \
g++-4.8-arm-linux-gnueabihf \
gcc-4.8-arm-linux-gnueabihf \
Expand All @@ -66,10 +66,9 @@ RUN apt-get update \
&& tar -xzf cmake-3.10.1.tar.gz \
&& cd cmake-3.10.1 \
&& ./configure \
&& make -j4 \
&& make install \
&& make -j8 \
&& make -j8 install \
&& cd .. && rm -rf cmake-* \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
&& apt-get clean

# EOF
14 changes: 14 additions & 0 deletions Dockerfile.obfuscator
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2017-2018 Swift Navigation Inc.
# Contact: Swift Navigation <[email protected]>
#
# This source is subject to the license found in the file 'LICENSE' which must
# be be distributed together with this source. All other rights reserved.
#
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

ARG DOCKER_NAMETAG
FROM $DOCKER_NAMETAG

RUN apt-get install -y llvm-4.0 llvm-4.0-dev clang-4.0 libclang-4.0-dev
14 changes: 14 additions & 0 deletions Dockerfile.vanilla
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2017-2018 Swift Navigation Inc.
# Contact: Swift Navigation <[email protected]>
#
# This source is subject to the license found in the file 'LICENSE' which must
# be be distributed together with this source. All other rights reserved.
#
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

ARG DOCKER_NAMETAG
FROM $DOCKER_NAMETAG

RUN apt-get install -y llvm-6.0 llvm-6.0-dev clang-6.0 libclang-6.0-dev
19 changes: 12 additions & 7 deletions base.bash
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@ fi

docker build \
--force-rm --no-cache \
-f Dockerfile -t "$DOCKER_NAMETAG" .
-f Dockerfile.base -t "$DOCKER_NAMETAG" .

if [[ -n "${DOCKER_USER:-}" ]] && [[ -n "${DOCKER_PASS:-}" ]]; then
echo "$DOCKER_PASS" | docker login --username="$DOCKER_USER" --password-stdin
docker push "$DOCKER_NAMETAG"
else
echo "WARNING: not pushing new image to Docker Hub..." >&2
fi
docker build \
--force-rm --no-cache \
--build-arg "DOCKER_NAMETAG=$DOCKER_NAMETAG" \
-f Dockerfile.vanilla -t "$DOCKER_NAMETAG-vanilla" .

docker build \
--force-rm --no-cache \
--build-arg "DOCKER_NAMETAG=$DOCKER_NAMETAG" \
-f Dockerfile.obfuscator -t "$DOCKER_NAMETAG-obfuscator" .

./push.bash
16 changes: 13 additions & 3 deletions build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ IFS=$'\n\t'
DOCKER_NAMETAG=$(cat docker_nametag)

mkdir -p output/opt
mkdir -p output/ccache

VERBOSE=
NO_TTY=
Expand Down Expand Up @@ -48,7 +49,9 @@ if [[ -z "${VARIANT:-}" ]]; then
exit 1
fi

set -x
CXX_FLAGS="-L/toolchain/x86/x86_64-buildroot-linux-gnu/sysroot/lib \
-L/toolchain/x86/x86_64-buildroot-linux-gnu/sysroot/usr/lib \
-I/toolchain/x86/lib/gcc/x86_64-buildroot-linux-gnu/6.4.0/plugin/include"

if [[ "$VARIANT" == "obfuscator" ]]; then
LLVM_REPO="https://github.com/obfuscator-llvm/obfuscator.git"
Expand All @@ -67,14 +70,17 @@ else
CPP_WRAPPER_DEFINE="-DCMAKE_CXX_COMPILER=/toolchain/x86/bin/x86_64-linux-g++"
PATCH_COMMAND="true"
COMPILE_CPP_WRAPPER="true"
CXX_FLAGS+=" -I/work/$VARIANT-llvm/tools/clang/include"
CXX_FLAGS+=" -I/work/build/tools/clang/include"
fi

CMAKE_COMMAND="\
cmake -G Ninja \
/work/$VARIANT-llvm \
-DCMAKE_INSTALL_PREFIX=/opt/llvm-$VARIANT \
-DLLVM_TARGETS_TO_BUILD=$ARCH \
-DCMAKE_CXX_FLAGS='-DENDIAN_LITTLE=1 -L/toolchain/x86/x86_64-buildroot-linux-gnu/sysroot/lib -L/toolchain/x86/x86_64-buildroot-linux-gnu/sysroot/usr/lib -I/toolchain/x86/lib/gcc/x86_64-buildroot-linux-gnu/6.4.0/plugin/include' \
-DCMAKE_CXX_FLAGS='-DENDIAN_LITTLE=1 $CXX_FLAGS' \
-DLLVM_CCACHE_BUILD=ON \
$CPP_WRAPPER_DEFINE \
-DCMAKE_C_COMPILER=/toolchain/x86/bin/x86_64-linux-gcc \
-DCMAKE_BUILD_TYPE=Release \
Expand All @@ -88,11 +94,14 @@ else
INTERACTIVE=()
fi

# -v $VARIANT-llvm-ccache:/work/ccache \

# shellcheck disable=SC2068
docker run ${INTERACTIVE[@]:-} --rm \
-v "$PWD/output/opt:/opt" \
-v "$PWD/patches:/patches" \
-v "$PWD:/this_dir" \
-v "$PWD/output/ccache:/work/ccache" \
-v $VARIANT-llvm:/work/$VARIANT-llvm \
-v $VARIANT-llvm-build:/work/build \
-e VARIANT=$VARIANT -e ARCH=$ARCH \
Expand All @@ -105,7 +114,8 @@ docker run ${INTERACTIVE[@]:-} --rm \
-e CLANG_TOOLS_EXTRA_REPO=$CLANG_TOOLS_EXTRA_REPO \
-e PATCH_COMMAND=$PATCH_COMMAND \
-e COMPILE_CPP_WRAPPER=$COMPILE_CPP_WRAPPER \
"$DOCKER_NAMETAG" \
-e CCACHE_DIR=/work/ccache \
"$DOCKER_NAMETAG-$VARIANT" \
/bin/bash -c "/this_dir/do_clang_build.bash"

./stage_sysroot.bash $NO_TTY "--variant=$VARIANT"
31 changes: 20 additions & 11 deletions do_clang_build.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/usr/bin/env bash

# Copyright (C) 2018 Swift Navigation Inc.
# Contact: Swift Navigation <[email protected]>
#
# This source is subject to the license found in the file 'LICENSE' which must
# be be distributed together with this source. All other rights reserved.
#
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

set -euo pipefail
IFS=$'\n\t'

Expand All @@ -9,14 +19,15 @@ die_non_empty()
die_not_defined()
{ echo "*** ERROR: variable $1 must be defined (can be empty)" >&2; exit 1; }

[[ -n "${VARIANT}" ]] || die_not_defined
[[ -n "${VARIANT:-}" ]] || die_non_empty

[[ "${VARIANT}" == "obfuscator" ]] || [[ "${VARIANT}" == "vanilla" ]] || \
{ echo "*** ERROR: invalid variant (must be one of 'vanilla', or 'obfuscator')" >&2; exit 1; }

[[ -n "${LLVM_REPO}" ]] || die_non_empty LLVM_REPO
[[ -n "${LLVM_BRANCH}" ]] || die_non_empty LLVM_BRANCH
[[ -n "${CMAKE_COMMAND}" ]] || die_non_empty CMAKE_COMMAND
[[ -n "${LLVM_REPO:-}" ]] || die_non_empty LLVM_REPO
[[ -n "${LLVM_BRANCH:-}" ]] || die_non_empty LLVM_BRANCH
[[ -n "${CMAKE_COMMAND:-}" ]] || die_non_empty CMAKE_COMMAND
[[ -n "${CCACHE_DIR:-}" ]] || die_non_empty CCACHE_DIR

[[ -n "${CLANG_REPO+x}" ]] || die_not_defined CLANG_REPO
[[ -n "${CLANG_TOOLS_EXTRA_REPO+x}" ]] || die_not_defined CLANG_TOOLS_EXTRA_REPO
Expand Down Expand Up @@ -49,6 +60,9 @@ if [ -n "${CLANG_TOOLS_EXTRA_REPO:-}" ]; then \
fi
fi

export CCACHE_DIR=$CCACHE_DIR
echo "CCACHE_DIR: $CCACHE_DIR"

eval "$COMPILE_CPP_WRAPPER"

cd "/work/$VARIANT-llvm"
Expand All @@ -58,10 +72,5 @@ cd /work/build

eval "$CMAKE_COMMAND"

if [[ -n "$VERBOSE" ]]; then
ninja -v
ninja -v install
else
ninja
ninja install
fi
eval ninja "$VERBOSE"
eval ninja "$VERBOSE" install
2 changes: 1 addition & 1 deletion docker_nametag
Original file line number Diff line number Diff line change
@@ -1 +1 @@
swiftnav/arm-llvm-obf:4.0-ubuntu1604-2018.06.08
swiftnav/arm-llvm-obf:2018.06.10
27 changes: 27 additions & 0 deletions push.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

# Copyright (C) 2017 Swift Navigation Inc.
# Contact: Swift Navigation <[email protected]>
#
# This source is subject to the license found in the file 'LICENSE' which must
# be be distributed together with this source. All other rights reserved.
#
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

set -euo pipefail
IFS=$'\n\t'

[[ -z "${DEBUG:-}" ]] || set -x

DOCKER_NAMETAG=$(cat docker_nametag)

if [[ -n "${DOCKER_USER:-}" ]] && [[ -n "${DOCKER_PASS:-}" ]]; then
echo "$DOCKER_PASS" | docker login --username="$DOCKER_USER" --password-stdin
docker push "$DOCKER_NAMETAG"
docker push "$DOCKER_NAMETAG-vanilla"
docker push "$DOCKER_NAMETAG-obfuscator"
else
echo "WARNING: not pushing new image to Docker Hub..." >&2
fi
2 changes: 1 addition & 1 deletion run_build_shell.bash
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ docker run -i -t --rm \
-v "$PWD:/this_dir" \
-v $VARIANT-llvm:/work/$VARIANT-llvm \
-v $VARIANT-llvm-build:/work/build \
"$DOCKER_NAMETAG" \
"$DOCKER_NAMETAG-$VARIANT" \
/bin/bash -c "export PATH=/opt/llvm-$VARIANT/bin:/opt/llvm-$VARIANT/wrappers/bin:\$PATH; \
cp -v /this_dir/cpp_wrapper.c /work/cpp_wrapper.c \
&& gcc -std=c99 -O3 -Wall /work/cpp_wrapper.c -o /bin/cpp_wrapper; \
Expand Down
2 changes: 1 addition & 1 deletion stage_sysroot.bash
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ run() {
-v $VARIANT-llvm-build:/work/build \
-e DOCKERCEPTION=1 \
-e "VARIANT=$VARIANT" \
"$DOCKER_NAMETAG" \
"$DOCKER_NAMETAG-$VARIANT" \
/bin/bash -c ". /this_dir/stage_sysroot.bash; stage_sysroot"
}

Expand Down

0 comments on commit 2fe5fd2

Please sign in to comment.