chicken.scm 4.6 KB

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