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