From 3cfaf59597338ff6f91b98113756c472adebeafe Mon Sep 17 00:00:00 2001 From: James Bartlett Date: Fri, 6 Jan 2023 13:32:26 -0800 Subject: [PATCH] Use correct llvm libs for cmake build of bcc and bpftrace. Summary: Previously, bcc/bpftrace were building using the libs in /opt/clang-15.0. This diff makes them use the downloaded libs instead. Test Plan: Checked the cmake logs to make sure its no longer using /opt/clang-15.0. #ci:bpf-build Reviewers: zasgar, vihang, #third_party_approvers Reviewed By: zasgar, #third_party_approvers Signed-off-by: James Bartlett Differential Revision: https://phab.corp.pixielabs.ai/D12729 GitOrigin-RevId: b6f2a70e74009fb5669ee163c2e33c5f826ff609 --- bazel/external/bcc.BUILD | 12 ++++++++---- bazel/external/bpftrace.BUILD | 10 +++++----- bazel/external/llvm.BUILD | 6 ++++++ bazel/llvm_cmake.bzl | 33 +++++++++++++++++++++++++++++++++ bazel/repository_locations.bzl | 8 ++++---- 5 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 bazel/llvm_cmake.bzl diff --git a/bazel/external/bcc.BUILD b/bazel/external/bcc.BUILD index f7797a66201..2105f5064b6 100644 --- a/bazel/external/bcc.BUILD +++ b/bazel/external/bcc.BUILD @@ -14,6 +14,7 @@ # # SPDX-License-Identifier: Apache-2.0 +load("@px//bazel:llvm_cmake.bzl", "add_llvm_cache_entries", "llvm_build_data_deps") load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") licenses(["notice"]) @@ -30,15 +31,15 @@ cmake( "-j`nproc`", "-l`nproc`", ], - cache_entries = { + build_data = llvm_build_data_deps(), + cache_entries = add_llvm_cache_entries({ "CMAKE_USE_LIBBPF_PACKAGE": "ON", "ENABLE_EXAMPLES": "OFF", "ENABLE_MAN": "OFF", "ENABLE_TESTS": "OFF", "LIBBPF_INCLUDE_DIR": "$EXT_BUILD_DEPS/libbpf/include", "LIBBPF_LIBRARIES": "$EXT_BUILD_DEPS/libbpf/lib64/libbpf.a", - "LLVM_ROOT": "/opt/clang-15.0", - }, + }), includes = [ "bcc/compat", ], @@ -65,5 +66,8 @@ cmake( "clang_frontend", ], visibility = ["//visibility:public"], - deps = ["@com_github_libbpf_libbpf//:libbpf"], + deps = [ + "@com_github_libbpf_libbpf//:libbpf", + "@px//:llvm", + ], ) diff --git a/bazel/external/bpftrace.BUILD b/bazel/external/bpftrace.BUILD index 66b99e6a9aa..2a6fd6aad8f 100644 --- a/bazel/external/bpftrace.BUILD +++ b/bazel/external/bpftrace.BUILD @@ -14,6 +14,7 @@ # # SPDX-License-Identifier: Apache-2.0 +load("@px//bazel:llvm_cmake.bzl", "add_llvm_cache_entries", "llvm_build_data_deps") load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") licenses(["notice"]) @@ -30,7 +31,8 @@ cmake( "-j`nproc`", "-l`nproc`", ], - cache_entries = { + build_data = llvm_build_data_deps(), + cache_entries = add_llvm_cache_entries({ "BUILD_FUZZ": "OFF", "BUILD_TESTING": "OFF", @@ -53,9 +55,7 @@ cmake( "LIBBPF_INCLUDE_DIRS": "$EXT_BUILD_DEPS/libbpf/include", "LIBBPF_LIBRARIES": "$EXT_BUILD_DEPS/libbpf/lib64/libbpf.a", "LIBCEREAL_INCLUDE_DIRS": "$EXT_BUILD_DEPS/include", - "LLVM_REQUESTED_VERSION": "15.0.6", - "LLVM_ROOT": "/opt/clang-15.0", - }, + }), lib_source = ":bpftrace_source", linkopts = [ "-lelf", @@ -78,6 +78,6 @@ cmake( "@com_github_USCiLab_cereal//:cereal", "@com_github_iovisor_bcc//:bcc", "@com_github_libbpf_libbpf//:libbpf", - "@com_llvm_lib//:llvm", + "@px//:llvm", ], ) diff --git a/bazel/external/llvm.BUILD b/bazel/external/llvm.BUILD index 2059c50c7d0..29426714b05 100644 --- a/bazel/external/llvm.BUILD +++ b/bazel/external/llvm.BUILD @@ -132,3 +132,9 @@ cc_library( visibility = ["//visibility:public"], alwayslink = 1, ) + +filegroup( + name = "cmake", + srcs = glob(["lib/cmake/llvm/**"]), + visibility = ["//visibility:public"], +) diff --git a/bazel/llvm_cmake.bzl b/bazel/llvm_cmake.bzl new file mode 100644 index 00000000000..c71c89e522b --- /dev/null +++ b/bazel/llvm_cmake.bzl @@ -0,0 +1,33 @@ +# 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 + +def add_llvm_cache_entries(cache_entries): + return select({ + "@px//bazel:use_libcpp": dict( + cache_entries, + LLVM_ROOT = "$EXT_BUILD_ROOT/external/com_llvm_lib_libcpp", + ), + "//conditions:default": dict( + cache_entries, + LLVM_ROOT = "$EXT_BUILD_ROOT/external/com_llvm_lib", + ), + }) + +def llvm_build_data_deps(): + return select({ + "@px//bazel:use_libcpp": ["@com_llvm_lib_libcpp//:cmake"], + "//conditions:default": ["@com_llvm_lib//:cmake"], + }) diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 055b10a627c..a57d579464b 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -290,14 +290,14 @@ REPOSITORY_LOCATIONS = dict( urls = ["https://github.com/oneapi-src/oneTBB/archive/e6104c9599f7f10473caf545199f7468c0a8e52f.tar.gz"], ), com_llvm_lib = dict( - sha256 = "af503fd8660bbd29455588d1fa87ad8cc0cd2bf6e4f3c59c8d738c2f934c8140", + sha256 = "e2cdc560be2469f376558164ce51d75669e4ff0585712f04face168fa597740f", strip_prefix = "", - urls = ["https://storage.googleapis.com/pixie-dev-public/clang/15.0-pl3/llvm-15.0-pl3.tar.gz"], + urls = ["https://storage.googleapis.com/pixie-dev-public/clang/15.0-pl5/llvm-15.0-pl5.tar.gz"], ), com_llvm_lib_libcpp = dict( - sha256 = "4d904ae1df7e0ba8546cf901509034da2a129805ef0720cb10b6a8a41ae44a29", + sha256 = "1bd0b9d41a2cbc34d9abc64b1017cf08a956200bb41c14b6fe3e1ddb29d1ca6b", strip_prefix = "", - urls = ["https://storage.googleapis.com/pixie-dev-public/clang/15.0-pl3/llvm-15.0-pl3-libcxx.tar.gz"], + urls = ["https://storage.googleapis.com/pixie-dev-public/clang/15.0-pl5/llvm-15.0-pl5-libcxx.tar.gz"], ), com_oracle_openjdk_18 = dict( sha256 = "3bfdb59fc38884672677cebca9a216902d87fe867563182ae8bc3373a65a2ebd",