Hey Guix!

I've been banging my head against this one for a while and I'd appreciate if
someone could take a look at it quickly, and spot where I went wrong.

So I'm trying to write a package with a single C file using
trivial-build-system[1]. I feel like I'm almost there, except when building the linker fails to find the glibc object files that I definitely specified. What makes this seem odd to me is: the same command succeeds if I run in a container
shell with only the dependencies and guile used.

I've attached the following files:

 - evhz.scm - containing the package definition that I just have in
   /gnu/packages/ in my checkout. (this is the only change)
 - build-evhz.out - the output of ./pre-inst-env guix build evhz
 - manual-gcc.out - the output of the command running the invoke gcc command
   in a guix-shell container

I've tried the following:

 - make clean and tried a few different master branch versions to see if that
   might shake it into action, but no avail.
 - Setting LD_LIBRARY_PATH, no effect
 - Specifying the library files explicitly with -l, still can't find them
 - Specifying native-inputs instead of just inputs, no change

If someone could take a look at my package definition, I've included the body
snippet below (full code attached):

        (build-system trivial-build-system)
        (arguments
         `(#:modules ((guix build utils))
           #:builder (begin
                         (use-modules (guix build utils))
                         (let ((source (assoc-ref %build-inputs "source"))
                               (glibc (assoc-ref %build-inputs "glibc"))
                               (gcc (assoc-ref %build-inputs "gcc"))
                               (binutils (assoc-ref %build-inputs "binutils"))                                (linux-libre-headers (assoc-ref %build-inputs "linux-libre-headers"))
                               (output (assoc-ref %outputs "out")))
                           (setenv "PATH" (string-join
                                           (list (string-append gcc "/bin")
                                                 (string-append binutils "/bin")
                                                 (getenv "PATH"))
                                           ":"))
                           (mkdir-p (string-append output "/bin"))
                           (invoke (string-append gcc "/bin/gcc")
                                   "-o" (string-append output "/bin/evhz")
                                   "-I" (string-append linux-libre-headers "/include")
                                   "-L" (string-append glibc "/lib")
                                   (string-append source "/evhz.c"))
                           #t))))
        (inputs
         (list binutils
               gcc
               gcc-toolchain
               glibc
               linux-libre-headers))

Thanks for making Guix awesome!

Christina O'Donnell

[1] It's my first attempt packaging and this looked the easiest on to start
with. There's no make file, so trivial-build-system seemed like it'd be the
right fit.[2]

[2] Aside: I saw that none of the trivial-build-system packages in Guix use
Gexp. Is Gexp compatible with trivial-build-system? I couldn't make it work.
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014 Andreas Enge <andr...@enge.fr>
;;; Copyright © 2014, 2015, 2017, 2018, 2020 Mark H Weaver <m...@netris.org>
;;; Copyright © 2014, 2015 Eric Bavier <bav...@member.fsf.org>
;;; Copyright © 2015-2022 Ludovic Courtès <l...@gnu.org>
;;; Copyright © 2015 Eric Dvorsak <e...@dvorsak.fr>
;;; Copyright © 2016 Mathieu Lirzin <m...@gnu.org>
;;; Copyright © 2015 Cyrill Schenkel <cyrill.schen...@gmail.com>
;;; Copyright © 2016, 2017, 2019-2023 Efraim Flashner <efr...@flashner.co.il>
;;; Copyright © 2016 Nikita <nik...@n0.is>
;;; Copyright © 2016 Alex Kost <alez...@gmail.com>
;;; Copyright © 2016 David Craven <da...@craven.ch>
;;; Copyright © 2016, 2017 John Darrington <j...@gnu.org>
;;; Copyright © 2017-2022 Marius Bakke <mar...@gnu.org>
;;; Copyright © 2017, 2018, 2019 Rutger Helling <rhell...@mykolab.com>
;;; Copyright © 2017, 2020 Arun Isaac <arunis...@systemreboot.net>
;;; Copyright © 2018–2022 Tobias Geerinckx-Rice <m...@tobias.gr>
;;; Copyright © 2018 Kei Kebreau <kkebr...@posteo.net>
;;; Copyright © 2018, 2020, 2022 Oleg Pykhalov <go.wig...@gmail.com>
;;; Copyright © 2018 Benjamin Slade <sl...@jnanam.net>
;;; Copyright © 2019 nee <n...@cock.li>
;;; Copyright © 2019 Yoshinori Arai <kumagus...@gmail.com>
;;; Copyright © 2019 Mathieu Othacehe <m.othac...@gmail.com>
;;; Copyright © 2020 Liliana Marie Prikler <liliana.prik...@gmail.com>
;;; Copyright © 2020 Florian Pelz <pelzflor...@pelzflorian.de>
;;; Copyright © 2020, 2021 Michael Rohleder <m...@rohleder.de>
;;; Copyright © 2020, 2021, 2022, 2023 Maxim Cournoyer <maxim.courno...@gmail.com>
;;; Copyright © 2020 Jean-Baptiste Note <jean-baptiste.n...@m4x.org>
;;; Copyright © 2021 Matthew James Kraai <kr...@ftbfs.org>
;;; Copyright © 2021 Nicolò Balzarotti <nic...@nixo.xyz>
;;; Copyright © 2021 Matthew James Kraai <kr...@ftbfs.org>
;;; Copyright © 2021 Brice Waegeneire <br...@waegenei.re>
;;; Copyright © 2021 Matthew James Kraai <kr...@ftbfs.org>
;;; Copyright © 2021 Maxime Devos <maximede...@telenet.be>
;;; Copyright © 2021 qblade <qbl...@protonmail.com>
;;; Copyright © 2021 Lu Hui <luhu...@gmail.com>
;;; Copyright © 2023 Zheng Junjie <873216...@qq.com>
;;; Copyright © 2023 Janneke Nieuwenhuizen <jann...@gnu.org>
;;; Copyright © 2023 John Kehayias <john.kehay...@protonmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages evhz)
  #:use-module (guix gexp)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix build-system trivial)
  #:use-module (guix utils)
  #:use-module (gnu packages)
  #:use-module (gnu packages base)
  #:use-module (gnu packages commencement)
  #:use-module (gnu packages gcc)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages xorg))

(define-public evhz
  (let ((commit "35b7526e0655522bbdf92f6384f4e9dff74f38a0")
        (revision "1"))
      (package
        (name "evhz")
        (version (git-version "0.0.0" revision commit))
        (source (origin
                  (method git-fetch)
                  (uri (git-reference
                        (url "https://git.sr.ht/~iank/evhz";)
                        (commit commit)))
                  (sha256
                   (base32
                     "1m2m60sh12jzc8f38g7g67b3avx2vg8ff0lai891jmjqvxw04bcl"))))
        (build-system trivial-build-system)
        (arguments
         `(#:modules ((guix build utils))
           #:builder (begin
                         (use-modules (guix build utils))
                         (let ((source (assoc-ref %build-inputs "source"))
                               (glibc (assoc-ref %build-inputs "glibc"))
                               (gcc (assoc-ref %build-inputs "gcc"))
                               (binutils (assoc-ref %build-inputs "binutils"))
                               (linux-libre-headers (assoc-ref %build-inputs "linux-libre-headers"))
                               (output (assoc-ref %outputs "out")))
                           (setenv "PATH" (string-join
                                           (list (string-append gcc "/bin")
                                                 (string-append binutils "/bin")
                                                 (getenv "PATH"))
                                           ":"))
                           ;; (setenv "LD_LIBRARY_PATH"
                           ;;         (string-join
                           ;;          (list (string-append glibc "/lib")
                           ;;                (getenv "LD_LIBRARY_PATH"))
                           ;;          ":"))
                           (mkdir-p (string-append output "/bin"))
                           (invoke (string-append gcc "/bin/gcc")
                                   "-o" (string-append output "/bin/evhz")
                                   "-I" (string-append linux-libre-headers "/include")
                                   "-L" (string-append glibc "/lib")
                                   ;; In an attempt to get it working. I know this shouldn't be necessary!
                                   ;; "-l" (string-append glibc "/lib/crt1.o")
                                   ;; "-l" (string-append glibc "/lib/crti.o")
                                   (string-append source "/evhz.c"))
                           #t))))
        (inputs
         (list binutils
               gcc
               gcc-toolchain
               glibc
               linux-libre-headers))
        ;; (native-inputs
        ;;  (list binutils
        ;;        gcc
        ;;        gcc-toolchain
        ;;        glibc
        ;;        linux-libre-headers))
        (home-page "https://git.sr.ht/~iank/evhz";)
        (synopsis "Show mouse refresh rate under linux + evdev.")
        (description
         "A simple diagnostic utility to show mouse refresh rate under linux +
evdev.")
        (license license:apsl2))))
cdo@peter ~/src/guix$ guix shell -CW --pure --share=/var/guix/daemon-socket
guix shell: loading environment from '/home/cdo/src/guix/manifest.scm'...
cdo@peter ~/src/guix [env]$ ./pre-inst-env guix build evhz
substitute: updating substitutes from 'https://ci.guix.gnu.org'... 100.0%
substitute: updating substitutes from 'https://bordeaux.guix.gnu.org'... 100.0%
The following derivation will be built:
  /gnu/store/krh1sk0zn9z517971cim6ld1mp9cimi4-evhz-0.0.0-1.35b7526.drv
building /gnu/store/krh1sk0zn9z517971cim6ld1mp9cimi4-evhz-0.0.0-1.35b7526.drv...
/gnu/store/cv571kkg5hyk98yw48857h1d0zi9azni-binutils-2.38/bin/ld: cannot find 
crt1.o: No such file or directory
/gnu/store/cv571kkg5hyk98yw48857h1d0zi9azni-binutils-2.38/bin/ld: cannot find 
crti.o: No such file or directory
collect2: error: ld returned 1 exit status
Backtrace:
           2 (primitive-load "/gnu/store/9nnndgaddiy668h5jdr5y1szzb1?")
In ice-9/eval.scm:
    619:8  1 (_ #(#<directory (guile-user) 7ffff77f7c80> "/gnu/st?" ?))
In guix/build/utils.scm:
    812:6  0 (invoke "/gnu/store/4xzyl951wdy25rgk0ppsn4nisglw3207-g?" ?)

guix/build/utils.scm:812:6: In procedure invoke:
ERROR:
  1. &invoke-error:
      program: "/gnu/store/4xzyl951wdy25rgk0ppsn4nisglw3207-gcc-11.3.0/bin/gcc"
      arguments: ("-o" 
"/gnu/store/cx1jfsphrpak2zvs6c5d3v0zj723jhc0-evhz-0.0.0-1.35b7526/bin/evhz" 
"-I" 
"/gnu/store/sjq77rvlryjgksni6ry1648xkj807ynv-linux-libre-headers-5.15.49/include"
 "-L" "/gnu/store/ip9mj1pwymxi1yq32zbhwp3n3bycy6yi-glibc-2.35/lib" 
"/gnu/store/2aji8wq4c7ix1b5g2g10b2wj1yghf4kl-git-checkout/evhz.c")
      exit-status: 1
      term-signal: #f
      stop-signal: #f
builder for 
`/gnu/store/krh1sk0zn9z517971cim6ld1mp9cimi4-evhz-0.0.0-1.35b7526.drv' failed 
with exit code 1
build of /gnu/store/krh1sk0zn9z517971cim6ld1mp9cimi4-evhz-0.0.0-1.35b7526.drv 
failed
Could not find build log for 
'/gnu/store/krh1sk0zn9z517971cim6ld1mp9cimi4-evhz-0.0.0-1.35b7526.drv'.
guix build: error: build of 
`/gnu/store/krh1sk0zn9z517971cim6ld1mp9cimi4-evhz-0.0.0-1.35b7526.drv' failed
cdo@peter ~/src/guix [env]$ 
cdo@peter ~$ guix shell -CW binutils gcc gcc-toolchain glibc 
linux-libre-headers guile --pure
cdo@peter ~ [env]$ exit
cdo@peter ~$ rm evhz
cdo@peter ~$ guix shell -CW binutils gcc gcc-toolchain glibc 
linux-libre-headers guile --pure
cdo@peter ~ [env]$ guile
GNU Guile 3.0.9
Copyright (C) 1995-2023 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (use-modules (guix build utils))
scheme@(guile-user)> (invoke 
"/gnu/store/4xzyl951wdy25rgk0ppsn4nisglw3207-gcc-11.3.0/bin/gcc" "-o" "evhz" 
"-I" 
"/gnu/store/sjq77rvlryjgksni6ry1648xkj807ynv-linux-libre-headers-5.15.49/include"
 "-L" "/gnu/store/ip9mj1pwymxi1yq32zbhwp3n3bycy6yi-glibc-2.35/lib" 
"/gnu/store/2aji8wq4c7ix1b5g2g10b2wj1yghf4kl-git-checkout/evhz.c")
$1 = #t
scheme@(guile-user)> 
cdo@peter ~ [env]$ exit
cdo@peter ~$ sudo ./evhz
Press CTRL-C to exit.

event0: Power Button
event1: Power Button
event2: SINO WEALTH Gaming KB 
event3: SINO WEALTH Gaming KB  System Control
event4: SINO WEALTH Gaming KB  Consumer Control
event5: SINO WEALTH Gaming KB  Keyboard
...

Reply via email to