|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +class Bpftime < Formula |
| 4 | + desc "Userspace eBPF runtime and tooling" |
| 5 | + homepage "https://github.com/eunomia-bpf/bpftime" |
| 6 | + url "https://github.com/eunomia-bpf/bpftime.git", |
| 7 | + tag: "v0.2.0", |
| 8 | + revision: "20acd8835241805b08bf256d0cf8963fd1cfbcac" |
| 9 | + license "MIT" |
| 10 | + head "https://github.com/eunomia-bpf/bpftime.git", branch: "master" |
| 11 | + |
| 12 | + depends_on "cmake" => :build |
| 13 | + depends_on "pkgconf" => :build |
| 14 | + depends_on "boost" |
| 15 | + depends_on "ncurses" |
| 16 | + |
| 17 | + resource "frida-core-devkit" do |
| 18 | + url "https://github.com/frida/frida/releases/download/16.1.2/frida-core-devkit-16.1.2-macos-arm64.tar.xz" |
| 19 | + sha256 "7811e516e6b7bbc0153d30095560e0b1133f154060c5542764100d3e0eb2ab2b" |
| 20 | + end |
| 21 | + |
| 22 | + resource "frida-gum-devkit" do |
| 23 | + url "https://github.com/frida/frida/releases/download/16.1.2/frida-gum-devkit-16.1.2-macos-arm64.tar.xz" |
| 24 | + sha256 "03f6085ae5330cf38e0a498784500675fc5bd7361bb551a9097ba5fe397aceda" |
| 25 | + end |
| 26 | + |
| 27 | + def install |
| 28 | + odie "bpftime v0.2.0's macOS Frida build is arm64-only" if OS.mac? && !Hardware::CPU.arm? |
| 29 | + |
| 30 | + mkdir_p "third_party/frida" |
| 31 | + resource("frida-core-devkit").fetch |
| 32 | + resource("frida-gum-devkit").fetch |
| 33 | + cp resource("frida-core-devkit").cached_download, |
| 34 | + "third_party/frida/frida-core-devkit-16.1.2-macos-arm64.tar.xz" |
| 35 | + cp resource("frida-gum-devkit").cached_download, |
| 36 | + "third_party/frida/frida-gum-devkit-16.1.2-macos-arm64.tar.xz" |
| 37 | + |
| 38 | + inreplace "CMakeLists.txt", |
| 39 | + 'set(DEST_DIR "$ENV{HOME}/.bpftime")', |
| 40 | + "set(DEST_DIR \"#{libexec}\")" |
| 41 | + |
| 42 | + %w[ |
| 43 | + CMakeLists.txt |
| 44 | + tools/cli/CMakeLists.txt |
| 45 | + tools/bpftimetool/CMakeLists.txt |
| 46 | + tools/aot/CMakeLists.txt |
| 47 | + vm/llvm-jit/cli/CMakeLists.txt |
| 48 | + ].each do |cmake_file| |
| 49 | + inreplace cmake_file, "DESTINATION ~/.bpftime", "DESTINATION #{libexec}" if File.exist?(cmake_file) |
| 50 | + end |
| 51 | + |
| 52 | + inreplace "runtime/agent/CMakeLists.txt", |
| 53 | + 'target_link_options(bpftime-agent PUBLIC "-Wl,-export-dynamic")', |
| 54 | + <<~CMAKE.chomp |
| 55 | + if(NOT APPLE) |
| 56 | + target_link_options(bpftime-agent PUBLIC "-Wl,-export-dynamic") |
| 57 | + endif() |
| 58 | + CMAKE |
| 59 | + |
| 60 | + inreplace "vm/compat/ubpf-vm/CMakeLists.txt", |
| 61 | + 'target_link_options(bpftime_ubpf_vm PUBLIC "-Wl,--whole-archive" "$<TARGET_FILE:bpftime_ubpf_vm>" "-Wl,--no-whole-archive")', |
| 62 | + <<~CMAKE.chomp |
| 63 | + if(APPLE) |
| 64 | + target_link_options(bpftime_ubpf_vm PUBLIC "-Wl,-force_load,$<TARGET_FILE:bpftime_ubpf_vm>") |
| 65 | + else() |
| 66 | + target_link_options(bpftime_ubpf_vm PUBLIC "-Wl,--whole-archive" "$<TARGET_FILE:bpftime_ubpf_vm>" "-Wl,--no-whole-archive") |
| 67 | + endif() |
| 68 | + CMAKE |
| 69 | + |
| 70 | + ENV.append "LDFLAGS", "-L#{Formula["ncurses"].opt_lib}" |
| 71 | + ENV.append "CPPFLAGS", "-I#{Formula["boost"].opt_include}" |
| 72 | + |
| 73 | + args = %W[ |
| 74 | + -DCMAKE_INSTALL_PREFIX=#{prefix} |
| 75 | + -DCMAKE_BUILD_TYPE=RelWithDebInfo |
| 76 | + -DBPFTIME_BUILD_WITH_LIBBPF=OFF |
| 77 | + -DBPFTIME_BUILD_KERNEL_BPF=OFF |
| 78 | + -DBUILD_BPFTIME_DAEMON=OFF |
| 79 | + -DBPFTIME_ENABLE_UNIT_TESTING=OFF |
| 80 | + -DBPFTIME_ENABLE_CUDA_ATTACH=OFF |
| 81 | + -DBPFTIME_ENABLE_IOURING_EXT=OFF |
| 82 | + -DBPFTIME_LLVM_JIT=OFF |
| 83 | + -DBPFTIME_UBPF_JIT=ON |
| 84 | + -DBoost_INCLUDE_DIR=#{Formula["boost"].opt_include} |
| 85 | + -DCMAKE_INSTALL_RPATH=#{libexec} |
| 86 | + -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON |
| 87 | + ] |
| 88 | + |
| 89 | + system "cmake", "-S", ".", "-B", "build", *args |
| 90 | + system "cmake", "--build", "build", "--parallel" |
| 91 | + system "cmake", "--install", "build" |
| 92 | + |
| 93 | + (bin/"bpftime").write <<~SH |
| 94 | + #!/bin/bash |
| 95 | + exec "#{libexec}/bpftime" --install-location "#{libexec}" "$@" |
| 96 | + SH |
| 97 | + chmod 0755, bin/"bpftime" |
| 98 | + |
| 99 | + bin.install_symlink libexec/"bpftimetool" if (libexec/"bpftimetool").exist? |
| 100 | + end |
| 101 | + |
| 102 | + def caveats |
| 103 | + <<~EOS |
| 104 | + This macOS formula installs bpftime runtime files in: |
| 105 | + #{opt_libexec} |
| 106 | +
|
| 107 | + The bpftime wrapper automatically passes: |
| 108 | + --install-location #{opt_libexec} |
| 109 | +
|
| 110 | + This build uses bpftime's non-Linux configuration: |
| 111 | + BPFTIME_BUILD_WITH_LIBBPF=OFF |
| 112 | + BPFTIME_BUILD_KERNEL_BPF=OFF |
| 113 | + BPFTIME_LLVM_JIT=OFF |
| 114 | + BPFTIME_UBPF_JIT=ON |
| 115 | + EOS |
| 116 | + end |
| 117 | + |
| 118 | + test do |
| 119 | + assert_match "Usage", shell_output("#{bin}/bpftime --help") |
| 120 | + end |
| 121 | +end |
0 commit comments