unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob ae4407c9c9e6f9c465ebb8bb9511adeb2f3d912c 8914 bytes (raw)
name: guix/build-system/mix.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2023 Pierre-Henry Fröhring <phfrohring@deeplinks.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

;; Commentary:
;;
;; Standard build procedure for Elixir packages using 'mix'.  This is
;; implemented as an extension of 'gnu-build-system'.
;;
;; Code:

(define-module (guix build-system mix)
  #:use-module (gnu packages base)
  #:use-module (gnu packages elixir)
  #:use-module (gnu packages elixir-xyz)
  #:use-module (gnu packages erlang)
  #:use-module (guix build mix-build-system)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system)
  #:use-module (guix gexp)
  #:use-module (guix monads)
  #:use-module (guix packages)
  #:use-module (guix search-paths)
  #:use-module (guix store)
  #:use-module (guix utils)
  #:use-module (ice-9 match)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:export (mix-build-system hexpm-uri))

(define (hexpm-uri name version)
  "Return the URI where to fetch the sources of a Hex package NAME at VERSION.
See: https://github.com/hexpm/specifications/blob/main/endpoints.md"
  (string-append "https://repo.hex.pm/tarballs/"
                 (string-replace-substring (strip-elixir-prefix name) "-" "_")
                 "-" version ".tar"))

(define glibc-utf8-locales
  (make-glibc-utf8-locales glibc
                           #:locales (list "en_US")
                           #:name "glibc-utf8-locales"))

(define (default-elixir)
  "Return the default Elixir package."
  ;; Lazily resolve the binding to avoid a circular dependency.
  (let ((elixir (resolve-interface '(gnu packages elixir))))
    (module-ref elixir 'elixir)))

(define imported-modules
  `((guix build mix-build-system)
    ,@%gnu-build-system-modules))

(define modules
  '((guix build mix-build-system)
    (guix build utils)))

;; The prefix of Elixir packages.
(define %elixir-prefix "elixir-")

;; The prefix of Erlang packages.
(define %erlang-prefix "erlang-")

(define (erlang-package? package)
  "Tell whether PACKAGE is an Erlang package."
  (string-prefix? %erlang-prefix (package-name package)))

(define (elixir-package? package)
  "Tell whether PACKAGE is an Elixir package."
  (string-prefix? %elixir-prefix (package-name package)))

(define (erlang-or-elixir-pkg? package)
  "Tell whether PACKAGE is an Elixir or an Erlang package."
  (or (erlang-package? package)
      (elixir-package? package)))

(define (erlang-or-elixir-input? input)
  "Tell whether INPUT is an Elixir or an Erlang input."
  (match input
    ((_ package)
     (erlang-or-elixir-pkg? package))))

(define (input=? input1 input2)
  "Tell whether inputs INPUT1 and INPUT2 are equal."
  (define pkg1 (match input1 ((_ pkg) pkg)))
  (define pkg2 (match input2 ((_ pkg) pkg)))
  (string=? (package-name pkg1) (package-name pkg2)))

;; A number of environment variables specific to the Mix build system are reflected here.
;; They are documented here: https://hexdocs.pm/mix/1.15.7/Mix.html#module-environment-variables.
;; Other parameters located in mix.exs are defined here:
;; https://hexdocs.pm/mix/1.15.7/Mix.Project.html#module-configuration
(define* (mix-build name
                    inputs
                    #:key
                    source
                    elixir-X.Y ;The major and minor of Elixir.
                    (tests? #t)
                    (mix-path #f) ;See MIX_PATH.
                    (mix-exs "mix.exs") ;See MIX_EXS.
                    (build-per-environment #t) ;See :build_per_environment.
                    (phases '%standard-phases)
                    (outputs '("out"))
                    (search-paths '())
                    (system (%current-system))
                    (guile #f)
                    (imported-modules imported-modules)
                    (modules modules))
  "Build SOURCE using Elixir, and with INPUTS."

  ;; Check the documentation of :build_per_environment here:
  ;; https://hexdocs.pm/mix/1.15.7/Mix.Project.html#module-configuration And
  ;; "Environments" here:
  ;; https://hexdocs.pm/mix/1.15.7/Mix.html#module-environments
  (define mix-environments
    (if build-per-environment
        `("prod" ,@(if tests? '("test") '()))
        '("shared")))

  (define builder
    (with-imported-modules imported-modules
      #~(begin

          (use-modules #$@(sexp->gexp modules))

          #$(with-build-variables inputs outputs
              #~(mix-build #:name #$name
                           #:source #+source
                           #:system #$system
                           #:tests? #$tests?
                           #:mix-path #$mix-path
                           #:mix-exs #$mix-exs
                           #:elixir-X.Y #$elixir-X.Y
                           #:mix-environments '#$mix-environments
                           #:build-per-environment #$build-per-environment
                           #:phases #$(if (pair? phases)
                                          (sexp->gexp phases)
                                          phases)
                           #:outputs %outputs
                           #:search-paths '#$(sexp->gexp
                                              (map
                                               search-path-specification->sexp
                                               search-paths))
                           #:inputs
                           %build-inputs)))))

  (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
                                                  system
                                                  #:graft? #f)))
    (gexp->derivation name
                      builder
                      #:system system
                      #:graft? #f       ;consistent with 'gnu-build'
                      #:target #f
                      #:guile-for-build guile)))

(define* (lower name
                #:key
                source
                (inputs '())
                (tests? #t)
                (native-inputs '())
                (propagated-inputs '())
                outputs
                system
                target
                (elixir (default-elixir))
                #:allow-other-keys #:rest arguments)
  "Return a bag for NAME."
  (define private-keywords
    '(#:inputs #:native-inputs #:outputs #:system #:target #:elixir))

  ;; Libraries are compiled using a given version of Elixir. This fact is
  ;; encoded by the name of a sub-directory like lib/elixir/X.Y. We compute
  ;; the value of X.Y here which is valid for the whole build.
  (define elixir-X.Y (version-major+minor (package-version elixir)))

  ;; Elixir depends on a specific version of Erlang, this one.
  (define erlang (lookup-package-input elixir "erlang"))

  ;; For mix to compile and test a package, it needs to find all inputs,
  ;; native-inputs and propagated-inputs (including the transitive ones) under
  ;; _build directories like _build/prod/lib.
  ;;
  ;; Given inputs and native-inputs of the package, we need to compute the
  ;; transitive closure of all Erlang and Elixir propagated inputs and add
  ;; them to the build inputs.
  (define all-propagated-inputs
    ((compose
      (cut delete-duplicates <> input=?)
      (cut filter erlang-or-elixir-input? <>)
      (cut append-map package-transitive-propagated-inputs <>)
      (cut map cadr <>))
     (append inputs native-inputs)))

  (define build-inputs
    `(,@(standard-packages)
      ("glibc-utf8-locales" ,glibc-utf8-locales)
      ("erlang" ,erlang)
      ("rebar3" ,rebar3)
      ("elixir" ,elixir)
      ("elixir-hex" ,elixir-hex)
      ,@all-propagated-inputs
      ,@inputs
      ,@native-inputs))

  ;; Some inputs, such as C programs, may be architecture dependent.
  (define host-inputs (if target inputs '()))

  (bag (name name)
       (system system)
       (build-inputs build-inputs)
       (host-inputs host-inputs)
       (outputs outputs)
       (build mix-build)
       (arguments (append `(#:elixir-X.Y ,elixir-X.Y)
                          (strip-keyword-arguments private-keywords arguments)))))

(define mix-build-system
  (build-system (name 'mix)
                (description "The standard Mix build system")
                (lower lower)))

;;; mix.scm ends here

debug log:

solving ae4407c9 ...
found ae4407c9 in https://yhetil.org/guix-patches/26ef9c0f4bf2ff942ba2b42e1fadeb6174bbaa6a.1699906775.git.phfrohring@deeplinks.com/

applying [1/1] https://yhetil.org/guix-patches/26ef9c0f4bf2ff942ba2b42e1fadeb6174bbaa6a.1699906775.git.phfrohring@deeplinks.com/
diff --git a/guix/build-system/mix.scm b/guix/build-system/mix.scm
new file mode 100644
index 00000000..ae4407c9

Checking patch guix/build-system/mix.scm...
Applied patch guix/build-system/mix.scm cleanly.

index at:
100644 ae4407c9c9e6f9c465ebb8bb9511adeb2f3d912c	guix/build-system/mix.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).