Skip to content

Commit f275d3d

Browse files
author
Brenden Blanco
committed
Add multiple build support styles
* 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]>
1 parent 439a9f3 commit f275d3d

15 files changed

+453
-32
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Dockerfile*
2+
build
3+
.*.swp

CMakeLists.txt

+17-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# Licensed under the Apache License, Version 2.0 (the "License")
33
cmake_minimum_required(VERSION 2.8.7)
44

5-
project(bpf-tools)
6-
set(CMAKE_BUILD_TYPE Debug)
5+
project(bcc)
6+
set(CMAKE_BUILD_TYPE Release)
77

88
enable_testing()
99

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

2222
# clang is linked as a library, but the library path searching is
2323
# primitively supported, unlike libLLVM
24-
set(CLANG_SEARCH "/opt/local/llvm/lib;${LLVM_LIBRARY_DIRS}")
24+
set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}")
2525
find_library(libclangAnalysis NAMES clangAnalysis HINTS ${CLANG_SEARCH})
2626
find_library(libclangAST NAMES clangAST HINTS ${CLANG_SEARCH})
2727
find_library(libclangBasic NAMES clangBasic HINTS ${CLANG_SEARCH})
@@ -48,3 +48,17 @@ endif()
4848
add_subdirectory(scripts)
4949
add_subdirectory(src)
5050
add_subdirectory(tests)
51+
52+
set(CPACK_PACKAGE_NAME "libbcc")
53+
set(CPACK_PACKAGE_VERSION "${REVISION}")
54+
set(CPACK_PACKAGE_CONTACT "Brenden Blanco <[email protected]")
55+
if(EXISTS "/etc/redhat-release")
56+
set(CPACK_GENERATOR "RPM")
57+
else()
58+
set(CPACK_GENERATOR "DEB")
59+
endif()
60+
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
61+
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
62+
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libstdc++6, python")
63+
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Shared Library for BPF Compiler Collection (BCC)")
64+
include(CPack)

Dockerfile.fedora

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# File to be used for building an Ubuntu .deb
2+
3+
FROM fedora
4+
5+
MAINTAINER Brenden Blanco <[email protected]>
6+
7+
RUN dnf -y install @rpm-development-tools @c-development @development-tools cmake libstdc++-static
8+
9+
WORKDIR /root
10+
RUN git clone https://github.com/llvm-mirror/llvm.git
11+
RUN git clone https://github.com/llvm-mirror/clang.git llvm/tools/clang
12+
RUN mkdir -p /root/llvm/build
13+
WORKDIR /root/llvm/build
14+
RUN cmake .. -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="ARM;CppBackend;X86;BPF"
15+
RUN make -j$(grep -c ^process /proc/cpuinfo)
16+
17+
RUN mkdir -p /root/bcc/build
18+
COPY ./ /root/bcc/
19+
WORKDIR /root/bcc/build
20+
RUN cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_PREFIX_PATH=/root/llvm/build
21+
RUN make -j$(grep -c ^process /proc/cpuinfo) package

Dockerfile.ubuntu

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# File to be used for building an Ubuntu .deb
2+
3+
FROM ubuntu:trusty
4+
5+
MAINTAINER Brenden Blanco <[email protected]>
6+
7+
RUN apt-get -y install wget
8+
RUN printf "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty main\ndeb-src http://llvm.org/apt/trusty/ llvm-toolchain-trusty main\n" > /etc/apt/sources.list.d/llvm.list
9+
RUN wget -q -O - http://llvm.org/apt/llvm-snapshot.gpg.key | apt-key add -
10+
RUN apt-get -y update
11+
12+
RUN apt-get -y install bison build-essential cmake flex git libedit-dev python zlib1g-dev
13+
RUN apt-get -y install libllvm3.7 llvm-3.7-dev libclang-3.7-dev
14+
15+
RUN mkdir -p /root/bcc/build
16+
COPY ./ /root/bcc/
17+
WORKDIR /root/bcc/build
18+
RUN cmake .. -DCMAKE_INSTALL_PREFIX=/usr
19+
RUN make -j$(grep -c ^process /proc/cpuinfo) package

scripts/CMakeLists.txt

+10-8
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ string(SUBSTRING "${GIT_SHA1}" 0 8 GIT_SHA1_SHORT)
55
git_describe(GIT_DESCRIPTION)
66
git_describe(GIT_TAG_LAST "--abbrev=0")
77
git_get_exact_tag(GIT_TAG_EXACT)
8-
string(SUBSTRING "${GIT_TAG_LAST}-${GIT_SHA1_SHORT}" 1 -1 REVISION)
9-
if(GIT_TAG_EXACT)
10-
string(SUBSTRING "${GIT_TAG_EXACT}" 1 -1 REVISION)
11-
message(STATUS "Currently on Git tag ${GIT_TAG_EXACT}")
12-
else ()
13-
message(STATUS "Latest recognized Git tag is ${GIT_TAG_LAST}")
14-
set(GIT_TAG_EXACT "")
8+
if(NOT REVISION)
9+
string(SUBSTRING "${GIT_TAG_LAST}-${GIT_SHA1_SHORT}" 1 -1 REVISION)
10+
if(GIT_TAG_EXACT)
11+
string(SUBSTRING "${GIT_TAG_EXACT}" 1 -1 REVISION)
12+
message(STATUS "Currently on Git tag ${GIT_TAG_EXACT}")
13+
else ()
14+
message(STATUS "Latest recognized Git tag is ${GIT_TAG_LAST}")
15+
set(GIT_TAG_EXACT "")
16+
endif()
17+
message(STATUS "Git HEAD is ${GIT_SHA1}")
1518
endif()
16-
message(STATUS "Git HEAD is ${GIT_SHA1}")
1719

1820
# strip leading 'v', and make unique for the tag
1921
message(STATUS "Revision is ${REVISION}")

scripts/bpf_demo.ks.erb

-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ numcpu=$(grep -c ^processor /proc/cpuinfo)
117117
git clone https://github.com/iovisor/bcc.git
118118
mkdir bcc/build/
119119
cd bcc/build/
120-
git checkout bblanco_dev
121120
export PATH=/opt/local/llvm/bin:$PATH
122121
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
123122
make -j$numcpu

src/cc/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
include_directories(${CMAKE_CURRENT_BINARY_DIR})
55
include_directories(${LLVM_INCLUDE_DIRS})
6+
# todo: if check for kernel version
7+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/compat)
68
add_definitions(${LLVM_DEFINITIONS})
79

810
BISON_TARGET(Parser parser.yy ${CMAKE_CURRENT_BINARY_DIR}/parser.yy.cc COMPILE_FLAGS "-o parser.yy.cc -v --debug")

src/cc/b_frontend_action.cc

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
#include <linux/bpf.h>
17+
#include <linux/version.h>
1718

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

0 commit comments

Comments
 (0)