Skip to content

Commit

Permalink
Convert bpftrace from a submodule into a bazel_repo
Browse files Browse the repository at this point in the history
Summary: TSIA

Test Plan: Build and test all

Reviewers: zasgar, #third_party_approvers, oazizi

Reviewed By: zasgar, #third_party_approvers

Differential Revision: https://phab.corp.pixielabs.ai/D8292

GitOrigin-RevId: a262807
  • Loading branch information
vihangm authored and copybaranaut committed Apr 20, 2021
1 parent 5901fc8 commit da29506
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 196 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "third_party/bcc"]
path = third_party/bcc
url = [email protected]:pixie-labs/bcc.git
[submodule "third_party/bpftrace"]
path = third_party/bpftrace
url = [email protected]:pixie-labs/bpftrace.git
149 changes: 149 additions & 0 deletions bazel/external/bpftrace.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Copyright 2018- The Pixie Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

load("@px//bazel:flex_bison.bzl", "genbison", "genflex")
load("@rules_cc//cc:defs.bzl", "cc_library")

licenses(["notice"])

# When building bpftrace, it automatically generates the following file:
# <build_dir>/resources/headers.cpp
# Due to build issues, this file was copied directly into src, and checked in to our fork of bpftrace.
# If at any time, bpftrace is updated from the origin, AND there are changes to the resources directory,
# then the updated headers.cpp should be copied and checked in to src.
# If there are no changes to files in the resources directory (which is the likely case), then no special steps are required.
cc_library(
name = "bpftrace",
srcs = glob(
["src/*.cpp"],
exclude = [
"src/main.cpp",
"src/bfd-disasm.cpp",
],
) + glob(
[
"src/*.h",
"src/arch/*.h",
"src/ast/*.h",
],
),
hdrs = glob([
"src/*.h",
"src/arch/*.h",
"src/ast/*.h",
]),
copts = [
"-w",
],
defines = [
"HAVE_NAME_TO_HANDLE_AT=1",
"HAVE_BCC_PROG_LOAD=1",
"HAVE_BCC_CREATE_MAP=1",
"HAVE_BCC_ELF_FOREACH_SYM=1",
"HAVE_BCC_KFUNC=1",
"HAVE_BCC_USDT_ADDSEM=1",
"LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE=1",
],
include_prefix = "bpftrace",
tags = ["linux_only"],
visibility = ["//visibility:public"],
deps = [
":bpftrace-arch",
":bpftrace-ast",
],
)

cc_library(
name = "bpftrace-arch",
srcs = [
"src/arch/x86_64.cpp",
],
hdrs = glob([
"src/arch/*.h",
]),
copts = [
"-w",
],
visibility = ["//visibility:private"],
)

cc_library(
name = "bpftrace-ast",
srcs = glob([
"src/ast/*.cpp",
]),
hdrs = glob([
"src/ast/*.h",
"src/arch/*.h",
]),
copts = [
"-w",
],
tags = ["linux_only"],
visibility = ["//visibility:private"],
deps = [
":bpftrace-parser",
"@com_llvm_lib//:llvm",
"@px//third_party/foreign_cc:bcc",
],
)

cc_library(
name = "bpftrace-parser",
srcs = [
":bpftrace-bison",
":bpftrace-flex",
],
hdrs = glob([
"src/*.h",
"src/libbpf/*.h",
"src/ast/*.h",
]) + [
":bpftrace-bison",
],
copts = [
"-w",
],
includes = [
"src",
"src/ast",
],
tags = ["linux_only"],
deps = [
"@px//third_party/foreign_cc:bcc",
],
)

genbison(
name = "bpftrace-bison",
src = "src/parser.yy",
extra_outs = [
"stack.hh",
"location.hh",
"position.hh",
],
header_out = "parser.tab.hh",
source_out = "parser.tab.cc",
tags = ["linux_only"],
)

