9 versionNoPatch = "${toString major_version}.${toString minor_version}";
10 version = "${versionNoPatch}.${toString patch_version}";
13 !(stdenv.hostPlatform.isAarch32 || stdenv.hostPlatform.isMips || stdenv.hostPlatform.isStatic);
27 useX11 ? safeX11 stdenv && lib.versionOlder version "4.09",
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";
44 args.src or (fetchurl {
46 args.url or "http://caml.inria.fr/pub/distrib/ocaml-${versionNoPatch}/ocaml-${version}.tar.xz";
47 inherit (args) sha256;
52 useNativeCompilers = !stdenv.hostPlatform.isMips;
60 pname = concatStrings [
62 (optionalString aflSupport "+afl")
63 (optionalString spaceTimeSupport "+spacetime")
64 (optionalString flambdaSupport "+flambda")
65 (optionalString framePointerSupport "+fp")
77 x11lib = x11env + "/lib";
78 x11inc = x11env + "/include";
80 fetchpatch' = x: if builtins.isAttrs x then fetchpatch x else x;
87 inherit pname version src;
89 patches = map fetchpatch' patches;
93 prefixKey = "-prefix ";
96 flags = new: old: if lib.versionAtLeast version "4.08" then new else old;
100 [ "--x-libraries=${x11lib}" "--x-includes=${x11inc}" ]
101 [ "-x11lib" x11lib "-x11include" x11inc ]
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"
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}"
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.
125 lib.versionAtLeast version "4.08"
126 && !(stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64)
132 # x86_64-unknown-linux-musl-ld: -r and -pie may not be used together
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;
153 if useNativeCompilers then
155 (if lib.versionOlder version "5.2" then "nixpkgs_world_bootstrap_world_opt" else "defaultentry")
160 optional (lib.versionOlder version "4.07") ncurses
161 ++ optionals useX11 [
165 depsBuildBuild = lib.optionals (!stdenv.hostPlatform.isDarwin) [ binutils ];
166 propagatedBuildInputs = optional spaceTimeSupport libunwind;
167 installTargets = [ "install" ] ++ optional useNativeCompilers "installopt";
169 optionalString (lib.versionOlder version "4.04") ''
171 sed -e "s@/bin/cat@$CAT@" -i config/auto-aux/sharpbang
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"
178 + optionalString (lib.versionOlder version "4.08" && stdenv.hostPlatform.isStatic) ''
179 configureFlagsArray+=("-cc" "$CC" "-as" "$AS" "-partialld" "$LD -r")
182 mkdir -p $out/include
183 ln -sv $out/lib/ocaml/caml $out/include/caml
187 nativeCompilers = useNativeCompilers;
191 homepage = "https://ocaml.org/";
192 branch = versionNoPatch;
193 license = with licenses; [
197 description = "OCaml is an industrial-strength programming language supporting functional, imperative and object-oriented styles";
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.
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
216 platforms = with platforms; linux ++ darwin;
218 stdenv.hostPlatform.isAarch64
219 && lib.versionOlder version (if stdenv.hostPlatform.isDarwin then "4.10" else "4.02");