chicken.scm 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #:export (%chicken-build-system-modules
  30. chicken-build
  31. chicken-build-system
  32. egg-uri))
  33. (define* (egg-uri name version #:optional (extension ".tar.gz"))
  34. "Return a URI string for the CHICKEN egg corresponding to NAME and VERSION.
  35. EXTENSION is the file name extension, such as '.tar.gz'."
  36. (string-append "https://code.call-cc.org/egg-tarballs/5/"
  37. name "/" name "-" version extension))
  38. (define %chicken-build-system-modules
  39. ;; Build-side modules imported and used by default.
  40. `((guix build chicken-build-system)
  41. (guix build union)
  42. ,@%gnu-build-system-modules))
  43. (define (default-chicken)
  44. ;; Lazily resolve the binding to avoid a circular dependency.
  45. ;; TODO is this actually needed in every build system?
  46. (let ((chicken (resolve-interface '(gnu packages chicken))))
  47. (module-ref chicken 'chicken)))
  48. (define* (lower name
  49. #:key source inputs native-inputs outputs system target
  50. (chicken (default-chicken))
  51. #:allow-other-keys
  52. #:rest arguments)
  53. "Return a bag for NAME."
  54. (define private-keywords
  55. '(#:target #:chicken #:inputs #:native-inputs))
  56. ;; TODO: cross-compilation support
  57. (and (not target)
  58. (bag
  59. (name name)
  60. (system system)
  61. (host-inputs `(,@(if source
  62. `(("source" ,source))
  63. '())
  64. ,@inputs
  65. ;; Keep the standard inputs of 'gnu-build-system', since
  66. ;; Chicken compiles Scheme by using C as an intermediate
  67. ;; language.
  68. ,@(standard-packages)))
  69. (build-inputs `(("chicken" ,chicken)
  70. ,@native-inputs))
  71. (outputs outputs)
  72. (build chicken-build)
  73. (arguments (strip-keyword-arguments private-keywords arguments)))))
  74. (define* (chicken-build name inputs
  75. #:key
  76. source
  77. (phases '%standard-phases)
  78. (outputs '("out"))
  79. (search-paths '())
  80. (egg-name "")
  81. (unpack-path "")
  82. (build-flags ''())
  83. (tests? #t)
  84. (system (%current-system))
  85. (guile #f)
  86. (imported-modules %chicken-build-system-modules)
  87. (modules '((guix build chicken-build-system)
  88. (guix build union)
  89. (guix build utils))))
  90. (define builder
  91. (with-imported-modules imported-modules
  92. #~(begin
  93. (use-modules #$@(sexp->gexp modules))
  94. (chicken-build #:name #$name
  95. #:source #+source
  96. #:system #$system
  97. #:phases #$phases
  98. #:outputs #$(outputs->gexp outputs)
  99. #:search-paths '#$(sexp->gexp
  100. (map search-path-specification->sexp
  101. search-paths))
  102. #:egg-name #$egg-name
  103. #:unpack-path #$unpack-path
  104. #:build-flags #$build-flags
  105. #:tests? #$tests?
  106. #:inputs #$(input-tuples->gexp inputs)))))
  107. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  108. system #:graft? #f)))
  109. (gexp->derivation name builder
  110. #:system system
  111. #:guile-for-build guile)))
  112. (define chicken-build-system
  113. (build-system
  114. (name 'chicken)
  115. (description
  116. "Build system for Chicken Scheme programs")
  117. (lower lower)))