mercury.scm 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2020 Brett Gilio <brettg@gnu.org>
  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. (define-module (gnu packages mercury)
  19. #:use-module (guix download)
  20. #:use-module (guix git-download)
  21. #:use-module (guix packages)
  22. #:use-module (guix utils)
  23. #:use-module ((guix licenses) #:prefix license:)
  24. #:use-module (guix build-system gnu)
  25. #:use-module (gnu packages autotools)
  26. #:use-module (gnu packages bdw-gc)
  27. #:use-module (gnu packages readline)
  28. #:use-module (gnu packages texinfo)
  29. #:use-module (gnu packages flex)
  30. #:use-module (gnu packages shells)
  31. #:use-module (gnu packages bison)
  32. #:use-module (gnu packages pkg-config)
  33. #:use-module (ice-9 match)) ; match-lambda
  34. ;; NOTE: Mercury uses a tightly coupled fork of BDWGC and
  35. ;; libatomic-ops. When updating the package, please check the GitHub
  36. ;; repository to ensure that the submodule commit matches what is
  37. ;; provided.
  38. (define (gc-fork package-name package-url
  39. package-commit package-hash)
  40. (let ((commit package-commit))
  41. (package (inherit package-name)
  42. (source
  43. (origin
  44. (method git-fetch)
  45. (uri (git-reference
  46. (url package-url)
  47. (commit commit)))
  48. (sha256 (base32 package-hash)))))))
  49. ;; NOTE: Mercury /MUST/ bootstrap from a tarball release.
  50. ;; Once the bootstrapping compiler is established, this
  51. ;; minimal build can be used for further compiling Mercury
  52. ;; from a git checkout with additional grades enabled.
  53. (define-public mercury-minimal
  54. (package
  55. (name "mercury-minimal")
  56. (version "20.06.1")
  57. (source (origin
  58. (method url-fetch)
  59. (uri (string-append
  60. "https://dl.mercurylang.org/release/mercury-srcdist-"
  61. version ".tar.gz"))
  62. (sha256
  63. (base32
  64. "07qwkk871yxd4q1sw5xv26g8jrpvnpprmzvfd7zg7i142kl3l2gg"))))
  65. (build-system gnu-build-system)
  66. (arguments
  67. `(#:modules ((guix build gnu-build-system)
  68. (guix build utils)
  69. (ice-9 match))
  70. #:tests? #f ; Tests are run on the stage-2 compiler.
  71. ;; TODO: Find a way to bypass all static linkages.
  72. #:configure-flags (list "--enable-minimal-install")
  73. #:phases
  74. (modify-phases %standard-phases
  75. (add-after 'unpack 'replace-boehm-gc
  76. (lambda* (#:key inputs outputs #:allow-other-keys)
  77. (let ((out (assoc-ref outputs "out"))
  78. (libgc (assoc-ref inputs "libgc"))
  79. (libatomic-ops (assoc-ref inputs "libatomic-ops"))
  80. (unpack (assoc-ref %standard-phases 'unpack))
  81. (patch-source-shebangs
  82. (assoc-ref %standard-phases 'patch-source-shebangs)))
  83. (map (match-lambda
  84. ((src orig-name new-name)
  85. (with-directory-excursion "."
  86. (apply unpack (list #:source src)))
  87. (delete-file-recursively new-name)
  88. (invoke "mv" orig-name new-name)
  89. (with-directory-excursion new-name
  90. (apply patch-source-shebangs (list #:source src)))))
  91. `((,libgc "source" "boehm_gc")))
  92. (map (match-lambda
  93. ((src orig-name new-name)
  94. (with-directory-excursion "."
  95. (apply unpack (list #:source src)))
  96. (delete-file-recursively new-name)
  97. (invoke "mv" orig-name new-name)
  98. (with-directory-excursion new-name
  99. (apply patch-source-shebangs (list #:source src)))))
  100. `((,libatomic-ops "source" "boehm_gc/libatomic_ops")))
  101. #t)))
  102. (add-after 'replace-boehm-gc 'patch-paths
  103. (lambda _
  104. (substitute*
  105. (list "Makefile"
  106. "Mmakefile"
  107. "scripts/mercury_update_interface.in"
  108. "scripts/mercury_config.in"
  109. "scripts/mmake.in"
  110. "scripts/Mmake.vars.in"
  111. "scripts/mdb.in"
  112. "scripts/rs6000_hack"
  113. "scripts/fullarch"
  114. "scripts/mmc.in"
  115. "scripts/canonical_grade"
  116. "scripts/mprof.in"
  117. "scripts/gud.el"
  118. "scripts/ml.in"
  119. "scripts/canonical_grade.in"
  120. "scripts/mdprof.in"
  121. "scripts/vpath_find"
  122. "scripts/mkfifo_using_mknod.in"
  123. "scripts/prepare_install_dir.in"
  124. "scripts/mprof_merge_runs"
  125. "scripts/mtc"
  126. "scripts/mgnuc.in"
  127. "scripts/c2init.in"
  128. "bindist/bindist.Makefile"
  129. "boehm_gc/configure.ac"
  130. "boehm_gc/Makefile.direct")
  131. (("/bin/sh") (which "sh"))
  132. (("/bin/pwd") (which "pwd"))
  133. (("/bin/rm") (which "rm")))
  134. #t)))))
  135. (native-inputs
  136. `(("texinfo" ,texinfo)
  137. ("flex" ,flex)
  138. ("tcsh" ,tcsh)
  139. ("bison" ,bison)
  140. ("readline" ,readline)
  141. ("libatomic-ops" ,(package-source
  142. (gc-fork
  143. libatomic-ops
  144. "https://github.com/Mercury-Language/libatomic_ops.git"
  145. "49b70d57f6922fd8be55a7dcb77955c8abfc9ae9"
  146. "1flvwscsa6b2b8a38vhhcgl10bbkb5nnihw7s7iia60cinf7wcqm")))
  147. ("libgc" ,(package-source
  148. (gc-fork
  149. libgc-7
  150. "https://github.com/Mercury-Language/bdwgc.git"
  151. "43ac2ea45261ba0a715534e9da41b2504904c46a"
  152. "0bmzmbs7id0ndyhy9xli6fhfad1shrim6vmy2k8m1nqr5wb31q76")))
  153. ("pkg-config" ,pkg-config)))
  154. (synopsis "Pure logic programming language (used only for
  155. bootstrapping dependent Mercury)")
  156. (description "Mercury is a logic/functional programming language which
  157. combines the clarity and expressiveness of declarative programming with advanced
  158. static analysis and error detection features. Its highly optimized execution
  159. algorithm delivers efficiency far in excess of existing logic programming
  160. systems, and close to conventional programming systems. Mercury addresses
  161. the problems of large-scale program development, allowing modularity,
  162. separate compilation, and numerous optimization/time trade-offs.")
  163. (home-page "https://mercurylang.org")
  164. (license license:gpl2)))
  165. ;; NOTE: This package is quite large and will take an extensive
  166. ;; amount of time to compile, especially with bootcheck functionality
  167. ;; enabled. To ensure that we do not monopolize the CI & build servers,
  168. ;; please make sure that your changes are justified.
  169. (define-public mercury
  170. (package (inherit mercury-minimal)
  171. (name "mercury")
  172. (version "20.06.1")
  173. (source
  174. (origin
  175. (method git-fetch)
  176. (uri (git-reference
  177. (url "https://github.com/Mercury-Language/mercury")
  178. (commit (string-append
  179. "version-"
  180. (string-join (string-split version #\.) "_")))))
  181. (file-name (git-file-name name version))
  182. (sha256
  183. (base32
  184. "1b6rmdinw8mj6n9sc7c75kkf42gd2k254rf51x4snlrqckxj7aaz"))))
  185. (arguments
  186. (substitute-keyword-arguments
  187. (package-arguments mercury-minimal)
  188. ;; TODO: Find a way to bypass all static linkages.
  189. ((#:configure-flags flags ''())
  190. `(list ""))
  191. ((#:tests? _) #f) ; FIXME: Many test-cases failing.
  192. ((#:phases phases)
  193. `(modify-phases ,phases
  194. (replace 'patch-paths
  195. (lambda _
  196. (substitute*
  197. (list "prepare.sh"
  198. "Makefile"
  199. "Mmakefile"
  200. "scripts/mercury_update_interface.in"
  201. "scripts/mercury_config.in"
  202. "scripts/mmake.in"
  203. "scripts/Mmake.vars.in"
  204. "scripts/mdb.in"
  205. "scripts/rs6000_hack"
  206. "scripts/fullarch"
  207. "scripts/mmc.in"
  208. "scripts/mprof.in"
  209. "scripts/gud.el"
  210. "scripts/ml.in"
  211. "scripts/canonical_grade.in"
  212. "scripts/mdprof.in"
  213. "scripts/vpath_find"
  214. "scripts/mkfifo_using_mknod.in"
  215. "scripts/prepare_install_dir.in"
  216. "scripts/mprof_merge_runs"
  217. "scripts/mtc"
  218. "scripts/mgnuc.in"
  219. "scripts/c2init.in"
  220. "tools/bootcheck"
  221. "boehm_gc/configure.ac"
  222. "boehm_gc/Makefile.direct")
  223. (("/bin/sh") (which "sh"))
  224. (("/bin/pwd") (which "pwd"))
  225. (("/bin/rm") (which "rm"))
  226. (("boehm_gc/.git") "boehm_gc"))
  227. #t))
  228. (replace 'bootstrap
  229. (lambda _
  230. (invoke "./prepare.sh")
  231. #t))))))
  232. ;; TODO: Uncomment phase when tests are enabled.
  233. ;; (replace 'check
  234. ;; (lambda _
  235. ;; (invoke "./tools/bootcheck")
  236. ;; #t))
  237. ;;
  238. ;; TODO: The mercury configuration system determines
  239. ;; grade support by looking for available toolchains.
  240. ;; Eventually we need to add inputs for Java, Erlang,
  241. ;; C#, etc. in order to enable these extra grades.
  242. (native-inputs
  243. `(("mercury-minimal" ,mercury-minimal)
  244. ("autoconf" ,autoconf)
  245. ("automake" ,automake)
  246. ,@(package-native-inputs mercury-minimal)))
  247. (synopsis "Pure logic programming language")))