summaryrefslogtreecommitdiff
path: root/hare.scm
blob: 77c5f6069ea318dd9410a3451b5fb52f929de662 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
(define-module (hare)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (guix gexp)
  #:use-module (guix git-download)
  #:use-module (guix download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system trivial)
  #:use-module (gnu packages)
  #:use-module (gnu packages base)
  #:use-module (gnu packages c)
  #:use-module (gnu packages man)
  #:use-module (ice-9 match))


;; Partially obtained from:
;; https://git.sr.ht/~whereiseveryone/guixrus/tree/master/item/guixrus/packages/hare.scm

(define tzdata-list
  (package
    (inherit tzdata)
    (name "tzdata-list")
    (arguments
     (list #:tests? #f
           ;; This consists purely of (architecture-independent) data, so
           ;; ‘cross-compilation’ is pointless here!  (The binaries zic,
           ;; dump, and tzselect are deleted in the post-install phase.)
           #:target #f
           #:make-flags
           #~(let ((out #$output)
                   (tmp (getenv "TMPDIR")))
               (list (string-append "TOPDIR=" out)
                     (string-append "TZDIR=" out "/share/zoneinfo")
                     (string-append "TZDEFAULT=" out
                                    "/share/zoneinfo/localtime")

                     ;; Likewise for the C library routines.
                     (string-append "LIBDIR=" tmp "/lib")
                     (string-append "MANDIR=" tmp "/man")

                     ;; XXX: tzdata 2020b changed the on-disk format
                     ;; of the time zone files from 'fat' to 'slim'.
                     ;; Many packages (particularly evolution-data-server)
                     ;; can not yet handle the latter, so we stick with
                     ;; 'fat' for now.
                     #$@(if (version>=? (package-version this-package)
                                        "2020b")
                            '("CPPFLAGS=-DZIC_BLOAT_DEFAULT='\"fat\"'")
                            '())

                     "AWK=awk"
                     "CC=gcc"))
           #:modules '((guix build utils)
                       (guix build gnu-build-system)
                       (srfi srfi-1))
           #:phases
           #~(modify-phases %standard-phases
               (replace 'unpack
                 (lambda* (#:key source inputs #:allow-other-keys)
                   (invoke "tar" "xvf" source)
                   (invoke "tar" "xvf"
                           #$(match (package-inputs this-package)
                               (((_ tzcode)) tzcode)))))
               (add-after 'install 'post-install
                 (lambda* (#:key outputs #:allow-other-keys)
                   ;; Move data in the right place.
                   (let ((out (assoc-ref outputs "out")))
                     (copy-file "leap-seconds.list"
                                (string-append out "/share/zoneinfo/leap-seconds.list"))
                     (symlink (string-append out "/share/zoneinfo")
                              (string-append out "/share/zoneinfo/posix"))
                     (copy-recursively (string-append out "/share/zoneinfo-leaps")
                                       (string-append out "/share/zoneinfo/right")))))
               (delete 'configure))))))

(define qbe-master
  (let ((commit "d023bdaa6b493686f7e9be7ac200ee4ac37d351f")
        (revision "1"))
    (package
      (inherit qbe)
      (name "qbe")
      (version (git-version "1.1" revision commit))
      (source (origin
                (method git-fetch)
                (uri (git-reference
                      (url "git://c9x.me/qbe")
                      (commit commit)))
                (file-name (git-file-name name version))
                (sha256
                 (base32
                  "11flr6mmxglidp4fr7whfzhwr1bjkiz0rcvpy541xmwm2isj5znm")))))))

(define-public harec
  (let ((revision "1")
        (commit "b4dd4275b24513d14e999bc35ea7d61ed02d1e08"))
    (package
      (name "harec")
      (version (git-version "0.0.1" revision commit))
      (source
        (origin
          (method git-fetch)
          (uri (git-reference
                 (url "https://git.sr.ht/~sircmpwn/harec")
                 (commit commit)))
          (file-name (git-file-name name version))
          (sha256
            (base32 "1brb0qr6fsi2hx724rprkkwi6qs6ymqglng78gm9m8k6z7c61j8b"))))
      (build-system gnu-build-system)
      (arguments
        `(#:phases
          (modify-phases %standard-phases
            (add-before 'configure 'setenv
              (lambda _
                (setenv "AR" ,(ar-for-target))
                (setenv "AS" ,(as-for-target))
                (setenv "LD" ,(ld-for-target))
                (setenv "CC" ,(cc-for-target))))
            (add-after 'configure 'configure-better
              (lambda* (#:key outputs #:allow-other-keys)
                (invoke "./configure"
                        (string-append "--prefix=" (assoc-ref outputs "out")))))
            (delete 'configure))))
      (inputs (list qbe-master scdoc))
      (synopsis "Bootstrapping compiler for Hare")
      (description "This package provides @code{harec}, the Hare language's
bootstrap written in C.  Currently, the self-hosting @code{harec} rewrite is
incomplete, so this is used as the default compiler in the build driver.")
      (home-page "https://git.sr.ht/~sircmpwn/harec")
      (license license:gpl3))))


(define-public hare
  (let ((revision "1")
        (commit "b35f4bc1551bf561de2e0e1fcd7367c20fa21216"))
    (package
      (name "hare")
      (version (git-version "0.0.1" revision commit))
      (source
        (origin
          (method git-fetch)
          (uri (git-reference
                 (url "https://git.sr.ht/~sircmpwn/hare")
                 (commit commit)))
          (file-name (git-file-name name version))
          (sha256
            (base32 "0v5r7007dyy75qagffkhag1pqigdsv2qgbgwrn44d51ws695phzi"))))
      (inputs (list scdoc qbe-master harec tzdata-list))
      (build-system gnu-build-system)
      (arguments
         (list
           #:make-flags #~(list "HARECACHE=./cache" (string-append "PREFIX=" #$output))
           #:phases
           #~(modify-phases %standard-phases
              (add-before 'configure 'configure-make
                (lambda _
                  (substitute*
                    "time/chrono/+linux.ha"
                    (("/usr/share/zoneinfo/leap-seconds.list")
                     (string-append #$tzdata-list "/share/zoneinfo/leap-seconds.list"))
                    (("/usr/share/zoneinfo/")
                     (string-append #$tzdata-list "/share/zoneinfo/")))
                  (copy-file "config.example.mk" "config.mk")
                  ;; We don't need to do this if we are using the toolchain
                  ;; below...
                  #;(substitute*
                    "config.mk"
                    (("AS = as")
                     (string-append "AS = "#$(as-for-target)))
                    (("LD = ld")
                     (string-append "LD = "#$(ld-for-target)))
                    (("QBE = qbe")
                     (string-append "QBE = " #$qbe-master "/bin/qbe"))
                    (("SCDOC = scdoc")
                     (string-append "SD =" #$scdoc "/bin/scdoc"))
                    (("HAREC = harec")
                     (string-append "HAREC =" #$harec "/bin/harec")))
                  #;(substitute*
                    "cmd/hare/build.ha"
                    (("\"qbe\"")
                     (string-append "\"" #$qbe-master "/bin/qbe" "\""))
                    (("\"harec\"")
                     (string-append "\"" #$harec "/bin/harec" "\"")))
              ))
              (delete 'configure))))
      (synopsis "Hare build driver")
      (description "Hare is a systems programming language designed to be
simple, stable, and robust.  Hare uses a static type system, manual memory
management, and a minimal runtime.  It is well-suited to writing operating
systems, system tools, compilers, networking software, and other low-level,
high performance tasks.")
      (home-page "https://git.sr.ht/~sircmpwn/hare")
      (license license:gpl3))))

(define-public hare-toolchain
  (package
    (name "hare-toolchain")
    (version (package-version hare))
    (source #f)
    (build-system trivial-build-system)
    (arguments `(#:builder (begin (mkdir %output))))
    (propagated-inputs (list binutils hare harec qbe-master))
    (native-search-paths (package-native-search-paths hare))
    (home-page (package-home-page hare))
    (synopsis "Complete @code{hare} toolchain for Hare development")
    (description "This package provides a toolchain for the Hare language. It
allows you to conveniently install all the required packages (such as
@code{binutils} and @code{qbe}) into your profile.")
    (license (package-license hare))))