about summary refs log tree commit diff
path: root/gn/packages/julia-source.scm
blob: 65230d324ab11d4f57270d557abc36e2ba2d692e (plain)
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
;;; guix-bioinformatics --- Julia built from source (1.10)
;;; Copyright © 2026 the GeneNetwork team

;;; A from-source build of Julia 1.10, alongside the Guix `julia` (1.8.5).
;;; Julia 1.10 needs LLVM 15 and libgit2 1.6 (both in the tree), and its
;;; deps stage fetches three source tarballs (the Julia LLVM fork,
;;; JuliaSyntax and ittapi) that 1.8 did not.  The Guix build sandbox has
;;; no network, so those are provided as origins and copied into
;;; deps/srccache/, where Julia's build expects them (the tarballs match
;;; the checksums recorded in deps/checksums/).

(define-module (gn packages julia-source)
  #:use-module (gnu packages)
  #:use-module (gnu packages cmake)
  #:use-module (gnu packages julia)
  #:use-module (gnu packages llvm)
  #:use-module (gnu packages version-control)
  #:use-module (guix download)
  #:use-module (guix gexp)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:export (julia-1.10 llvm-julia-15))

(define-public llvm-julia-15
  ;; LLVM 15 built the way Julia wants it: a shared LLVM dylib with the
  ;; "jl" suffix, targetting the host architecture.
  (package
    (inherit llvm-15)
    (arguments
     (substitute-keyword-arguments (package-arguments llvm-15)
       ((#:configure-flags flags ''())
        #~(cons* "-DLLVM_BUILD_LLVM_DYLIB=ON"
                 "-DLLVM_LINK_LLVM_DYLIB=ON"
                 "-DLLVM_VERSION_SUFFIX:STRING=jl"
                 #$(string-append "-DLLVM_TARGETS_TO_BUILD="
                                  (system->llvm-target))
                 (delete "-DBUILD_SHARED_LIBS:BOOL=TRUE" #$flags)))
       ((#:build-type _) "Release")))
    (properties `((hidden? . #t)
                  ,@(package-properties llvm-15)))))

;; The source tarballs Julia's deps stage would download.
(define ittapi-source
  (origin
    (method url-fetch)
    (uri (string-append "https://api.github.com/repos/intel/ittapi/tarball/"
                        "0014aec56fea2f30c1374f40861e1bccdd53d0cb"))
    (file-name "ittapi-0014aec56fea2f30c1374f40861e1bccdd53d0cb.tar.gz")
    (sha256
     (base32 "0v1csylisfa7mkpr3hsl64y2pm1brkzx221412x1rb69qfk8da06"))))

(define juliasyntax-source
  (origin
    (method url-fetch)
    (uri (string-append "https://api.github.com/repos/JuliaLang/JuliaSyntax.jl"
                        "/tarball/4f1731d6ce7c2465fc21ea245110b7a39f34658a"))
    (file-name "JuliaSyntax-4f1731d6ce7c2465fc21ea245110b7a39f34658a.tar.gz")
    (sha256
     (base32 "1nj4nr6p2lg4s0b1mia8grd843cza8zidv7wi5l7c7q3d4l0pv9a"))))

(define llvm-julia-source
  (origin
    (method url-fetch)
    (uri "https://api.github.com/repos/JuliaLang/llvm-project/tarball/julia-15.0.7-10")
    (file-name "llvm-julia-15.0.7-10.tar.gz")
    (sha256
     (base32 "0xwwhc5b6k6vawxrbrf52f5fpmxzg7yqwglrysy7f8dhvpfsl857"))))

(define-public julia-1.10
  (package
    (inherit julia)
    (version "1.10.9")
    (source
     (origin
       (method url-fetch)
       (uri (string-append
             "https://github.com/JuliaLang/julia/releases/download/v"
             version "/julia-" version ".tar.gz"))
       (sha256
        (base32 "0jwmdqrkidpilnzvjrpmk0x5j745xlkjwd9q1glwfx127nkhc0kq"))))
    (arguments
     (substitute-keyword-arguments (package-arguments julia)
       ((#:phases phases)
        #~(modify-phases #$phases
            (add-after 'unpack 'patch-cmake-policy
              ;; CMake 4 dropped compatibility with cmake_minimum_required
              ;; < 3.5, which ittapi still uses.
              (lambda _
                (substitute* "deps/ittapi.mk"
                  (("-DITT_API_FORTRAN_SUPPORT=0")
                   "-DITT_API_FORTRAN_SUPPORT=0 -DCMAKE_POLICY_VERSION_MINIMUM=3.5"))))
            (add-after 'unpack 'no-suite-sparse-cuda
              ;; Julia 1.10 expects the CUDA-only SuiteSparse libraries
              ;; (libcholmod_cuda/libspqr_cuda), which Guix's SuiteSparse
              ;; does not build.  They are optional; drop them.
              (lambda _
                (substitute* "base/Makefile"
                  (("^.*libcholmod_cuda.*$") "")
                  (("^.*libspqr_cuda.*$") ""))
                (substitute* "Makefile"
                  (("libcholmod_cuda libspqr_cuda ") ""))))
            (add-after 'unpack 'fix-cplus-include-path
              ;; The build environment leaks a CPLUS_INCLUDE_PATH listing
              ;; every input's include dir (including the top-level
              ;; libstdc++ "include/c++"), which shadows the C headers
              ;; (<fenv.h>, <stdlib.h>) and breaks the LLVM build.  The
              ;; build passes the needed include dirs explicitly, so drop
              ;; the variables.
              (lambda _
                (for-each (lambda (var)
                            (when (getenv var) (unsetenv var)))
                          '("CPLUS_INCLUDE_PATH" "OBJCPLUS_INCLUDE_PATH"))))
            (add-after 'unpack 'seed-srccache
              (lambda* (#:key inputs #:allow-other-keys)
                (mkdir-p "deps/srccache")
                (copy-file (assoc-ref inputs "ittapi-src")
                           "deps/srccache/ittapi-0014aec56fea2f30c1374f40861e1bccdd53d0cb.tar.gz")
                (copy-file (assoc-ref inputs "llvm-julia-src")
                           "deps/srccache/llvm-julia-15.0.7-10.tar.gz")
                (copy-file (assoc-ref inputs "juliasyntax-src")
                           "deps/srccache/JuliaSyntax-4f1731d6ce7c2465fc21ea245110b7a39f34658a.tar.gz")))))))
    (inputs
     (modify-inputs (package-inputs julia)
       (replace "llvm" llvm-julia-15)
       (replace "libgit2" libgit2-1.6)))
    (native-inputs
     (append (package-native-inputs julia)
             (list `("cmake" ,cmake)
                   `("ittapi-src" ,ittapi-source)
                   `("llvm-julia-src" ,llvm-julia-source)
                   `("juliasyntax-src" ,juliasyntax-source))))))