unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob bd4c64fa110d45866ba7a83bd62318d8a0a95364 5757 bytes (raw)
name: guix/build/julia-build-system.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
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2019 Nicolò Balzarotti <nicolo@nixo.xyz>
;;;
;;; 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/>.


(define-module (guix build julia-build-system)
  #:use-module ((guix build gnu-build-system) #:prefix gnu:)
  #:use-module (guix build utils)
  #:use-module (ice-9 match)
  #:export (%standard-phases
            julia-create-package-toml
            julia-build))

;; Commentary:
;;
;; Builder-side code of the standard build procedure for Julia packages.
;;
;; Code:

(define (invoke-julia code)
  ;; Julia stores the result of the time() call
  ;; inside the precompiled file. When trying to load it, its precompilation
  ;; it fails at comparing the file mtime with the precompilation time,
  ;; always triggering a recompile. This fixes the stored value.
  ;; Also, libc.jl rand() uses time() as its seed. This might introduce indeterminism while building
  ;; Default guix mtime is 1, so I'm setting the same here (if they differ, precompilation is invalid)
  (invoke "faketime" "-f" "1970-01-01 00:00:01" "julia" "-e" code))

;; subpath where we store the package content
(define %package-path "/share/julia/packages/")

(define (generate-load-path inputs outputs)
  (string-append
   (string-join (map (match-lambda
                       ((_ . path)
                        (string-append path %package-path)))
                     ;; Restrict to inputs beginning with "julia-".
                     (filter (match-lambda
                               ((name . _)
                                (string-prefix? "julia-" name)))
                             inputs))
                ":")
   (string-append ":" (assoc-ref outputs "out") %package-path)
   ;; stdlib is always required to find Julia's standard libraries.
   ;; usually there are other two paths in this variable:
   ;; "@" and "@v#.#"
   ":@stdlib"))

(define* (install #:key source inputs outputs #:allow-other-keys)
  (let* ((out (assoc-ref outputs "out"))
         (package-dir (string-append out %package-path
                                     (string-append
                                      (strip-store-file-name source)))))
    (setenv "JULIA_LOAD_PATH" (generate-load-path inputs outputs))
    (mkdir-p package-dir)
    (copy-recursively source package-dir))
  #t)

;; TODO: Precompilation is working, but I don't know how to tell
;; julia to use use it. If (on rantime) we set HOME to
;; store path, julia tries to write files there (failing)
(define* (precompile #:key source inputs outputs #:allow-other-keys)
  (let* ((out (assoc-ref outputs "out"))
         (builddir (string-append out "/share/julia/"))
         (package (strip-store-file-name source)))
    (mkdir-p builddir)
    (setenv "JULIA_DEPOT_PATH" builddir)
    (setenv "JULIA_LOAD_PATH" (generate-load-path inputs outputs))
    ;; Actual precompilation
    (invoke-julia (string-append "using " package)))
  #t)

(define* (check #:key tests? source inputs outputs #:allow-other-keys)
  (when tests?
      (let* ((out (assoc-ref outputs "out"))
             (package (strip-store-file-name source))
             (builddir (string-append out "/share/julia/")))
        (setenv "JULIA_DEPOT_PATH" builddir)
        (setenv "JULIA_LOAD_PATH" (generate-load-path inputs outputs))
        (display builddir)
        (invoke "julia" (string-append builddir
                                       "packages/"
                                       package "/test/runtests.jl"))))
  #t)

(define (julia-create-package-toml outputs source
                                   name uuid version
                                   deps)
  "Some packages are not using the new Package.toml dependency specifications.
Write this file manually, so that Julia can find its dependencies."
  (let ((f (open-file
            (string-append
             (assoc-ref outputs "out")
             %package-path
             (string-append
              name "/Project.toml"))
            "w")))
    (display (string-append
              "
name = \"" name "\"
uuid = \"" uuid "\"
version = \"" version "\"
") f)
    (when (not (null? deps))
      (display "[deps]\n" f)
      (for-each (lambda dep
                  (display (string-append (car (car dep)) " = \"" (cdr (car dep)) "\"\n")
                           f))
                deps))
    (close-port f))
  #t)

(define %standard-phases
  (modify-phases gnu:%standard-phases
    (delete 'check) ; tests must be run after installation
    (replace 'install install)
    (add-after 'install 'precompile precompile)
    (add-after 'install 'check check)
    ;; TODO: In the future we could add a "system-image-generation" phase
    ;; where we use PackageCompiler.jl to speed up package loading times
    (delete 'configure)
    (delete 'bootstrap)
    (delete 'patch-usr-bin-file)
    (delete 'build)))

(define* (julia-build #:key inputs (phases %standard-phases)
                      #:allow-other-keys #:rest args)
  "Build the given Julia package, applying all of PHASES in order."
  (apply gnu:gnu-build
         #:inputs inputs #:phases phases
         args))

debug log:

solving bd4c64fa11 ...
found bd4c64fa11 in https://yhetil.org/guix-patches/87sgltvbs1.fsf@guixSD.i-did-not-set--mail-host-address--so-tickle-me/
found ff6fcf5fe3 in https://git.savannah.gnu.org/cgit/guix.git
preparing index
index prepared:
100644 ff6fcf5fe3ba61a795a6acd040724403dde1418b	guix/build/julia-build-system.scm

applying [1/1] https://yhetil.org/guix-patches/87sgltvbs1.fsf@guixSD.i-did-not-set--mail-host-address--so-tickle-me/
diff --git a/guix/build/julia-build-system.scm b/guix/build/julia-build-system.scm
index ff6fcf5fe3..bd4c64fa11 100644

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

index at:
100644 bd4c64fa110d45866ba7a83bd62318d8a0a95364	guix/build/julia-build-system.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).