Skip to content

Commit

Permalink
Add updated bpf linker into nix env
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Mar 4, 2024
1 parent 87307ea commit 7145210
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
53 changes: 53 additions & 0 deletions deps/bpf-linker.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{ lib
, stdenv
, rustPlatform
, fetchFromGitHub
, llvmPackages_16
, zlib
, ncurses
, libxml2
, useRustLlvm ? false
}:

rustPlatform.buildRustPackage rec {
pname = "bpf-linker";
version = "0.9.10";

src = fetchFromGitHub {
owner = "aya-rs";
repo = pname;
rev = "v${version}";
hash = "sha256-EIZqeqCCnRqJIuhX5Dj9ogZCgFGfA2ukoPwU8AzYupI=";
};

cargoHash = "sha256-jLbQ49fxLROEAgokbVAy8yDIRe/MhFJxutRzSEtlnEk=";

buildNoDefaultFeatures = !useRustLlvm;

nativeBuildInputs = lib.optional (!useRustLlvm) llvmPackages_16.llvm;
buildInputs = [ zlib ncurses libxml2 ];

# aya-rustc-llvm-proxy will run cargo-metadata from $cargoDeps, so we need to fixup the .cargo/config there.
postPatch = lib.optionalString useRustLlvm ''
substituteInPlace $cargoDepsCopy/.cargo/config --replace @vendor@ $cargoDepsCopy
'';

# fails with: couldn't find crate `core` with expected target triple bpfel-unknown-none
# rust-src and `-Z build-std=core` are required to properly run the tests
doCheck = false;

# Work around https://github.com/NixOS/nixpkgs/issues/166205.
env = lib.optionalAttrs stdenv.cc.isClang {
NIX_LDFLAGS = "-l${stdenv.cc.libcxx.cxxabi.libName}";
};

meta = with lib; {
description = "Simple BPF static linker";
homepage = "https://github.com/aya-rs/bpf-linker";
license = with licenses; [ asl20 mit ];
maintainers = with maintainers; [ nickcao ];
# llvm-sys crate locates llvm by calling llvm-config
# which is not available when cross compiling
broken = stdenv.buildPlatform != stdenv.hostPlatform;
};
}
9 changes: 8 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {
buildInputs = with pkgs; [udev];
nativeBuildInputs = with pkgs; [rustup pkg-config];
nativeBuildInputs = with pkgs; [
rustup
pkg-config
(pkgs.callPackage deps/bpf-linker.nix { useRustLlvm = true; })

# For llvm-objdump
llvmPackages.bintools
];
}

0 comments on commit 7145210

Please sign in to comment.