Skip to content

Commit

Permalink
Add multiple build support styles
Browse files Browse the repository at this point in the history
* Add RPM and DEB packaging targets (using CPack from CMake) to build
  binary packages for Fedora and Ubuntu targets.
* Add Docker build scripts for each of the above that run the build in
  the right environment (assuming docker is available).
 - In Ubuntu, build against the LLVM 3.7 nightly snapshots
 - In Fedora, build against LLVM 3.7 from git (takes longer)
* Depending on packages installed on the build machine, it may be
  possible to cross-package for other targets without invoking Docker.
* Re-introduce src/cc/compat directory to keep the build stable for the
  time being. Similarly, it was necessary to #define some ugly constants
  that should eventually show up in libc.
* Add a few simple version checks to allow a partially working (really
  tracing only) libbcc in 4.1 kernels.

TODO (followup commit): Re-work the READMEs

Signed-off-by: Brenden Blanco <[email protected]>
  • Loading branch information
Brenden Blanco committed Jul 7, 2015
1 parent 439a9f3 commit f275d3d
Show file tree
Hide file tree
Showing 15 changed files with 453 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dockerfile*
build
.*.swp
20 changes: 17 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Licensed under the Apache License, Version 2.0 (the "License")
cmake_minimum_required(VERSION 2.8.7)

project(bpf-tools)
set(CMAKE_BUILD_TYPE Debug)
project(bcc)
set(CMAKE_BUILD_TYPE Release)

enable_testing()

Expand All @@ -21,7 +21,7 @@ message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS}")

# clang is linked as a library, but the library path searching is
# primitively supported, unlike libLLVM
set(CLANG_SEARCH "/opt/local/llvm/lib;${LLVM_LIBRARY_DIRS}")
set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}")
find_library(libclangAnalysis NAMES clangAnalysis HINTS ${CLANG_SEARCH})
find_library(libclangAST NAMES clangAST HINTS ${CLANG_SEARCH})
find_library(libclangBasic NAMES clangBasic HINTS ${CLANG_SEARCH})
Expand All @@ -48,3 +48,17 @@ endif()
add_subdirectory(scripts)
add_subdirectory(src)
add_subdirectory(tests)

set(CPACK_PACKAGE_NAME "libbcc")
set(CPACK_PACKAGE_VERSION "${REVISION}")
set(CPACK_PACKAGE_CONTACT "Brenden Blanco <[email protected]")
if(EXISTS "/etc/redhat-release")
set(CPACK_GENERATOR "RPM")
else()
set(CPACK_GENERATOR "DEB")
endif()
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libstdc++6, python")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Shared Library for BPF Compiler Collection (BCC)")
include(CPack)
21 changes: 21 additions & 0 deletions Dockerfile.fedora
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# File to be used for building an Ubuntu .deb

FROM fedora

MAINTAINER Brenden Blanco <[email protected]>

RUN dnf -y install @rpm-development-tools @c-development @development-tools cmake libstdc++-static

WORKDIR /root
RUN git clone https://github.com/llvm-mirror/llvm.git
RUN git clone https://github.com/llvm-mirror/clang.git llvm/tools/clang
RUN mkdir -p /root/llvm/build
WORKDIR /root/llvm/build
RUN cmake .. -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="ARM;CppBackend;X86;BPF"
RUN make -j$(grep -c ^process /proc/cpuinfo)

RUN mkdir -p /root/bcc/build
COPY ./ /root/bcc/
WORKDIR /root/bcc/build
RUN cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_PREFIX_PATH=/root/llvm/build
RUN make -j$(grep -c ^process /proc/cpuinfo) package
19 changes: 19 additions & 0 deletions Dockerfile.ubuntu
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# File to be used for building an Ubuntu .deb

FROM ubuntu:trusty

MAINTAINER Brenden Blanco <[email protected]>

