Merge pull request #119126 from fabaff/pycomfoconnect
[NixPkgs.git] / pkgs / development / compilers / julia / 1.5.nix
blobb4c33faa44cd1ea066ed4de3fa19816c5a69cdb9
1 { lib, stdenv, fetchzip
2 # build tools
3 , gfortran, m4, makeWrapper, patchelf, perl, which, python2, cmake
4 # libjulia dependencies
5 , libunwind, readline, utf8proc, zlib
6 # standard library dependencies
7 , curl, fftwSinglePrec, fftw, libgit2, mpfr, openlibm, openspecfun, pcre2
8 # linear algebra
9 , blas, lapack, arpack
10 # Darwin frameworks
11 , CoreServices, ApplicationServices
14 assert (!blas.isILP64) && (!lapack.isILP64);
16 with lib;
18 let
19   majorVersion = "1";
20   minorVersion = "5";
21   maintenanceVersion = "4";
22   src_sha256 = "1ba1v7hakgj95xvhyff0zcp0574qv6vailjl48wl1f8w5k54lsw2";
23   version = "${majorVersion}.${minorVersion}.${maintenanceVersion}";
26 stdenv.mkDerivation rec {
27   pname = "julia";
28   inherit version;
30   src = fetchzip {
31     url = "https://github.com/JuliaLang/julia/releases/download/v${version}/julia-${version}-full.tar.gz";
32     sha256 = src_sha256;
33   };
35   patches = [
36     ./use-system-utf8proc-julia-1.3.patch
38     # Julia recompiles a precompiled file if the mtime stored *in* the
39     # .ji file differs from the mtime of the .ji file.  This
40     # doesn't work in Nix because Nix changes the mtime of files in
41     # the Nix store to 1. So patch Julia to accept mtimes of 1.
42     ./allow_nix_mtime.patch
43   ];
45   postPatch = ''
46     patchShebangs . contrib
47     for i in backtrace cmdlineargs; do
48       mv test/$i.jl{,.off}
49       touch test/$i.jl
50     done
51     rm stdlib/Sockets/test/runtests.jl && touch stdlib/Sockets/test/runtests.jl
52     rm stdlib/Distributed/test/runtests.jl && touch stdlib/Distributed/test/runtests.jl
53     # LibGit2 fails with a weird error, so we skip it as well now
54     rm stdlib/LibGit2/test/runtests.jl && touch stdlib/LibGit2/test/runtests.jl
55     sed -e 's/Invalid Content-Type:/invalid Content-Type:/g' -i ./stdlib/LibGit2/test/libgit2.jl
56     sed -e 's/Failed to resolve /failed to resolve /g' -i ./stdlib/LibGit2/test/libgit2.jl
57   '';
59   dontUseCmakeConfigure = true;
61   buildInputs = [
62     arpack fftw fftwSinglePrec libgit2 libunwind mpfr
63     pcre2.dev blas lapack openlibm openspecfun readline utf8proc
64     zlib
65   ] ++ lib.optionals stdenv.isDarwin [CoreServices ApplicationServices];
67   nativeBuildInputs = [ curl gfortran m4 makeWrapper patchelf perl python2 which cmake ];
69   makeFlags =
70     let
71       arch = head (splitString "-" stdenv.system);
72       march = {
73         x86_64 = stdenv.hostPlatform.gcc.arch or "x86-64";
74         i686 = "pentium4";
75         aarch64 = "armv8-a";
76       }.${arch}
77               or (throw "unsupported architecture: ${arch}");
78       # Julia requires Pentium 4 (SSE2) or better
79       cpuTarget = { x86_64 = "x86-64"; i686 = "pentium4"; aarch64 = "generic"; }.${arch}
80                   or (throw "unsupported architecture: ${arch}");
81     # Julia applies a lot of patches to its dependencies, so for now do not use the system LLVM
82     # https://github.com/JuliaLang/julia/tree/master/deps/patches
83     in [
84       "ARCH=${arch}"
85       "MARCH=${march}"
86       "JULIA_CPU_TARGET=${cpuTarget}"
87       "PREFIX=$(out)"
88       "prefix=$(out)"
89       "SHELL=${stdenv.shell}"
91       (lib.optionalString (!stdenv.isDarwin) "USE_SYSTEM_BLAS=1")
92       "USE_BLAS64=${if blas.isILP64 then "1" else "0"}"
94       "USE_SYSTEM_LAPACK=1"
96       "USE_SYSTEM_ARPACK=1"
97       "USE_SYSTEM_FFTW=1"
98       "USE_SYSTEM_GMP=0"
99       "USE_SYSTEM_LIBGIT2=1"
100       "USE_SYSTEM_LIBUNWIND=1"
102       "USE_SYSTEM_MPFR=1"
103       "USE_SYSTEM_OPENLIBM=1"
104       "USE_SYSTEM_OPENSPECFUN=1"
105       "USE_SYSTEM_PATCHELF=1"
106       "USE_SYSTEM_PCRE=1"
107       "PCRE_CONFIG=${pcre2.dev}/bin/pcre2-config"
108       "PCRE_INCL_PATH=${pcre2.dev}/include/pcre2.h"
109       "USE_SYSTEM_READLINE=1"
110       "USE_SYSTEM_UTF8PROC=1"
111       "USE_SYSTEM_ZLIB=1"
113       "USE_BINARYBUILDER=0"
114     ];
116   LD_LIBRARY_PATH = makeLibraryPath [
117     arpack fftw fftwSinglePrec libgit2 mpfr blas openlibm
118     openspecfun pcre2 lapack
119   ];
121   # Julia's tests require read/write access to $HOME
122   preCheck = ''
123     export HOME="$NIX_BUILD_TOP"
124   '';
126   preBuild = ''
127     sed -e '/^install:/s@[^ ]*/doc/[^ ]*@@' -i Makefile
128     sed -e '/[$](DESTDIR)[$](docdir)/d' -i Makefile
129     export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
130   '';
132   postInstall = ''
133     # Symlink shared libraries from LD_LIBRARY_PATH into lib/julia,
134     # as using a wrapper with LD_LIBRARY_PATH causes segmentation
135     # faults when program returns an error:
136     #   $ julia -e 'throw(Error())'
137     find $(echo $LD_LIBRARY_PATH | sed 's|:| |g') -maxdepth 1 -name '*.${if stdenv.isDarwin then "dylib" else "so"}*' | while read lib; do
138       if [[ ! -e $out/lib/julia/$(basename $lib) ]]; then
139         ln -sv $lib $out/lib/julia/$(basename $lib)
140       fi
141     done
142   '';
144   passthru = {
145     inherit majorVersion minorVersion maintenanceVersion;
146     site = "share/julia/site/v${majorVersion}.${minorVersion}";
147   };
149   meta = {
150     description = "High-level performance-oriented dynamical language for technical computing";
151     homepage = "https://julialang.org/";
152     license = lib.licenses.mit;
153     maintainers = with lib.maintainers; [ raskin rob garrison ];
154     platforms = [ "i686-linux" "x86_64-linux" "x86_64-darwin" "aarch64-linux" ];
155     broken = stdenv.isi686;
156   };