Skip to content

Commit

Permalink
chore(nix): diable libbpf feature flag in cross build
Browse files Browse the repository at this point in the history
Upstream issue: NixOS/nixpkgs#373516

The aya loading backend appears to be stable and I am not bother to update
the hack for cross build anymore.

Also use bpftool for stripping as it produces smaller binary.
  • Loading branch information
EHfive committed Jan 23, 2025
1 parent 4062977 commit 3681b34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 42 deletions.
46 changes: 5 additions & 41 deletions nix/cross-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,10 @@ let

crossCC = "${crossPkgs.stdenv.cc}/bin/${crossPkgs.stdenv.cc.targetPrefix}cc";

buildInputs =
with crossPkgs;
[
## runtime dependencies of libbpf-sys on target platform
stdenv.cc.libc
# elfutils already has static library built
elfutils
]
++ lib.optionals (!enableStatic) (
with crossPkgs;
[
zlib
]
)
++ lib.optionals enableStatic (
assert crossPkgs.hostPlatform.isMusl;
with crossPkgs.pkgsStatic;
[
zlib
#required by libelf
zstd
]
);
buildInputs = with crossPkgs; [
## runtime dependencies on target platform
stdenv.cc.libc
];

buildInputsSearchFlags = map (dep: "-L${lib.getLib dep}/lib") buildInputs;
in
Expand All @@ -56,32 +37,21 @@ naersk'.buildPackage {

# compile BPF C code
llvmPackages.clang-unwrapped
llvmPackages.bintools-unwrapped

## build dependencies of libbpf-sys on target platform
# for cross linking libelf and zlib, and make libbpf
crossPkgs.stdenv.cc
bpftools
];
inherit buildInputs;
strictDeps = true;

cargoBuildOptions =
orig:
orig
++ [
#"-Z build-std"
"--features aya,libbpf"
]
++ lib.optionals enableStatic [
"--features static"
]
++ lib.optionals enableIpv6 [
"--features ipv6"
];

# bindgen libbpf for build platform and target platform
LIBCLANG_PATH = "${pkgs.clang.cc.lib}/lib";

CARGO_BUILD_TARGET = targetTriple;

NIX_CFLAGS_COMPILE = lib.optionals (enableStatic && crossPkgs.hostPlatform.isAarch) [
Expand All @@ -99,15 +69,9 @@ naersk'.buildPackage {
"-C target-feature=${if enableStatic then "+" else "-"}crt-static"
]
++ buildInputsSearchFlags
++ lib.optionals enableStatic [
"-lstatic=pthread"
"-lstatic=zstd"
]
);

preBuild = ''
export BINDGEN_EXTRA_CLANG_ARGS_${targetUnderscore}="''${NIX_CFLAGS_COMPILE}";
# Avoid adding host dependencies to CFLAGS and LDFLAGS for build platform
if [[ ${pkgs.stdenv.cc.suffixSalt} != ${crossPkgs.stdenv.cc.suffixSalt} ]]; then
export NIX_CC_WRAPPER_TARGET_HOST_${pkgs.stdenv.cc.suffixSalt}="";
Expand Down
3 changes: 2 additions & 1 deletion nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
rustPlatform,
pkg-config,
llvmPackages,
bpftools,
libbpf,
elfutils,
zlib,
Expand All @@ -15,7 +16,7 @@ naersk.buildPackage {
nativeBuildInputs = [
pkg-config
llvmPackages.clang-unwrapped
llvmPackages.bintools-unwrapped
bpftools
rustPlatform.bindgenHook
];

Expand Down

0 comments on commit 3681b34

Please sign in to comment.