Skip to content

Commit fa45261

Browse files
zasgarcopybaranaut
authored andcommittedApr 20, 2021
Remove bcc submodule
Summary: This moves BCC to be a git repo in bazel. Note: we need to use it as a git module because bcc has submodules. Test Plan: existing Reviewers: michelle, oazizi, vihang, #third_party_approvers Reviewed By: vihang, #third_party_approvers Differential Revision: https://phab.corp.pixielabs.ai/D8291 GitOrigin-RevId: c801745
1 parent da29506 commit fa45261

File tree

10 files changed

+94
-60
lines changed

10 files changed

+94
-60
lines changed
 

‎.gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "third_party/bcc"]
2-
path = third_party/bcc
3-
url = git@github.com:pixie-labs/bcc.git

‎BUILD.bazel

-8
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,6 @@ list_pl_deps(
196196
name = "pl_3p_deps",
197197
)
198198

199-
genrule(
200-
name = "pl_3p_submodules",
201-
srcs = [".gitmodules"],
202-
outs = ["pl_3p_submodules.out"],
203-
cmd = "git config --file $< --get-regexp url | cut -d' ' -f2 > $@",
204-
visibility = ["//visibility:public"],
205-
)
206-
207199
genrule(
208200
name = "pl_3p_go_sum",
209201
srcs = ["go.sum"],

‎bazel/external/bcc.BUILD

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2018- The Pixie Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
18+
19+
licenses(["notice"])
20+
21+
filegroup(
22+
name = "bcc_source",
23+
srcs = glob(["**/*"]),
24+
)
25+
26+
cmake(
27+
name = "bcc",
28+
generate_crosstool_file = True,
29+
lib_name = "libbcc_static",
30+
lib_source = ":bcc_source",
31+
# These link opts are dependencies of bcc.
32+
linkopts = [
33+
# ELF binary parsing.
34+
"-lelf",
35+
],
36+
make_commands = [
37+
"make -j$(nproc) -C src/cc install",
38+
],
39+
out_static_libs = [
40+
"libapi-static.a",
41+
"libbcc.a",
42+
"libbcc_bpf.a",
43+
"libbcc-loader-static.a",
44+
"libb_frontend.a",
45+
"libclang_frontend.a",
46+
"libusdt-static.a",
47+
],
48+
visibility = ["//visibility:public"],
49+
)

‎bazel/external/bpftrace.BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ cc_library(
9797
deps = [
9898
":bpftrace-parser",
9999
"@com_llvm_lib//:llvm",
100-
"@px//third_party/foreign_cc:bcc",
100+
"@com_github_iovisor_bcc//:bcc",
101101
],
102102
)
103103

@@ -123,7 +123,7 @@ cc_library(
123123
],
124124
tags = ["linux_only"],
125125
deps = [
126-
"@px//third_party/foreign_cc:bcc",
126+
"@com_github_iovisor_bcc//:bcc",
127127
],
128128
)
129129

‎bazel/repositories.bzl

+34-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
#
1515
# SPDX-License-Identifier: Apache-2.0
1616

17+
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
1718
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
18-
load(":repository_locations.bzl", "REPOSITORY_LOCATIONS")
19+
load(":repository_locations.bzl", "GIT_REPOSITORY_LOCATIONS", "REPOSITORY_LOCATIONS")
1920

2021
# Make all contents of an external repository accessible under a filegroup.
2122
# Used for external HTTP archives, e.g. cares.
@@ -43,6 +44,30 @@ def _repo_impl(name, **kwargs):
4344
**kwargs
4445
)
4546

47+
def _git_repo_impl(name, **kwargs):
48+
# `existing_rule_keys` contains the names of repositories that have already
49+
# been defined in the Bazel workspace. By skipping repos with existing keys,
50+
# users can override dependency versions by using standard Bazel repository
51+
# rules in their WORKSPACE files.
52+
existing_rule_keys = native.existing_rules().keys()
53+
if name in existing_rule_keys:
54+
# This repository has already been defined, probably because the user
55+
# wants to override the version. Do nothing.
56+
return
57+
58+
location = GIT_REPOSITORY_LOCATIONS[name]
59+
60+
# HTTP tarball at a given URL. Add a BUILD file if requested.
61+
new_git_repository(
62+
name = name,
63+
remote = location["remote"],
64+
commit = location["commit"],
65+
init_submodules = True,
66+
recursive_init_submodules = True,
67+
shallow_since = location.get("shallow_since", ""),
68+
**kwargs
69+
)
70+
4671
# For bazel repos do not require customization.
4772
def _bazel_repo(name, **kwargs):
4873
_repo_impl(name, **kwargs)
@@ -83,6 +108,8 @@ def _cc_deps():
83108
_include_all_repo("com_github_libuv_libuv", patches = ["//bazel/external:libuv.patch"], patch_args = ["-p1"])
84109
_include_all_repo("com_github_libarchive_libarchive")
85110

