123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- (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)
- #:use-module (ice-9 regex)
- #:use-module (ice-9 rdelim)
- #:export (%standard-phases
- julia-create-package-toml
- julia-build))
- (define (invoke-julia code)
- (invoke "julia" "-e" code))
- (define %package-path "/share/julia/packages/")
- (define (project.toml->name file)
- "Look for Julia package name in the TOML file FILE (usually named
- Project.toml)."
- (call-with-input-file file
- (lambda (in)
- (let loop ((line (read-line in 'concat)))
- (if (eof-object? line)
- #f
- (let ((m (string-match "name\\s*=\\s*\"(.*)\"" line)))
- (if m (match:substring m 1)
- (loop (read-line in 'concat)))))))))
- (define* (install #:key source inputs outputs julia-package-name
- #:allow-other-keys)
- (let* ((out (assoc-ref outputs "out"))
- (package-dir (string-append out %package-path
- (or
- julia-package-name
- (project.toml->name "Project.toml")))))
- (mkdir-p package-dir)
- (copy-recursively (getcwd) package-dir))
- #t)
- (define* (precompile #:key source inputs outputs julia-package-name
- #:allow-other-keys)
- (let* ((out (assoc-ref outputs "out"))
- (builddir (string-append out "/share/julia/"))
- (package (or julia-package-name (project.toml->name "Project.toml"))))
- (mkdir-p builddir)
-
- (setenv "SOURCE_DATE_EPOCH" "1")
- (setenv "JULIA_DEPOT_PATH" builddir)
-
- (setenv "JULIA_LOAD_PATH"
- (string-append builddir "packages/" ":"
- (or (getenv "JULIA_LOAD_PATH")
- "")))
-
- (invoke-julia
-
-
-
-
-
-
- (string-append "pushfirst!(DEPOT_PATH, pop!(DEPOT_PATH)); using " package)))
- #t)
- (define* (check #:key tests? source inputs outputs julia-package-name
- #:allow-other-keys)
- (when tests?
- (let* ((out (assoc-ref outputs "out"))
- (package (or julia-package-name (project.toml->name "Project.toml")))
- (builddir (string-append out "/share/julia/")))
-
- (setenv "SOURCE_DATE_EPOCH" "1")
- (setenv "JULIA_DEPOT_PATH" builddir)
- (setenv "JULIA_LOAD_PATH"
- (string-append builddir "packages/" ":"
- (or (getenv "JULIA_LOAD_PATH")
- "")))
- (setenv "HOME" "/tmp")
- (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)
- (replace 'install install)
- (add-after 'install 'precompile precompile)
- (add-after 'install 'check check)
-
-
- (delete 'configure)
- (delete 'bootstrap)
- (delete 'patch-usr-bin-file)
- (delete 'build)))
- (define* (julia-build #:key inputs julia-package-name
- (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
- #:julia-package-name julia-package-name
- args))
|