python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / development / compilers / ocaml / generic.nix
blob44886770cad8f83fa18d51f6caa54e18010d8559
1 { minor_version, major_version, patch_version, patches ? []
2 , ...}@args:
3 let
4   versionNoPatch = "${toString major_version}.${toString minor_version}";
5   version = "${versionNoPatch}.${toString patch_version}";
6   safeX11 = stdenv: !(stdenv.isAarch32 || stdenv.isMips || stdenv.hostPlatform.isStatic);
7 in
9 { lib, stdenv, fetchurl, ncurses, buildEnv, libunwind, fetchpatch
10 , libX11, xorgproto, useX11 ? safeX11 stdenv && lib.versionOlder version "4.09"
11 , aflSupport ? false
12 , flambdaSupport ? false
13 , spaceTimeSupport ? false
16 assert useX11 -> safeX11 stdenv;
17 assert aflSupport -> lib.versionAtLeast version "4.05";
18 assert flambdaSupport -> lib.versionAtLeast version "4.03";
19 assert spaceTimeSupport -> lib.versionAtLeast version "4.04";
21 let
22   src = args.src or (fetchurl {
23     url = args.url or "http://caml.inria.fr/pub/distrib/ocaml-${versionNoPatch}/ocaml-${version}.tar.xz";
24     inherit (args) sha256;
25   });
28 let
29    useNativeCompilers = !stdenv.isMips;
30    inherit (lib) optional optionals optionalString;
31    pname = "ocaml${optionalString aflSupport "+afl"}${optionalString spaceTimeSupport "+spacetime"}${optionalString flambdaSupport "+flambda"}";
34 let
35   x11env = buildEnv { name = "x11env"; paths = [libX11 xorgproto]; };
36   x11lib = x11env + "/lib";
37   x11inc = x11env + "/include";
39   fetchpatch' = x: if builtins.isAttrs x then fetchpatch x else x;
42 stdenv.mkDerivation (args // {
44   inherit pname version src;
46   patches = map fetchpatch' patches;
48   strictDeps = true;
50   prefixKey = "-prefix ";
51   configureFlags =
52     let flags = new: old:
53       if lib.versionAtLeast version "4.08"
54       then new else old
55     ; in
56     optionals useX11 (flags
57       [ "--x-libraries=${x11lib}" "--x-includes=${x11inc}"]
58       [ "-x11lib" x11lib "-x11include" x11inc ])
59   ++ optional aflSupport (flags "--with-afl" "-afl-instrument")
60   ++ optional flambdaSupport (flags "--enable-flambda" "-flambda")
61   ++ optional spaceTimeSupport (flags "--enable-spacetime" "-spacetime")
62   ++ optional (stdenv.hostPlatform.isStatic && (lib.versionOlder version "4.08")) "-no-shared-libs"
63   ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform && lib.versionOlder version "4.08") [
64     "-host ${stdenv.hostPlatform.config}"
65     "-target ${stdenv.targetPlatform.config}"
66   ];
67   dontAddStaticConfigureFlags = lib.versionOlder version "4.08";
69   # on aarch64-darwin using --host and --target causes the build to invoke
70   # `aarch64-apple-darwin-clang` while using assembler. However, such binary
71   # does not exist. So, disable these configure flags on `aarch64-darwin`.
72   # See #144785 for details.
73   configurePlatforms = lib.optionals (lib.versionAtLeast version "4.08" && !(stdenv.isDarwin && stdenv.isAarch64)) [ "host" "target" ];
74   # x86_64-unknown-linux-musl-ld: -r and -pie may not be used together
75   hardeningDisable = lib.optional (lib.versionAtLeast version "4.09" && stdenv.hostPlatform.isMusl) "pie"
76     ++ lib.optional (lib.versionAtLeast version "5.0" && stdenv.cc.isClang) "strictoverflow"
77     ++ lib.optionals (args ? hardeningDisable) args.hardeningDisable;
79   # Older versions have some race:
80   #  cp: cannot stat 'boot/ocamlrun': No such file or directory
81   #  make[2]: *** [Makefile:199: backup] Error 1
82   enableParallelBuilding = lib.versionAtLeast version "4.08";
84   # Workaround lack of parallelism support among top-level targets:
85   # we place nixpkgs-specific targets to a separate file and set
86   # sequential order among them as a single rule.
87   makefile = ./Makefile.nixpkgs;
88   buildFlags = if useNativeCompilers
89     then ["nixpkgs_world_bootstrap_world_opt"]
90     else ["nixpkgs_world"];
91   buildInputs = optional (lib.versionOlder version "4.07") ncurses
92     ++ optionals useX11 [ libX11 xorgproto ];
93   propagatedBuildInputs = optional spaceTimeSupport libunwind;
94   installTargets = [ "install" ] ++ optional useNativeCompilers "installopt";
95   preConfigure = optionalString (lib.versionOlder version "4.04") ''
96     CAT=$(type -tp cat)
97     sed -e "s@/bin/cat@$CAT@" -i config/auto-aux/sharpbang
98   '' + optionalString (stdenv.isDarwin && lib.versionOlder version "4.13") ''
99     # Do what upstream does by default now: https://github.com/ocaml/ocaml/pull/10176
100     # This is required for aarch64-darwin, everything else works as is.
101     AS="${stdenv.cc}/bin/cc -c" ASPP="${stdenv.cc}/bin/cc -c"
102   '' + optionalString (lib.versionOlder version "4.08" && stdenv.hostPlatform.isStatic) ''
103     configureFlagsArray+=("-cc" "$CC" "-as" "$AS" "-partialld" "$LD -r")
104   '';
105   postBuild = ''
106     mkdir -p $out/include
107     ln -sv $out/lib/ocaml/caml $out/include/caml
108   '';
110   passthru = {
111     nativeCompilers = useNativeCompilers;
112   };
114   meta = with lib; {
115     homepage = "https://ocaml.org/";
116     branch = versionNoPatch;
117     license = with licenses; [
118       qpl /* compiler */
119       lgpl2 /* library */
120     ];
121     description = "OCaml is an industrial-strength programming language supporting functional, imperative and object-oriented styles";
123     longDescription = ''
124       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.
126       Strengths:
127       * 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.
128       * 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.
129       * Automatic memory management, thanks to a fast, unobtrusive, incremental garbage collector.
130       * 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.
132       In addition, OCaml features:
133       * A sophisticated module system, which allows organizing modules hierarchically and parameterizing a module over a number of other modules.
134       * An expressive object-oriented layer, featuring multiple inheritance, parametric and virtual classes.
135       * Efficient native code compilers. In addition to its bytecode compiler, OCaml offers a compiler that produces efficient machine code for many architectures.
137       Learn more at: https://ocaml.org/learn/description.html
138     '';
140     platforms = with platforms; linux ++ darwin;
141     broken = stdenv.isAarch64 && lib.versionOlder version (if stdenv.isDarwin then "4.10" else "4.06");
142   };