111+
_git_repo_impl("com_github_iovisor_bcc", build_file = "//bazel/external:bcc.BUILD")
112+
86113
_repo_impl("com_github_apache_arrow", build_file = "//bazel/external:arrow.BUILD")
87114
_repo_impl("com_github_ariafallah_csv_parser", build_file = "//bazel/external:csv_parser.BUILD")
88115
_repo_impl("com_github_arun11299_cpp_jwt", build_file = "//bazel/external:cpp_jwt.BUILD")
@@ -119,6 +146,12 @@ def list_pl_deps(name):
119146
best_url = url
120147
repo_urls.append(best_url)
121148

149+
for repo_name, repo_config in GIT_REPOSITORY_LOCATIONS.items():
150+
remote = repo_config["remote"]
151+
if remote.endswith(".git"):
152+
remote = remote[:-len(".git")]
153+
repo_urls.append(remote)
154+
122155
native.genrule(
123156
name = name,
124157
outs = ["{}.out".format(name)],

‎bazel/repository_locations.bzl

+8
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,11 @@ REPOSITORY_LOCATIONS = dict(
270270
urls = ["https://github.com/pixie-labs/bpftrace/archive/da17ebda1090b5e09dc89d69a3afdb580d486670.tar.gz"],
271271
),
272272
)
273+
274+
GIT_REPOSITORY_LOCATIONS = dict(
275+
com_github_iovisor_bcc = dict(
276+
remote = "https://github.com/pixie-labs/bcc.git",
277+
commit = "c50098cadc54a602a7e423ae958dca8562ee2cf9",
278+
shallow_since = "1618606641 -0700",
279+
),
280+
)

‎src/stirling/bpf_tools/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pl_cc_library(
4040
"//src/stirling/bpf_tools/bcc_bpf:task_struct_mem_read",
4141
] + select({
4242
"@bazel_tools//src/conditions:linux_x86_64": [
43-
"//third_party/foreign_cc:bcc",
43+
"@com_github_iovisor_bcc//:bcc",
4444
"@com_github_iovisor_bpftrace//:bpftrace",
4545
"//:llvm",
4646
],

‎third_party/BUILD.bazel

-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ load("@rules_cc//cc:defs.bzl", "cc_library")
1818

1919
licenses(["notice"])
2020

21-
filegroup(
22-
name = "bcc_source",
23-
srcs = glob(["bcc/**"]),
24-
visibility = ["//visibility:public"],
25-
)
26-
2721
cc_library(
2822
name = "clang_tidy_stub",
2923
srcs = ["clang_tidy_stub.cc"],

‎third_party/foreign_cc/BUILD.bazel

-23
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,3 @@ cmake(
9696
lib_name = "libarchive",
9797
lib_source = "@com_github_libarchive_libarchive//:all",
9898
)
99-
cmake(
100-
name = "bcc",
101-
generate_crosstool_file = True,
102-
lib_name = "libbcc_static",
103-
lib_source = "//third_party:bcc_source",
104-
# These link opts are dependencies of bcc.
105-
linkopts = [
106-
# ELF binary parsing.
107-
"-lelf",
108-
],
109-
make_commands = [
110-
"make -j$(nproc) -C src/cc install",
111-
],
112-
out_static_libs = [
113-
"libapi-static.a",
114-
"libbcc.a",
115-
"libbcc_bpf.a",
116-
"libbcc-loader-static.a",
117-
"libb_frontend.a",
118-
"libclang_frontend.a",
119-
"libusdt-static.a",
120-
],
121-
)

‎tools/licenses/BUILD.bazel

-16
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,6 @@ fetch_licenses(
6262
use_pkg_dev_go = True,
6363
)
6464

65-
fetch_licenses(
66-
name = "submodule_licenses",
67-
src = "//:pl_3p_submodules",
68-
disallow_missing = select({
69-
"//bazel:stamped": True,
70-
"//conditions:default": False,
71-
}),
72-
fetch_tool = ":fetch_licenses",
73-
manual_licenses = "manual_licenses.json",
74-
oauth_token = credential,
75-
out_found = "submodule_licenses.json",
76-
out_missing = "submodule_licenses_missing.json",
77-
)
78-
7965
fetch_licenses(
8066
name = "deps_licenses",
8167
src = "//:pl_3p_deps",
@@ -94,7 +80,6 @@ genrule(
9480
name = "all_licenses",
9581
srcs = [
9682
"go_licenses.json",
97-
"submodule_licenses.json",
9883
"deps_licenses.json",
9984
"//src/ui:npm_licenses",
10085
],
@@ -104,7 +89,6 @@ genrule(
10489
cmd = """
10590
python3 $(location combine_licenses.py) \
10691
$(location go_licenses.json) \
107-
$(location submodule_licenses.json) \
10892
$(location deps_licenses.json) \
10993
$(location //src/ui:npm_licenses) \
11094
--output $(location all_licenses.json)

0 commit comments

Comments
 (0)
Please sign in to comment.