Subject: [bug#48889] [PATCH 4/4] bpftool: new package

From: Maxime Devos <[email-masked]>
Date: Mon, 07 Jun 2021 11:50:31 +0200

Ryan Sundberg via Guix-patches via schreef op zo 06-06-2021 om 11:52 [-0700]:
> Adds the bpftool package from the Linux kernel source tree.
> ---
>  gnu/packages/linux.scm | 40 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 
> diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
> index c8ec310665..06bb344475 100644
> --- a/gnu/packages/linux.scm
> +++ b/gnu/packages/linux.scm
> @@ -54,6 +54,7 @@
>  ;;; Copyright © 2020 David Dashyan <[email-masked]>
>  ;;; Copyright © 2020 pukkamustard <[email-masked]>
>  ;;; Copyright © 2021 B. Wilson <[email-masked]>
> +;;; Copyright © 2021 Ryan Sundberg <[email-masked]>
>  ;;;
>  ;;; This file is part of GNU Guix.
>  ;;;
> @@ -8108,3 +8109,42 @@ Availability and Serviceability} reports from Linux kernel trace events.
>  These trace events are logged in @file{/sys/kernel/debug/tracing} and reported
>  through standard log mechanisms like syslog.")
>      (license license:gpl2)))
> +
> +(define-public bpftool
> +  (package
> +    (name "bpftool")
> +    (version (package-version linux-libre))
> +    (source (package-source linux-libre))
> +    (build-system gnu-build-system)
> +    (arguments
> +      `(#:tests? #f

Why are tests disabled?

> +        #:phases 
> +        (modify-phases %standard-phases
> +          (add-before 'configure 'chdir 
> +            (lambda _ (chdir "tools/bpf") #t))
> +          (delete 'configure)
> +          (replace 'build 
> +            (lambda _ (invoke "make" "CC=gcc" "bpftool") #t))

Use ,(string-append "CC=" (cc-for-target)), to make sure cross-compiling bpftools
works.

> +          (replace 'install 
> +            (lambda* (#:key outputs #:allow-other-keys)
> +              (let* ((out (assoc-ref outputs "out"))) 
> +                (mkdir-p (string-append out "/sbin"))
> +                (mkdir-p (string-append out "/share/bash-completion/completions"))
> +                (invoke "make" 
> +                        (string-append "prefix=" out)
> +                        (string-append "bash_compdir=" out "/share/bash-completion/completions")
> +                        "-C" "bpftool"
> +                        "install")
> +                #t))))))
> +    (inputs
> +      `(("bison" ,bison)

Bison looks like a native input to me.

> +        ("python" ,python-3)

Could be input, could be native-input. I don't know what's appropriate for bpftools.

You can check with
  ./pre-inst-env guix build bpftools --target=aarch64-linux-gnu

If there is "command not found: python" or something like that,
you'll need to move python to native-inputs.

> +        ("readline" ,readline)))
> +    (propagated-inputs
> +      `(("libcap" ,libcap)
> +        ("libelf" ,libelf)
> +        ("zlib" ,zlib)))

bpftool is a tool, and not a library, right?
Then these libraries should be in inputs, not propagated-inputs,
to avoid polluting the profile.

bpftool should still have access to these libraries by ELF's RPATH
or something like that.

> +    (home-page (package-home-page linux-libre))

I don't see anything about bpftools on <https://www.gnu.org/software/linux-libre/>.
Maybe bpftools has a wiki somewhere?

> +    (synopsis "bpftool is a tool for inspection and simple manipulation of eBPF programs and maps")
> +    (description "*bpftool* allows for inspection and simple modification of BPF objects on the system.  Note that format of the output of all tools is not guaranteed to be stable and should not be depended upon.")

Line is too long. Also, what's up with surrounding bpftools with *asterisks*?

Greetings,
Maxime.