RUN apt-get -y install wget
RUN printf "deb http:https://llvm.org/apt/trusty/ llvm-toolchain-trusty main\ndeb-src http:https://llvm.org/apt/trusty/ llvm-toolchain-trusty main\n" > /etc/apt/sources.list.d/llvm.list
RUN wget -q -O - http:https://llvm.org/apt/llvm-snapshot.gpg.key | apt-key add -
RUN apt-get -y update

RUN apt-get -y install bison build-essential cmake flex git libedit-dev python zlib1g-dev
RUN apt-get -y install libllvm3.7 llvm-3.7-dev libclang-3.7-dev

RUN mkdir -p /root/bcc/build
COPY ./ /root/bcc/
WORKDIR /root/bcc/build
RUN cmake .. -DCMAKE_INSTALL_PREFIX=/usr
RUN make -j$(grep -c ^process /proc/cpuinfo) package
18 changes: 10 additions & 8 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ string(SUBSTRING "${GIT_SHA1}" 0 8 GIT_SHA1_SHORT)
git_describe(GIT_DESCRIPTION)
git_describe(GIT_TAG_LAST "--abbrev=0")
git_get_exact_tag(GIT_TAG_EXACT)
string(SUBSTRING "${GIT_TAG_LAST}-${GIT_SHA1_SHORT}" 1 -1 REVISION)
if(GIT_TAG_EXACT)
string(SUBSTRING "${GIT_TAG_EXACT}" 1 -1 REVISION)
message(STATUS "Currently on Git tag ${GIT_TAG_EXACT}")
else ()
message(STATUS "Latest recognized Git tag is ${GIT_TAG_LAST}")
set(GIT_TAG_EXACT "")
if(NOT REVISION)
string(SUBSTRING "${GIT_TAG_LAST}-${GIT_SHA1_SHORT}" 1 -1 REVISION)
if(GIT_TAG_EXACT)
string(SUBSTRING "${GIT_TAG_EXACT}" 1 -1 REVISION)
message(STATUS "Currently on Git tag ${GIT_TAG_EXACT}")
else ()
message(STATUS "Latest recognized Git tag is ${GIT_TAG_LAST}")
set(GIT_TAG_EXACT "")
endif()
message(STATUS "Git HEAD is ${GIT_SHA1}")
endif()
message(STATUS "Git HEAD is ${GIT_SHA1}")

# strip leading 'v', and make unique for the tag
message(STATUS "Revision is ${REVISION}")
Expand Down
1 change: 0 additions & 1 deletion scripts/bpf_demo.ks.erb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ numcpu=$(grep -c ^processor /proc/cpuinfo)
git clone https://github.com/iovisor/bcc.git
mkdir bcc/build/
cd bcc/build/
git checkout bblanco_dev
export PATH=/opt/local/llvm/bin:$PATH
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
make -j$numcpu
Expand Down
2 changes: 2 additions & 0 deletions src/cc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${LLVM_INCLUDE_DIRS})
# todo: if check for kernel version
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/compat)
add_definitions(${LLVM_DEFINITIONS})

BISON_TARGET(Parser parser.yy ${CMAKE_CURRENT_BINARY_DIR}/parser.yy.cc COMPILE_FLAGS "-o parser.yy.cc -v --debug")
Expand Down
3 changes: 3 additions & 0 deletions src/cc/b_frontend_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <linux/bpf.h>
#include <linux/version.h>

#include <clang/AST/ASTConsumer.h>
#include <clang/AST/ASTContext.h>
Expand Down Expand Up @@ -373,8 +374,10 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) {
map_type = BPF_MAP_TYPE_HASH;
else if (A->getName() == "maps/array")
map_type = BPF_MAP_TYPE_ARRAY;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)
else if (A->getName() == "maps/prog")
map_type = BPF_MAP_TYPE_PROG_ARRAY;
#endif
table.fd = bpf_create_map(map_type, table.key_size, table.leaf_size, table.max_entries);
if (table.fd < 0) {
llvm::errs() << "error: could not open bpf fd\n";
Expand Down
Loading

0 comments on commit f275d3d

Please sign in to comment.