From 029c575fc1dea3486a5e5538a2cee5a4b9434ef6 Mon Sep 17 00:00:00 2001 From: Lilah Tascheter Date: Sat, 25 Oct 2025 12:04:11 -0500 Subject: [PATCH] guix: build-system: Add hare-build-system. * guix/build-system/hare.scm: New file. * guix/build/hare-build-system.scm: New file. * Makefile.am (MODULES): Add above new files. Change-Id: I5b760410f6cd2ede28b84e8d2db363ff968f16f6 Signed-off-by: jgart --- Makefile.am | 2 + guix/build-system/hare.scm | 144 +++++++++++++++++++++++++++++++ guix/build/hare-build-system.scm | 63 ++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 guix/build-system/hare.scm create mode 100644 guix/build/hare-build-system.scm diff --git a/Makefile.am b/Makefile.am index a4e7277d6d493ed13fdf691eff0d4cb3a4c083f3..459f3f4b6b74a010b3f54ecdf9d9d9357723a0ce 100644 --- a/Makefile.am +++ b/Makefile.am @@ -170,6 +170,7 @@ MODULES = \ guix/build-system/gnu.scm \ guix/build-system/go.scm \ guix/build-system/guile.scm \ + guix/build-system/hare.scm \ guix/build-system/haskell.scm \ guix/build-system/julia.scm \ guix/build-system/linux-module.scm \ @@ -240,6 +241,7 @@ MODULES = \ guix/build/gnu-build-system.scm \ guix/build/gnu-dist.scm \ guix/build/guile-build-system.scm \ + guix/build/hare-build-system.scm \ guix/build/luanti-build-system.scm \ guix/build/maven-build-system.scm \ guix/build/minetest-build-system.scm \ diff --git a/guix/build-system/hare.scm b/guix/build-system/hare.scm new file mode 100644 index 0000000000000000000000000000000000000000..6b5f70968046f5bac03078813a4d0f124660fb6c --- /dev/null +++ b/guix/build-system/hare.scm @@ -0,0 +1,144 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2025 Lilah Tascheter +;;; +;;; 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 . + +(define-module (guix build-system hare) + #:use-module (guix build-system) + #:use-module (guix build-system gnu) + #:use-module (guix gexp) + #:use-module (guix monads) + #:use-module (guix packages) + #:use-module (guix search-paths) + #:use-module (guix store) + #:use-module (guix utils) + #:export (%hare-supported-systems + target->hare-arch + %default-hare-imported-modules + %default-hare-modules + hare-build-system)) + +(define %hare-supported-systems + '("x86_64-linux" "aarch64-linux" "riscv64-linux")) + +(define* (target->hare-arch #:optional (target (or (%current-target-system) + (%current-system)))) + ;; Only error on supported systems, so we don't break guix pull. + (if (member (%current-system) %hare-supported-systems) + (cond ((target-x86-64? target) "x86_64") + ((target-aarch64? target) "aarch64") + ((target-riscv64? target) "riscv64") + (else (error "unsupported hare target" target))) + "UNKNOWN")) + +(define %default-hare-imported-modules + (cons '(guix build hare-build-system) %default-gnu-imported-modules)) +(define %default-hare-modules + '((guix build hare-build-system) (guix build utils))) + +(define* (lower name #:key source inputs native-inputs outputs system target + (implicit-inputs? #t) (implicit-cross-inputs? #t) + #:allow-other-keys #:rest arguments) + (let* ((hare (module-ref (resolve-interface '(gnu packages hare)) 'hare)) + (private-arguments '(#:inputs #:native-inputs #:target + #:build-inputs #:target-inputs #:host-inputs + #:implicit-inputs? #:implicit-cross-inputs?))) + (bag + (name name) + (system system) + (target target) + (arguments (strip-keyword-arguments private-arguments arguments)) + (build-inputs (append (if source `(("source" ,source)) '()) + native-inputs + (if implicit-inputs? `(("hare" ,hare)) '()) + (if (and implicit-cross-inputs? target) + (standard-cross-packages target 'host) '()) + (if implicit-inputs? + (standard-packages system) '()))) + (host-inputs inputs) + (target-inputs (if (and implicit-cross-inputs? target) + (standard-cross-packages target 'target) '())) + (outputs outputs) + (build (if target hare-build (lambda (name inputs . rest) + (apply hare-build name + #:host-inputs inputs rest))))))) + +(define* (hare-build name #:key guile system (target #f) source + (build-inputs '()) (target-inputs '()) (host-inputs '()) + (phases '%standard-phases) (outputs '("out")) + (imported-modules %default-hare-imported-modules) + (modules %default-hare-modules) + + (search-paths '()) (native-search-paths '()) + (make-flags ''()) (hare-arch #f) + (parallel-builds? #t) + (tests? #t) (test-target "check") (parallel-tests? #t) + (binary-output (if (member "bin" outputs) "bin" "out")) + (module-output (if (member "lib" outputs) "lib" "out")) + (validate-runpath? #t) + + (substitutable? #t) + allowed-references disallowed-references) + (define builder + (with-imported-modules imported-modules + #~(begin (use-modules #$@modules) + (define %build-host-inputs #+(input-tuples->gexp build-inputs)) + (define %build-target-inputs + (append #$(input-tuples->gexp host-inputs) + #+(input-tuples->gexp target-inputs))) + (define %build-inputs + (append %build-host-inputs %build-target-inputs)) + + (define %outputs #$(outputs->gexp outputs)) + (define %binary-output (assoc-ref %outputs #$binary-output)) + (define %module-output (assoc-ref %outputs #$module-output)) + + (hare-build + #:source #+source + #:system #$system + #:target #$target + #:phases #$phases + #:inputs %build-target-inputs + #:native-inputs %build-host-inputs + #:outputs %outputs + #:search-paths '#$(map search-path-specification->sexp search-paths) + #:native-search-paths '#$(map search-path-specification->sexp + native-search-paths) + #:hare-arch #$(or hare-arch (target->hare-arch (or target system))) + #:binary-output %binary-output + #:module-output %module-output + #:make-flags #$make-flags + #:parallel-builds? #$parallel-builds? + #:tests? #$tests? + #:test-target #$test-target + #:parallel-tests? #$parallel-tests? + #:validate-runpath? #$validate-runpath?)))) + (mlet %store-monad ((guile (package->derivation (or guile (default-guile)) + system #:graft? #f))) + (gexp->derivation name builder + #:system system + #:target target + #:graft? #f ; same as gnu-build-system + #:substitutable? substitutable? + #:allowed-references allowed-references + #:disallowed-references disallowed-references + #:guile-for-build guile))) + +(define hare-build-system + (build-system + (name 'hare) + (description "Hare de facto build systems") + (lower lower))) diff --git a/guix/build/hare-build-system.scm b/guix/build/hare-build-system.scm new file mode 100644 index 0000000000000000000000000000000000000000..9853011e22f50e8a07eebc998911fdbf21097a76 --- /dev/null +++ b/guix/build/hare-build-system.scm @@ -0,0 +1,63 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2025 Lilah Tascheter +;;; +;;; 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 . + +(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)