chicken.scm 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2020 raingloom <raingloom@riseup.net>
  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 (guix build-system chicken)
  19. #:use-module (guix utils)
  20. #:use-module (guix derivations)
  21. #:use-module (guix search-paths)
  22. #:use-module (guix build-system)
  23. #:use-module (guix build-system gnu)
  24. #:use-module (guix packages)
  25. #:use-module (ice-9 match)
  26. #:export (%chicken-build-system-modules
  27. chicken-build
  28. chicken-build-system))
  29. (define %chicken-build-system-modules
  30. ;; Build-side modules imported and used by default.
  31. `((guix build chicken-build-system)
  32. (guix build union)
  33. ,@%gnu-build-system-modules))
  34. (define (default-chicken)
  35. ;; Lazily resolve the binding to avoid a circular dependency.
  36. ;; TODO is this actually needed in every build system?
  37. (let ((chicken (resolve-interface '(gnu packages chicken))))
  38. (module-ref chicken 'chicken)))
  39. (define* (lower name
  40. #:key source inputs native-inputs outputs system target
  41. (chicken (default-chicken))
  42. #:allow-other-keys
  43. #:rest arguments)
  44. "Return a bag for NAME."
  45. (define private-keywords
  46. '(#:source #:target #:chicken #:inputs #:native-inputs))
  47. ;; TODO: cross-compilation support
  48. (and (not target)
  49. (bag
  50. (name name)
  51. (system system)
  52. (host-inputs `(,@(if source
  53. `(("source" ,source))
  54. '())
  55. ,@inputs
  56. ;; Keep the standard inputs of 'gnu-build-system', since
  57. ;; Chicken compiles Scheme by using C as an intermediate
  58. ;; language.
  59. ,@(standard-packages)))
  60. (build-inputs `(("chicken" ,chicken)
  61. ,@native-inputs))
  62. (outputs outputs)
  63. (build chicken-build)
  64. (arguments (strip-keyword-arguments private-keywords arguments)))))
  65. (define* (chicken-build store name inputs
  66. #:key
  67. (phases '(@ (guix build chicken-build-system)
  68. %standard-phases))
  69. (outputs '("out"))
  70. (search-paths '())
  71. (egg-name "")
  72. (unpack-path "")
  73. (build-flags ''())
  74. (tests? #t)
  75. (system (%current-system))
  76. (guile #f)
  77. (imported-modules %chicken-build-system-modules)
  78. (modules '((guix build chicken-build-system)
  79. (guix build union)
  80. (guix build utils))))
  81. (define builder
  82. `(begin
  83. (use-modules ,@modules)
  84. (chicken-build #:name ,name
  85. #:source ,(match (assoc-ref inputs "source")
  86. (((? derivation? source))
  87. (derivation->output-path source))
  88. ((source)
  89. source)
  90. (source
  91. source))
  92. #:system ,system
  93. #:phases ,phases
  94. #:outputs %outputs
  95. #:search-paths ',(map search-path-specification->sexp
  96. search-paths)
  97. #:egg-name ,egg-name
  98. #:unpack-path ,unpack-path
  99. #:build-flags ,build-flags
  100. #:tests? ,tests?
  101. #:inputs %build-inputs)))
  102. (define guile-for-build
  103. (match guile
  104. ((? package?)
  105. (package-derivation store guile system #:graft? #f))
  106. (#f ; the default
  107. (let* ((distro (resolve-interface '(gnu packages commencement)))
  108. (guile (module-ref distro 'guile-final)))
  109. (package-derivation store guile system
  110. #:graft? #f)))))
  111. (build-expression->derivation store name builder
  112. #:inputs inputs
  113. #:system system
  114. #:modules imported-modules
  115. #:outputs outputs
  116. #:guile-for-build guile-for-build))
  117. (define chicken-build-system
  118. (build-system
  119. (name 'chicken)
  120. (description
  121. "Build system for Chicken Scheme programs")
  122. (lower lower)))