Julia's built-in package manager (Pkg) looks for packages in JULIA_DEPOT_PATH/packages/PACKAGENAME/XXXX, where XXXX is a string encoding package UUID and SHA1 of files. The link-depot phase creates a link at the correct location to allow Pkg to find packages that were already installed by Guix. * guix/build/julia-build-system.scm (link-depot): New phase. (%package-path): Modified package path from packages/ to loadpath/. (project.toml->uuid): New procedure, retrive package uuid from TOML file. (precompile, check): Adjust to the change in paths. (%standard-phases): Add link-depot phase. (julia-build): Add julia-package-uuid keyword. * guix/build-system/julia.scm (julia-build): Also use the julia-package-uuid keyword. * gnu/packages/julia-jll.scm (julia-bzip2-jll, julia-cairo-jll, julia-compilersupportlibraries-jll, julia-expat-jll, julia-ffmpeg-jll, julia-fontconfig-jll, julia-freetype2-jll, julia-fribidi-jll, julia-gettext-jll, julia-glib-jll, julia-gr-jll, julia-gumbo-jll, julia-imagemagick-jll, julia-jllwrappers-jll, julia-jpegturbo-jll, julia-lame-jll, julia-libass-jll, julia-libfdk-aac-jll, julia-libffi-jll, julia-libgcrypt-jll, julia-libglvnd-jll, julia-libgpg-error-jll, juli-libiconv-jll, julia-libmount-jll, julia-libpng-jll, julia-libsass-jll, julia-libtiff-jll, julia-libuuid-jll, julia-libvorbis-jll, julia-lzo-jll, julia-mbedtls-jll, julia-ogg-jll, julia-openspecfun-jll, julia-openssl-jll, julia-opus-jll, julia-pcre-jll, julia-pixman-jll, julia-qt5base-jll, julia-wayland-jll, julia-wayland-protocols-jll, julia-x264-jll, julia-x265-jll, julia-xkbcommon-jll, julia-xml2-jll, julia-xorg-libpthread-stubs-jll, julia-xorg-libx11-jll, julia-xorg-libxau-jll, julia-xorg-libxcb-jll, julia-xorg-libxcursor-jll, julia-xorg-libxdmcp-jll, julia-xorg-libxext-jll, julia-xorg-libxfixes-jll, julia-xorg-libxi-jll, julia-xorg-libxinerama-jll, julia-xorg-libxkbfile-jll, julia-xorg-libxrandr-jll, julia-xorg-libxrender-jll, julia-xorg-xcb-util-jll, julia-xorg-xcb-util-keysyms-jll, julia-xorg-xcb-util-renderutil-jll, julia-xorg-xcb-util-wm-jll, julia-xorg-xkbcomp-jll, julia-xorg-xkeyboard-config-jll, julia-xorg-xtrans-jll, julia-xslt-jll, julia-zlib-jll, julia-zstd-jll) [argument]: Adjust the order of the phases to the change in the julia-build-system. * gnu/packages/julia-xyz.scm (julia-bufferedstreams, julia-calculus, julia-dataframes, julia-datavalues, julia-distances, julia-documenter, julia-dualnumbers, julia-ellipsisnotation, julia-expronicon, julia-fileio, julia-fixedpointnumbers, julia-functionwrappers, julia-fuzzycompletions, julia-genericlinearalgebra, julia-genericschur, julia-geometrybasics, julia-imagemagick, julia-infinity, julia-matrixfactorizations, julia-media, julia-missings, julia-nnlib, julia-optimtestproblems, julia-orderedcollections, julia-prettytables, julia-pycall, julia-quadmath, julia-safetests, julia-stackviews) [arguments]: Correct paths to reflect change of %package-path modify order of phases as link-depot needs to run on an unmodified src directory add package-name-uuid keyword argument to packages without Project.toml file. * gnu/packages/julia.scm (julia)[native-search-paths]: Correct paths to reflect change of %package-path modify order of phases as link-depot needs to run on an unmodified src directory. Signed-off-by: Efraim Flashner <efraim@flashner.co.il>
195 lines
7.7 KiB
Scheme
195 lines
7.7 KiB
Scheme
;;; GNU Guix --- Functional package management for GNU
|
|
;;; Copyright © 2019, 2020 Nicolò Balzarotti <nicolo@nixo.xyz>
|
|
;;; Copyright © 2021 Jean-Baptiste Volatier <jbv@pm.me>
|
|
;;;
|
|
;;; 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 (rnrs io ports)
|
|
#:use-module (ice-9 match)
|
|
#:use-module (ice-9 regex)
|
|
#:use-module (ice-9 rdelim)
|
|
#:use-module (ice-9 popen)
|
|
#: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)
|
|
(invoke "julia" "-e" code))
|
|
|
|
;; subpath where we store the package content
|
|
(define %package-path "/share/julia/loadpath/")
|
|
|
|
(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 (project.toml->uuid file)
|
|
"Look for Julia package uuid 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 "uuid\\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)
|
|
;; With a patch, SOURCE_DATE_EPOCH is honored
|
|
(setenv "SOURCE_DATE_EPOCH" "1")
|
|
(setenv "JULIA_DEPOT_PATH" builddir)
|
|
;; Add new package dir to the load path.
|
|
(setenv "JULIA_LOAD_PATH"
|
|
(string-append builddir "loadpath/" ":"
|
|
(or (getenv "JULIA_LOAD_PATH")
|
|
"")))
|
|
;; Actual precompilation:
|
|
(invoke-julia
|
|
;; When using Julia as a user, Julia writes precompile cache to the first
|
|
;; entry of the DEPOT_PATH list (by default, the home dir). We want to
|
|
;; write it to the store, so let's push the store path as the first
|
|
;; element of DEPOT_PATH. Once the cache file exists, this hack is not
|
|
;; needed anymore (like in the check phase). If the user install new
|
|
;; packages, those will be installed and precompiled in the home dir.
|
|
(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/")))
|
|
;; With a patch, SOURCE_DATE_EPOCH is honored
|
|
(setenv "SOURCE_DATE_EPOCH" "1")
|
|
(setenv "JULIA_DEPOT_PATH" builddir)
|
|
(setenv "JULIA_LOAD_PATH"
|
|
(string-append builddir "loadpath/" ":"
|
|
(or (getenv "JULIA_LOAD_PATH")
|
|
"")))
|
|
(setenv "HOME" "/tmp")
|
|
(invoke "julia" "--depwarn=yes"
|
|
(string-append builddir "loadpath/"
|
|
package "/test/runtests.jl"))))
|
|
#t)
|
|
|
|
(define* (link-depot #:key source inputs outputs julia-package-name julia-package-uuid
|
|
#:allow-other-keys)
|
|
(let* ((out (assoc-ref outputs "out"))
|
|
(package-name (or
|
|
julia-package-name
|
|
(project.toml->name "Project.toml")))
|
|
(package-dir (string-append out %package-path package-name))
|
|
(uuid (or julia-package-uuid (project.toml->uuid "Project.toml")))
|
|
(pipe (open-pipe* OPEN_READ "julia" "-e"
|
|
(format #f "using Pkg;
|
|
println(Base.version_slug(Base.UUID(\"~a\"),
|
|
Base.SHA1(Pkg.GitTools.tree_hash(\".\"))))" uuid)))
|
|
(slug (string-trim-right (get-string-all pipe))))
|
|
;; When installing a package, julia looks first at in the JULIA_DEPOT_PATH
|
|
;; for a path like packages/PACKAGE/XXXX
|
|
;; Where XXXX is a slug encoding the package UUID and SHA1 of the files
|
|
;; Here we create a link with the correct path to enable julia to find the package
|
|
(mkdir-p (string-append out "/share/julia/packages/" package-name))
|
|
(symlink package-dir (string-append out "/share/julia/packages/" package-name "/" slug)))
|
|
#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 'unpack 'link-depot link-depot)
|
|
(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 julia-package-name julia-package-uuid
|
|
(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
|
|
#:julia-package-uuid julia-package-uuid
|
|
args))
|