Commit 2b83b671 authored by Dan Xu's avatar Dan Xu Committed by GitHub

Fix alpine docker build (#372)

This patch fixes the docker builds (`./build.sh` and
`./build-debug.sh`).

Two main things were broken:
* Alpine was missing a bcc-devel package. The temporary fix is to clone
  bcc, build, and install into the container
* Static linking against bcc was broken. I've made some cmake config
  changes to support this.
parent b7909547
......@@ -30,6 +30,8 @@ if (STATIC_LINKING)
set(CMAKE_LINK_SEARCH_END_STATIC TRUE)
endif()
set(FIND_LIBRARY_USE_LIB64_PATHS TRUE)
find_package(LibBcc REQUIRED)
include_directories(${LIBBCC_INCLUDE_DIRS})
......
......@@ -5,6 +5,8 @@
# LIBBCC_INCLUDE_DIRS - the libbcc include directory
# LIBBCC_LIBRARIES - Link these to use libbcc
# LIBBCC_DEFINITIONS - Compiler switches required for using libbcc
# LIBBPF_LIBRARY_STATIC - libbpf static library (for static compilation)
# LIBBCC_LOADER_LIBRARY_STATIC - libbcc helper static library (for static compilation)
if (LIBBCC_LIBRARIES AND LIBBCC_INCLUDE_DIRS)
set (LibBcc_FIND_QUIETLY TRUE)
......@@ -18,6 +20,7 @@ find_path (LIBBCC_INCLUDE_DIRS
/usr/include/bcc
/usr/local/include
/usr/local/include/libbcc
/usr/local/include/bcc
/opt/local/include
/opt/local/include/libbcc
/sw/include
......@@ -35,6 +38,28 @@ find_library (LIBBCC_LIBRARIES
ENV LIBRARY_PATH
ENV LD_LIBRARY_PATH)
find_library (LIBBPF_LIBRARY_STATIC
NAMES
bpf
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
ENV LIBRARY_PATH
ENV LD_LIBRARY_PATH)
find_library (LIBBCC_LOADER_LIBRARY_STATIC
NAMES
bcc-loader-static
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
ENV LIBRARY_PATH
ENV LD_LIBRARY_PATH)
include (FindPackageHandleStandardArgs)
......
......@@ -4,6 +4,7 @@ RUN apk add --update \
build-base \
clang-dev \
clang-static \
curl \
cmake \
elfutils-dev \
flex-dev \
......@@ -11,13 +12,28 @@ RUN apk add --update \
linux-headers \
llvm5-dev \
llvm5-static \
zlib-dev \
bcc-dev
python \
zlib-dev
# Put LLVM directories where CMake expects them to be
RUN ln -s /usr/lib/cmake/llvm5 /usr/lib/cmake/llvm
RUN ln -s /usr/include/llvm5/llvm /usr/include/llvm
RUN ln -s /usr/include/llvm5/llvm-c /usr/include/llvm-c
# Alpine currently does not have a package for bcc. Until they do,
# we'll peg the alpine build to bcc v0.8.0
#
# We're building here so docker can cache the build layer
WORKDIR /
RUN curl -L https://github.com/iovisor/bcc/archive/v0.8.0.tar.gz \
--output /bcc.tar.gz
RUN tar xvf /bcc.tar.gz
RUN mv bcc-0.8.0 bcc
RUN cd /bcc && mkdir build && cd build && cmake .. && make install -j4 && \
cp src/cc/libbcc.a /usr/local/lib64/libbcc.a && \
cp src/cc/libbcc-loader-static.a /usr/local/lib64/libbcc-loader-static.a && \
cp src/cc/libbpf.a /usr/local/lib64/libbpf.a
COPY build.sh /build.sh
ENTRYPOINT ["/bin/sh", "/build.sh"]
......@@ -5,6 +5,7 @@ set -e
STATIC_LINKING=${STATIC_LINKING:-OFF}
RUN_TESTS=${RUN_TESTS:-1}
# Build bpftrace
mkdir -p "$1"
cd "$1"
cmake -DCMAKE_BUILD_TYPE="$2" -DSTATIC_LINKING:BOOL=$STATIC_LINKING ../
......
......@@ -20,7 +20,13 @@ if(HAVE_NAME_TO_HANDLE_AT)
endif(HAVE_NAME_TO_HANDLE_AT)
target_link_libraries(bpftrace arch ast parser resources)
target_link_libraries(bpftrace ${LIBBCC_LIBRARIES})
if (STATIC_LINKING)
target_link_libraries(bpftrace ${LIBBCC_LIBRARIES})
target_link_libraries(bpftrace ${LIBBPF_LIBRARY_STATIC})
target_link_libraries(bpftrace ${LIBBCC_LOADER_LIBRARY_STATIC})
else()
target_link_libraries(bpftrace ${LIBBCC_LIBRARIES})
endif()
target_link_libraries(bpftrace ${LIBELF_LIBRARIES})
install(TARGETS bpftrace DESTINATION bin)
......@@ -38,4 +44,4 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE
)
add_definitions("-DBPFTRACE_VERSION=\"${BPFTRACE_VERSION}\"")
\ No newline at end of file
add_definitions("-DBPFTRACE_VERSION=\"${BPFTRACE_VERSION}\"")
......@@ -33,7 +33,13 @@ if(HAVE_NAME_TO_HANDLE_AT)
endif(HAVE_NAME_TO_HANDLE_AT)
target_link_libraries(bpftrace_test arch ast parser resources)
target_link_libraries(bpftrace_test ${LIBBCC_LIBRARIES})
if (STATIC_LINKING)
target_link_libraries(bpftrace_test ${LIBBCC_LIBRARIES})
target_link_libraries(bpftrace_test ${LIBBPF_LIBRARY_STATIC})
target_link_libraries(bpftrace_test ${LIBBCC_LOADER_LIBRARY_STATIC})
else()
target_link_libraries(bpftrace_test ${LIBBCC_LIBRARIES})
endif()
target_link_libraries(bpftrace_test ${LIBELF_LIBRARIES})
find_package(Threads REQUIRED)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment