~ruther/guix-local

ref: cuirass-guix guix-local/guix/build/hare-build-system.scm -rw-r--r-- 2.8 KiB
be058c00 — Rutherther ci: Use (guix channels) to build guix specification. 30 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2025 Lilah Tascheter <lilah@lunabee.space>
;;;
;;; 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 (guix build hare-build-system)
  #:use-module ((guix build gnu-build-system) #:prefix gnu:)
  #:use-module (guix build utils)
  #:export (%standard-phases
            hare-build))

(define (invoke-gnu-phase name args)
  (apply (assoc-ref gnu:%standard-phases name) args))

(define* (set-paths #:key inputs #:allow-other-keys #:rest args)
  "Sets proper PATH, HAREPATH, and pulled-in search paths."
  (invoke-gnu-phase 'set-paths args)
  ;; XXX: bag->derivation doesn't consider non-native search paths
  (set-path-environment-variable "HAREPATH" '("share/hare")
    (map cdr (alist-delete "source" inputs))))

(define* (build #:key hare-arch (make-flags '()) #:allow-other-keys #:rest args)
  "Builds Hare binaries through a provided Makefile."
  ;; HAREFLAGS seems to be typically supported, but we have to just guess.
  ;; Later args override earlier ones, so packages can override HAREFLAGS.
  (let* ((hareflags (format #f "HAREFLAGS=-a ~a" hare-arch))
         (flags (cons* hareflags make-flags)))
    (invoke-gnu-phase 'build (append args (list #:make-flags flags)))))

(define* (install #:key (make-flags '()) binary-output module-output
                  #:allow-other-keys #:rest args)
  "Install Hare modules and binaries through a provided Makefile."
  ;; Same deal here as in build. These seem to be the most common relevant
  ;; variables. Packages can override as needed.
  (let* ((prefix (format #f "PREFIX=~a" binary-output)) ; for manpages mostly
         (bindir (format #f "BINDIR=~a/bin" binary-output))
         (srcdir (format #f "SRCDIR=~a/share/hare" module-output))
         (moddir (format #f "THIRDPARTYDIR=~a/share/hare" module-output))
         (flags (cons* prefix bindir srcdir moddir make-flags)))
    (invoke-gnu-phase 'install (append args (list #:make-flags flags)))))

(define %standard-phases
  (modify-phases gnu:%standard-phases
    (replace 'set-paths set-paths)
    (delete 'bootstrap)
    (delete 'configure)
    (replace 'build build)
    (replace 'install install)))

(define hare-build gnu:gnu-build)