genflex(
name = "bpftrace-flex",
src = "src/lexer.l",
out = "lex.yy.cc",
includes = [":bpftrace-bison"],
tags = ["linux_only"],
)
1 change: 1 addition & 0 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def _cc_deps():
_repo_impl("com_github_cameron314_concurrentqueue", build_file = "//bazel/external:concurrentqueue.BUILD")
_repo_impl("com_github_cmcqueen_aes_min", patches = ["//bazel/external:aes_min.patch"], patch_args = ["-p1"], build_file = "//bazel/external:aes_min.BUILD")
_repo_impl("com_github_cyan4973_xxhash", build_file = "//bazel/external:xxhash.BUILD")
_repo_impl("com_github_iovisor_bpftrace", build_file = "//bazel/external:bpftrace.BUILD")
_repo_impl("com_github_nlohmann_json", build_file = "//bazel/external:nlohmann_json.BUILD")
_repo_impl("com_github_packetzero_dnsparser", build_file = "//bazel/external:dnsparser.BUILD")
_repo_impl("com_github_rlyeh_sole", build_file = "//bazel/external:sole.BUILD")
Expand Down
5 changes: 5 additions & 0 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,9 @@ REPOSITORY_LOCATIONS = dict(
strip_prefix = "threadstacks-94adbe26c4aaf9ca945fd7936670d40ec6f228fb",
urls = ["https://github.com/pixie-labs/threadstacks/archive/94adbe26c4aaf9ca945fd7936670d40ec6f228fb.tar.gz"],
),
com_github_iovisor_bpftrace = dict(
sha256 = "8bd665c0ab7cc79794d4cd7a1c5553e8bd25b65215bb7b4b7c4f905067cf63ee",
strip_prefix = "bpftrace-da17ebda1090b5e09dc89d69a3afdb580d486670",
urls = ["https://github.com/pixie-labs/bpftrace/archive/da17ebda1090b5e09dc89d69a3afdb580d486670.tar.gz"],
),
)
2 changes: 1 addition & 1 deletion src/stirling/bpf_tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pl_cc_library(
] + select({
"@bazel_tools//src/conditions:linux_x86_64": [
"//third_party/foreign_cc:bcc",
"//third_party:bpftrace",
"@com_github_iovisor_bpftrace//:bpftrace",
"//:llvm",
],
"//conditions:default": [],
Expand Down
17 changes: 8 additions & 9 deletions src/stirling/bpf_tools/bpftrace_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@

#include "src/stirling/bpf_tools/bpftrace_wrapper.h"

#include <bpftrace/src/ast/codegen_llvm.h>
#include <bpftrace/src/ast/printer.h>
#include <bpftrace/src/ast/semantic_analyser.h>
#include <bpftrace/src/clang_parser.h>
#include <bpftrace/src/driver.h>
#include <bpftrace/src/procmon.h>
#include <bpftrace/src/tracepoint_format_parser.h>

#include <sstream>

#include "src/common/base/base.h"
#include "src/common/system/config.h"

#include "third_party/bpftrace/src/ast/codegen_llvm.h"
#include "third_party/bpftrace/src/ast/printer.h"
#include "third_party/bpftrace/src/ast/semantic_analyser.h"
#include "third_party/bpftrace/src/clang_parser.h"
#include "third_party/bpftrace/src/driver.h"
#include "third_party/bpftrace/src/procmon.h"
#include "third_party/bpftrace/src/tracepoint_format_parser.h"

#include "src/stirling/utils/linux_headers.h"

namespace px {
Expand Down
8 changes: 4 additions & 4 deletions src/stirling/bpf_tools/bpftrace_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@

#ifdef __linux__

#include <bpftrace/src/bpforc.h>
#include <bpftrace/src/bpftrace.h>
#include <bpftrace/src/driver.h>

#include <memory>
#include <string>
#include <vector>

#include "src/common/base/base.h"

#include "third_party/bpftrace/src/bpforc.h"
#include "third_party/bpftrace/src/bpftrace.h"
#include "third_party/bpftrace/src/driver.h"

namespace px {
namespace stirling {
namespace bpf_tools {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@

#include "src/stirling/source_connectors/dynamic_bpftrace/dynamic_bpftrace_connector.h"

#include <bpftrace/src/ast/async_event_types.h>

#include <utility>
#include <vector>

#include <absl/memory/memory.h>
#include <absl/strings/ascii.h>

#include "src/shared/types/typespb/wrapper/types_pb_wrapper.h"
#include "third_party/bpftrace/src/ast/async_event_types.h"

namespace px {
namespace stirling {
Expand Down
127 changes: 0 additions & 127 deletions third_party/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# SPDX-License-Identifier: Apache-2.0

load("@rules_cc//cc:defs.bzl", "cc_library")
load("//bazel:flex_bison.bzl", "genbison", "genflex")

licenses(["notice"])

Expand All @@ -30,129 +29,3 @@ cc_library(
srcs = ["clang_tidy_stub.cc"],
visibility = ["//visibility:public"],
)

# See README.md for special instructions on re-building bpftrace.
cc_library(
name = "bpftrace",
srcs = glob(
["bpftrace/src/*.cpp"],
exclude = [
"bpftrace/src/main.cpp",
"bpftrace/src/bfd-disasm.cpp",
],
),
hdrs = glob([
"bpftrace/src/*.h",
]),
copts = [
"-w",
"-Ithird_party/bpftrace/src/arch",
"-Ithird_party/bpftrace/src/ast",
"-Ithird_party/bpftrace/src",
],
defines = [
"HAVE_NAME_TO_HANDLE_AT=1",
"HAVE_BCC_PROG_LOAD=1",
"HAVE_BCC_CREATE_MAP=1",
"HAVE_BCC_ELF_FOREACH_SYM=1",
"HAVE_BCC_KFUNC=1",
"HAVE_BCC_USDT_ADDSEM=1",
"LIBBCC_ATTACH_KPROBE_SIX_ARGS_SIGNATURE=1",
],
includes = [
"bpftrace/src",
"bpftrace/src/arch",
"bpftrace/src/ast",
],
tags = ["linux_only"],
visibility = ["//visibility:public"],
deps = [
":bpftrace-arch",
":bpftrace-ast",
],
)

cc_library(
name = "bpftrace-arch",
srcs = [
"bpftrace/src/arch/x86_64.cpp",
],
hdrs = glob([
"bpftrace/src/arch/*.h",
]),
copts = [
"-w",
],
visibility = ["//visibility:private"],
)

cc_library(
name = "bpftrace-ast",
srcs = glob([
"bpftrace/src/ast/*.cpp",
]),
hdrs = glob([
"bpftrace/src/*.h",
"bpftrace/src/ast/*.h",
"bpftrace/src/arch/*.h",
]),
copts = [
"-w",
"-Ithird_party/bpftrace/src/ast",
"-Ithird_party/bpftrace/src",
],
tags = ["linux_only"],
visibility = ["//visibility:private"],
deps = [
":bpftrace-parser",
"//third_party/foreign_cc:bcc",
"@com_llvm_lib//:llvm",
],
)

cc_library(
name = "bpftrace-parser",
srcs = [
":bpftrace-bison",
":bpftrace-flex",
],
hdrs = glob([
"bpftrace/src/*.h",
"bpftrace/src/libbpf/*.h",
"bpftrace/src/ast/*.h",
":bpftrace-bison",
]),
copts = [
"-w",
"-Ithird_party/bpftrace/src",
"-Ithird_party/bpftrace/src/ast",
"-I.",
],
#Hacky, but otherwise can't find parser.tab.hh.
includes = ["."],
tags = ["linux_only"],
deps = [
"//third_party/foreign_cc:bcc",
],
)

genbison(
name = "bpftrace-bison",
src = "bpftrace/src/parser.yy",
extra_outs = [
"stack.hh",
"location.hh",
"position.hh",
],
header_out = "parser.tab.hh",
source_out = "parser.tab.cc",
tags = ["linux_only"],
)

genflex(
name = "bpftrace-flex",
src = "bpftrace/src/lexer.l",
out = "lex.yy.cc",
includes = [":bpftrace-bison"],
tags = ["linux_only"],
)
Loading

0 comments on commit da29506

Please sign in to comment.