projects/guix·blob java-team · refs

198 lines · 8.7 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2025 Lilah Tascheter <[email protected]>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (gnu packages hare)
20 #:use-module (gnu packages)
21 #:use-module (gnu packages base)
22 #:use-module (gnu packages c)
23 #:use-module (gnu packages commencement)
24 #:use-module (gnu packages cross-base)
25 #:use-module (gnu packages less)
26 #:use-module (gnu packages man)
27 #:use-module (guix build-system gnu)
28 #:use-module (guix build-system hare)
29 #:use-module (guix deprecation)
30 #:use-module (guix gexp)
31 #:use-module (guix git-download)
32 #:use-module ((guix licenses) #:prefix license:)
33 #:use-module (guix packages)
34 #:use-module (guix search-paths)
35 #:use-module (guix utils)
36 #:re-export (%hare-supported-systems target->hare-arch))
37
38(define-deprecated/public-alias hare-supported-systems %hare-supported-systems)
39
40(define (cross-target? target) ; only has to work for supported arches
41 (and target (not (if (%current-target-system)
42 (string=? (%current-target-system) target)
43 (string-prefix? (%current-system) target)))))
44
45(define (tools-for-target target)
46 (let* ((cross? (and=> target cross-target?))
47 (with-target (lambda (f) (if cross? (f target) (f))))
48 (prefix (string-upcase (with-target target->hare-arch)))
49 (prefix-for (lambda (v) (if target (string-append prefix "_" v) v)))
50 (toolchain (if cross? (cross-gcc-toolchain target) gcc-toolchain))
51 (bin-for (lambda (t) (file-append toolchain "/bin/" (with-target t)))))
52 #~((#$(prefix-for "CC") #$(bin-for cc-for-target))
53 (#$(prefix-for "AS") #$(bin-for as-for-target))
54 (#$(prefix-for "LD") #$(bin-for ld-for-target)))))
55
56(define hare-config ; unified build config for hare packages
57 (computed-file "hare-config.mk"
58 #~(begin (use-modules (ice-9 format))
59 (call-with-output-file #$output
60 (lambda (port)
61 (format port "include configs/linux.mk~%~:{~a=~a~%~}"
62 `(("ARCH" ,#$(target->hare-arch))
63 ("DEFAULT_TARGET" "$(ARCH)")
64 ("STDLIB" "$(PREFIX)/share/hare")
65 ("HAREPATH" "$(PREFIX)/share/hare")
66 #$@(tools-for-target #f)
67 #$@(tools-for-target "aarch64-linux-gnu")
68 #$@(tools-for-target "riscv64-linux-gnu")
69 #$@(tools-for-target "x86_64-linux-gnu"))))))))
70
71(define-public harec
72 (package
73 (name "harec")
74 (version "0.26.0")
75 (source (origin
76 (method git-fetch)
77 (uri (git-reference
78 (url "https://git.sr.ht/~sircmpwn/harec")
79 (commit version)))
80 (file-name (git-file-name name version))
81 (sha256
82 (base32
83 "1bzmd4j2q6kdgz8zxs6qwy57fzh7wh7xwps9rcmcrhwl5zngff3b"))))
84 (build-system gnu-build-system)
85 (arguments
86 (list #:modules `((ice-9 format) ,@%default-gnu-modules)
87 #:make-flags #~(list (string-append "PREFIX=" #$output)
88 (string-append "VERSION=" #$version))
89 #:phases
90 #~(modify-phases %standard-phases
91 (replace 'configure
92 (lambda _ (copy-file #$hare-config "config.mk"))))))
93 (native-inputs (list qbe))
94 (supported-systems %hare-supported-systems)
95 (home-page "https://harelang.org")
96 (synopsis "Harelang bootstrap compiler")
97 (description "@code{harec} is a bootstrap compiler written in C for the Hare
98programming language. For general Hare programming, see the @code{hare}
99package.")
100 (license license:gpl3)))
101
102(define $HAREPATH
103 (search-path-specification
104 (variable "HAREPATH")
105 (files '("share/hare"))))
106
107(define $HARE_TOOLPATH
108 (search-path-specification
109 (variable "HARE_TOOLPATH")
110 (files '("libexec/hare"))))
111
112(define-public hare
113 (package
114 (name "hare")
115 (version "0.26.0")
116 (source (origin
117 (method git-fetch)
118 (uri (git-reference
119 (url "https://git.sr.ht/~sircmpwn/hare")
120 (commit version)))
121 (file-name (git-file-name name version))
122 (patches (search-patches "hare-fallback-cache.patch"))
123 (sha256
124 (base32
125 "1iay401z2bl6rihjlgd50zq1d29l7k304r5jmwr55l8in2fy3nnw"))))
126 (build-system gnu-build-system)
127 (arguments
128 (list #:modules `((ice-9 format) ,@%default-gnu-modules)
129 #:make-flags #~(list (string-append "PREFIX=" #$output)
130 (string-append "VERSION=" #$version))
131 #:phases
132 #~(modify-phases %standard-phases
133 ;; technically hare does programmatically generate some
134 ;; makefiles as part of a bootstrap phase. however, regenning
135 ;; these files requires an installation of hare in the first
136 ;; place. seeing as the files are pretty short and
137 ;; human-readable, I think it's fine to leave them as-is.
138 (replace 'configure
139 (lambda* (#:key inputs #:allow-other-keys)
140 (copy-file #$hare-config "config.mk")
141 ;; need to unhardcode some shit manually
142 (let ((file (lambda (s) (search-input-file inputs s)))
143 (dir (lambda (s) (search-input-directory inputs s))))
144 (substitute* "cmd/hare/build.ha"
145 (("\"harec\"") (format #f "\"~a\"" (file "bin/harec")))
146 (("\"qbe\"") (format #f "\"~a\"" (file "bin/qbe"))))
147 (substitute* "cmd/haredoc/main.ha"
148 (("\"less\"") (format #f "\"~a\"" (file "bin/less"))))
149 (substitute* "wordexp/wordexp.ha"
150 (("/bin/sh") (file "bin/sh")))
151 (substitute* "time/chrono/+linux.ha"
152 (("/usr/share/zoneinfo/leap-seconds.list")
153 (file "share/zoneinfo/leap-seconds.list")))
154 (substitute* "time/date/+linux.ha"
155 (("/usr/share/zoneinfo") (dir "share/zoneinfo")))))))))
156 (inputs
157 (let ((tc (lambda (t) (and (cross-target? t) (cross-gcc-toolchain t)))))
158 (filter ->bool (list gcc-toolchain less tzdata/leap-seconds harec qbe
159 ;; provide cross toolchains for all
160 ;; non-native possible targets
161 (tc "aarch64-linux-gnu")
162 (tc "riscv64-linux-gnu")
163 (tc "x86_64-linux-gnu")))))
164 (native-inputs (list harec qbe scdoc))
165 (supported-systems %hare-supported-systems)
166 (native-search-paths (list $HAREPATH $HARE_TOOLPATH))
167 (home-page "https://harelang.org")
168 (synopsis "Harelang compiler tooling and stdlib")
169 (description "Hare is a simple systems programming language, featuring
170static typing, manual memory management, and a minimal runtime.")
171 (license (list license:gpl3 license:mpl2.0))))
172
173(define-public hare-update
174 (package
175 (name "hare-update")
176 (version "0.26.0.0")
177 (source (origin
178 (method git-fetch)
179 (uri (git-reference
180 (url "https://git.sr.ht/~sircmpwn/hare-update")
181 (commit version)))
182 (file-name (git-file-name name version))
183 (sha256
184 (base32
185 "1pqlqgryjdcvzshj95p3gd8icpjgn01hcsfss8r3hd8xqr87v8qk"))))
186 (build-system hare-build-system)
187 (arguments (list #:phases
188 #~(modify-phases %standard-phases
189 (add-before 'build 'build-rules
190 ;; genrules is invoked during build, so we have to
191 ;; build it natively separately
192 (lambda _ (invoke "make" "hare-update-genrules"))))))
193 (supported-systems %hare-supported-systems)
194 (home-page "https://harelang.org")
195 (synopsis "Harelang interversion updater tool")
196 (description "@code{hare-update} updates Harelang source files to newer
197versions of the language and stdlib automagically.")
198 (license license:eupl1.2)))