tutanota-desktop: 259.250108.1 -> 266.250202.0 (#377234)
[NixPkgs.git] / pkgs / development / compilers / ocaml / generic.nix
blobb0398fdc39cb785927bfe4ccd17918505c3a7955
2   minor_version,
3   major_version,
4   patch_version,
5   patches ? [ ],
6   ...
7 }@args:
8 let
9   versionNoPatch = "${toString major_version}.${toString minor_version}";
10   version = "${versionNoPatch}.${toString patch_version}";
11   safeX11 =
12     stdenv:
13     !(stdenv.hostPlatform.isAarch32 || stdenv.hostPlatform.isMips || stdenv.hostPlatform.isStatic);
17   lib,
18   stdenv,
19   fetchurl,
20   ncurses,
21   binutils,
22   buildEnv,
23   libunwind,
24   fetchpatch,
25   libX11,
26   xorgproto,
27   useX11 ? safeX11 stdenv && lib.versionOlder version "4.09",
28   aflSupport ? false,
29   flambdaSupport ? false,
30   spaceTimeSupport ? false,
31   unsafeStringSupport ? false,
32   framePointerSupport ? false,
35 assert useX11 -> safeX11 stdenv;
36 assert aflSupport -> lib.versionAtLeast version "4.05";
37 assert flambdaSupport -> lib.versionAtLeast version "4.03";
38 assert spaceTimeSupport -> lib.versionAtLeast version "4.04" && lib.versionOlder version "4.12";
39 assert unsafeStringSupport -> lib.versionAtLeast version "4.06" && lib.versionOlder version "5.0";
40 assert framePointerSupport -> lib.versionAtLeast version "4.01";
42 let
43   src =
44     args.src or (fetchurl {
45       url =
46         args.url or "http://caml.inria.fr/pub/distrib/ocaml-${versionNoPatch}/ocaml-${version}.tar.xz";
47       inherit (args) sha256;
48     });
51 let
52   useNativeCompilers = !stdenv.hostPlatform.isMips;
53   inherit (lib)
54     optional
55     optionals
56     optionalString
57     strings
58     concatStrings
59     ;
60   pname = concatStrings [
61     "ocaml"
62     (optionalString aflSupport "+afl")
63     (optionalString spaceTimeSupport "+spacetime")
64     (optionalString flambdaSupport "+flambda")
65     (optionalString framePointerSupport "+fp")
66   ];
69 let
70   x11env = buildEnv {
71     name = "x11env";
72     paths = [
73       libX11
74       xorgproto
75     ];
76   };
77   x11lib = x11env + "/lib";
78   x11inc = x11env + "/include";
80   fetchpatch' = x: if builtins.isAttrs x then fetchpatch x else x;
83 stdenv.mkDerivation (
84   args
85   // {
87     inherit pname version src;
89     patches = map fetchpatch' patches;
91     strictDeps = true;
93     prefixKey = "-prefix ";
94     configureFlags =
95       let
96         flags = new: old: if lib.versionAtLeast version "4.08" then new else old;
97       in
98       optionals useX11 (
99         flags
100           [ "--x-libraries=${x11lib}" "--x-includes=${x11inc}" ]
101           [ "-x11lib" x11lib "-x11include" x11inc ]
102       )
103       ++ optional aflSupport (flags "--with-afl" "-afl-instrument")
104       ++ optional flambdaSupport (flags "--enable-flambda" "-flambda")
105       ++ optional spaceTimeSupport (flags "--enable-spacetime" "-spacetime")
106       ++ optional framePointerSupport (flags "--enable-frame-pointers" "-with-frame-pointers")
107       ++ optionals unsafeStringSupport [
108         "--disable-force-safe-string"
109         "DEFAULT_STRING=unsafe"
110       ]
111       ++ optional (stdenv.hostPlatform.isStatic && (lib.versionOlder version "4.08")) "-no-shared-libs"
112       ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform && lib.versionOlder version "4.08") [
113         "-host ${stdenv.hostPlatform.config}"
114         "-target ${stdenv.targetPlatform.config}"
115       ];
116     dontAddStaticConfigureFlags = lib.versionOlder version "4.08";
118     # on aarch64-darwin using --host and --target causes the build to invoke
119     # `aarch64-apple-darwin-clang` while using assembler. However, such binary
120     # does not exist. So, disable these configure flags on `aarch64-darwin`.
121     # See #144785 for details.
122     configurePlatforms =
123       lib.optionals
124         (
125           lib.versionAtLeast version "4.08"
126           && !(stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64)
127         )
128         [
129           "host"
130           "target"
131         ];
132     # x86_64-unknown-linux-musl-ld: -r and -pie may not be used together
133     hardeningDisable =
134       lib.optional (lib.versionAtLeast version "4.09" && stdenv.hostPlatform.isMusl) "pie"
135       ++ lib.optional (lib.versionAtLeast version "5.0" && stdenv.cc.isClang) "strictoverflow"
136       ++ lib.optionals (args ? hardeningDisable) args.hardeningDisable;
138     # Older versions have some race:
139     #  cp: cannot stat 'boot/ocamlrun': No such file or directory
140     #  make[2]: *** [Makefile:199: backup] Error 1
141     enableParallelBuilding = lib.versionAtLeast version "4.08";
143     # Workaround missing dependencies for install parallelism:
144     #  install: target '...-ocaml-4.14.0/lib/ocaml/threads': No such file or directory
145     #  make[1]: *** [Makefile:140: installopt] Error 1
146     enableParallelInstalling = false;
148     # Workaround lack of parallelism support among top-level targets:
149     # we place nixpkgs-specific targets to a separate file and set
150     # sequential order among them as a single rule.
151     makefile = ./Makefile.nixpkgs;
152     buildFlags =
153       if useNativeCompilers then
154         [
155           (if lib.versionOlder version "5.2" then "nixpkgs_world_bootstrap_world_opt" else "defaultentry")
156         ]
157       else
158         [ "nixpkgs_world" ];
159     buildInputs =
160       optional (lib.versionOlder version "4.07") ncurses
161       ++ optionals useX11 [
162         libX11
163         xorgproto
164       ];
165     depsBuildBuild = lib.optionals (!stdenv.hostPlatform.isDarwin) [ binutils ];
166     propagatedBuildInputs = optional spaceTimeSupport libunwind;
167     installTargets = [ "install" ] ++ optional useNativeCompilers "installopt";
168     preConfigure =
169       optionalString (lib.versionOlder version "4.04") ''
170         CAT=$(type -tp cat)
171         sed -e "s@/bin/cat@$CAT@" -i config/auto-aux/sharpbang
172       ''
173       + optionalString (stdenv.hostPlatform.isDarwin) ''
174         # Do what upstream does by default now: https://github.com/ocaml/ocaml/pull/10176
175         # This is required for aarch64-darwin, everything else works as is.
176         AS="${stdenv.cc}/bin/cc -c" ASPP="${stdenv.cc}/bin/cc -c"
177       ''
178       + optionalString (lib.versionOlder version "4.08" && stdenv.hostPlatform.isStatic) ''
179         configureFlagsArray+=("-cc" "$CC" "-as" "$AS" "-partialld" "$LD -r")
180       '';
181     postBuild = ''
182       mkdir -p $out/include
183       ln -sv $out/lib/ocaml/caml $out/include/caml
184     '';
186     passthru = {
187       nativeCompilers = useNativeCompilers;
188     };
190     meta = with lib; {
191       homepage = "https://ocaml.org/";
192       branch = versionNoPatch;
193       license = with licenses; [
194         qpl # compiler
195         lgpl2 # library
196       ];
197       description = "OCaml is an industrial-strength programming language supporting functional, imperative and object-oriented styles";
199       longDescription = ''
200         OCaml is a general purpose programming language with an emphasis on expressiveness and safety. Developed for more than 20 years at Inria by a group of leading researchers, it has an advanced type system that helps catch your mistakes without getting in your way. It's used in environments where a single mistake can cost millions and speed matters, is supported by an active community, and has a rich set of libraries and development tools. It's widely used in teaching for its power and simplicity.
202         Strengths:
203         * A powerful type system, equipped with parametric polymorphism and type inference. For instance, the type of a collection can be parameterized by the type of its elements. This allows defining some operations over a collection independently of the type of its elements: sorting an array is one example. Furthermore, type inference allows defining such operations without having to explicitly provide the type of their parameters and result.
204         * User-definable algebraic data types and pattern-matching. New algebraic data types can be defined as combinations of records and sums. Functions that operate over such data structures can then be defined by pattern matching, a generalized form of the well-known switch statement, which offers a clean and elegant way of simultaneously examining and naming data.
205         * Automatic memory management, thanks to a fast, unobtrusive, incremental garbage collector.
206         * Separate compilation of standalone applications. Portable bytecode compilers allow creating stand-alone applications out of Caml Light or OCaml programs. A foreign function interface allows OCaml code to interoperate with C code when necessary. Interactive use of OCaml is also supported via a “read-evaluate-print” loop.
208         In addition, OCaml features:
209         * A sophisticated module system, which allows organizing modules hierarchically and parameterizing a module over a number of other modules.
210         * An expressive object-oriented layer, featuring multiple inheritance, parametric and virtual classes.
211         * Efficient native code compilers. In addition to its bytecode compiler, OCaml offers a compiler that produces efficient machine code for many architectures.
213         Learn more at: https://ocaml.org/learn/description.html
214       '';
216       platforms = with platforms; linux ++ darwin;
217       broken =
218         stdenv.hostPlatform.isAarch64
219         && lib.versionOlder version (if stdenv.hostPlatform.isDarwin then "4.10" else "4.02");
220     };
222   }