Commit | Line | Data |
---|---|---|
65e862d1 DM |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org> | |
3 | ;;; Copyright © 2013 Andreas Enge <andreas@enge.fr> | |
4 | ;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org> | |
5 | ;;; Copyright © 2016 David Craven <david@craven.ch> | |
6 | ;;; Copyright © 2016 Danny Milosavljevic <dannym@scratchpost.org> | |
7 | ;;; | |
8 | ;;; This file is part of GNU Guix. | |
9 | ;;; | |
10 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
11 | ;;; under the terms of the GNU General Public License as published by | |
12 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
13 | ;;; your option) any later version. | |
14 | ;;; | |
15 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
16 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;;; GNU General Public License for more details. | |
19 | ;;; | |
20 | ;;; You should have received a copy of the GNU General Public License | |
21 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
22 | ||
23 | (define-module (guix build-system dub) | |
24 | #:use-module (guix search-paths) | |
25 | #:use-module (guix store) | |
26 | #:use-module (guix utils) | |
27 | #:use-module (guix derivations) | |
28 | #:use-module (guix packages) | |
29 | #:use-module (guix build-system) | |
30 | #:use-module (guix build-system gnu) | |
31 | #:use-module (ice-9 match) | |
32 | #:use-module (srfi srfi-26) | |
33 | #:export (dub-build-system)) | |
34 | ||
35 | (define (default-ldc) | |
36 | "Return the default ldc package." | |
37 | ;; Lazily resolve the binding to avoid a circular dependency. | |
875d0681 | 38 | (let ((ldc (resolve-interface '(gnu packages dlang)))) |
65e862d1 DM |
39 | (module-ref ldc 'ldc))) |
40 | ||
41 | (define (default-dub) | |
42 | "Return the default dub package." | |
43 | ;; Lazily resolve the binding to avoid a circular dependency. | |
875d0681 | 44 | (let ((ldc (resolve-interface '(gnu packages dlang)))) |
65e862d1 DM |
45 | (module-ref ldc 'dub))) |
46 | ||
47 | (define (default-pkg-config) | |
48 | "Return the default pkg-config package." | |
49 | ;; Lazily resolve the binding to avoid a circular dependency. | |
50 | (let ((pkg-config (resolve-interface '(gnu packages pkg-config)))) | |
51 | (module-ref pkg-config 'pkg-config))) | |
52 | ||
53 | (define %dub-build-system-modules | |
54 | ;; Build-side modules imported by default. | |
55 | `((guix build dub-build-system) | |
56 | (guix build syscalls) | |
57 | ,@%gnu-build-system-modules)) | |
58 | ||
59 | (define* (dub-build store name inputs | |
60 | #:key | |
61 | (tests? #t) | |
62 | (test-target #f) | |
63 | (dub-build-flags ''()) | |
64 | (phases '(@ (guix build dub-build-system) | |
65 | %standard-phases)) | |
66 | (outputs '("out")) | |
67 | (search-paths '()) | |
68 | (system (%current-system)) | |
69 | (guile #f) | |
70 | (imported-modules %dub-build-system-modules) | |
71 | (modules '((guix build dub-build-system) | |
72 | (guix build utils)))) | |
73 | "Build SOURCE using DUB, and with INPUTS." | |
74 | (define builder | |
75 | `(begin | |
76 | (use-modules ,@modules) | |
77 | (dub-build #:name ,name | |
78 | #:source ,(match (assoc-ref inputs "source") | |
79 | (((? derivation? source)) | |
80 | (derivation->output-path source)) | |
81 | ((source) | |
82 | source) | |
83 | (source | |
84 | source)) | |
85 | #:system ,system | |
86 | #:test-target ,test-target | |
87 | #:dub-build-flags ,dub-build-flags | |
88 | #:tests? ,tests? | |
89 | #:phases ,phases | |
90 | #:outputs %outputs | |
91 | #:search-paths ',(map search-path-specification->sexp | |
92 | search-paths) | |
93 | #:inputs %build-inputs))) | |
94 | ||
95 | (define guile-for-build | |
96 | (match guile | |
97 | ((? package?) | |
98 | (package-derivation store guile system #:graft? #f)) | |
99 | (#f ; the default | |
100 | (let* ((distro (resolve-interface '(gnu packages commencement))) | |
101 | (guile (module-ref distro 'guile-final))) | |
102 | (package-derivation store guile system #:graft? #f))))) | |
103 | ||
104 | (build-expression->derivation store name builder | |
105 | #:inputs inputs | |
106 | #:system system | |
107 | #:modules imported-modules | |
108 | #:outputs outputs | |
109 | #:guile-for-build guile-for-build)) | |
110 | ||
111 | (define* (lower name | |
112 | #:key source inputs native-inputs outputs system target | |
113 | (ldc (default-ldc)) | |
114 | (dub (default-dub)) | |
115 | (pkg-config (default-pkg-config)) | |
116 | #:allow-other-keys | |
117 | #:rest arguments) | |
118 | "Return a bag for NAME." | |
119 | ||
120 | (define private-keywords | |
121 | '(#:source #:target #:ldc #:dub #:pkg-config #:inputs #:native-inputs #:outputs)) | |
122 | ||
123 | (and (not target) ;; TODO: support cross-compilation | |
124 | (bag | |
125 | (name name) | |
126 | (system system) | |
127 | (target target) | |
128 | (host-inputs `(,@(if source | |
129 | `(("source" ,source)) | |
130 | '()) | |
131 | ,@inputs | |
132 | ||
133 | ;; Keep the standard inputs of 'gnu-build-system' | |
134 | ,@(standard-packages))) | |
135 | (build-inputs `(("ldc" ,ldc) | |
136 | ("dub" ,dub) | |
137 | ,@native-inputs)) | |
138 | (outputs outputs) | |
139 | (build dub-build) | |
140 | (arguments (strip-keyword-arguments private-keywords arguments))))) | |
141 | ||
142 | (define dub-build-system | |
143 | (build-system | |
144 | (name 'dub) | |
145 | (description | |
146 | "DUB build system, to build D packages") | |
147 | (lower lower))) |