chicken.scm 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2020 raingloom <raingloom@riseup.net>
  3. ;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org>
  4. ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (guix build-system chicken)
  21. #:use-module (guix utils)
  22. #:use-module (guix gexp)
  23. #:use-module (guix store)
  24. #:use-module (guix monads)
  25. #:use-module (guix search-paths)
  26. #:use-module (guix build-system)
  27. #:use-module (guix build-system gnu)
  28. #:use-module (guix packages)
  29. #:use-module (ice-9 match)
  30. #:export (%chicken-build-system-modules
  31. chicken-build
  32. chicken-build-system
  33. egg-uri))
  34. (define* (egg-uri name version #:optional (extension ".tar.gz"))
  35. "Return a URI string for the CHICKEN egg corresponding to NAME and VERSION.
  36. EXTENSION is the file name extension, such as '.tar.gz'."
  37. (string-append "https://code.call-cc.org/egg-tarballs/5/"
  38. name "/" name "-" version extension))
  39. (define %chicken-build-system-modules
  40. ;; Build-side modules imported and used by default.
  41. `((guix build chicken-build-system)
  42. (guix build union)
  43. ,@%gnu-build-system-modules))
  44. (define (default-chicken)
  45. ;; Lazily resolve the binding to avoid a circular dependency.
  46. ;; TODO is this actually needed in every build system?
  47. (let ((chicken (resolve-interface '(gnu packages chicken))))
  48. (module-ref chicken 'chicken)))
  49. (define* (lower name
  50. #:key source inputs native-inputs outputs system target
  51. (chicken (default-chicken))
  52. #:allow-other-keys
  53. #:rest arguments)
  54. "Return a bag for NAME."
  55. (define private-keywords
  56. '(#:target #:chicken #:inputs #:native-inputs))
  57. ;; TODO: cross-compilation support
  58. (and (not target)
  59. (bag
  60. (name name)
  61. (system system)
  62. (host-inputs `(,@(if source
  63. `(("source" ,source))
  64. '())
  65. ,@inputs
  66. ;; Keep the standard inputs of 'gnu-build-system', since
  67. ;; Chicken compiles Scheme by using C as an intermediate
  68. ;; language.
  69. ,@(standard-packages)))
  70. (build-inputs `(("chicken" ,chicken)
  71. ,@native-inputs))
  72. (outputs outputs)
  73. (build chicken-build)
  74. (arguments (strip-keyword-arguments private-keywords arguments)))))
  75. (define* (chicken-build name inputs
  76. #:key
  77. source
  78. (phases '%standard-phases)
  79. (outputs '("out"))
  80. (search-paths '())
  81. (egg-name "")
  82. (unpack-path "")
  83. (build-flags ''())
  84. (tests? #t)
  85. (system (%current-system))
  86. (guile #f)
  87. (imported-modules %chicken-build-system-modules)
  88. (modules '((guix build chicken-build-system)
  89. (guix build union)
  90. (guix build utils))))
  91. (define builder
  92. (with-imported-modules imported-modules
  93. #~(begin
  94. (use-modules #$@(sexp->gexp modules))
  95. (chicken-build #:name #$name
  96. #:source #+source
  97. #:system #$system
  98. #:phases #$phases
  99. #:outputs #$(outputs->gexp outputs)
  100. #:search-paths '#$(sexp->gexp
  101. (map search-path-specification->sexp
  102. search-paths))
  103. #:egg-name #$egg-name
  104. #:unpack-path #$unpack-path
  105. #:build-flags #$build-flags
  106. #:tests? #$tests?
  107. #:inputs #$(input-tuples->gexp inputs)))))
  108. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  109. system #:graft? #f)))
  110. (gexp->derivation name builder
  111. #:system system
  112. #:guile-for-build guile)))
  113. (define chicken-build-system
  114. (build-system
  115. (name 'chicken)
  116. (description
  117. "Build system for Chicken Scheme programs")
  118. (lower lower)))