2021-09-30 19:18:53 +00:00
|
|
|
{ minor_version, major_version, patch_version, patches ? []
|
2020-11-18 07:10:35 +00:00
|
|
|
, ...}@args:
|
2016-07-13 12:52:50 +00:00
|
|
|
let
|
|
|
|
versionNoPatch = "${toString major_version}.${toString minor_version}";
|
|
|
|
version = "${versionNoPatch}.${toString patch_version}";
|
2021-08-14 12:00:00 +00:00
|
|
|
safeX11 = stdenv: !(stdenv.hostPlatform.isAarch32 || stdenv.hostPlatform.isMips || stdenv.hostPlatform.isStatic);
|
2016-07-13 12:52:50 +00:00
|
|
|
in
|
|
|
|
|
2024-11-26 09:55:09 +00:00
|
|
|
{ lib, stdenv, fetchurl, ncurses, binutils, buildEnv, libunwind, fetchpatch
|
2022-04-25 20:35:24 +00:00
|
|
|
, libX11, xorgproto, useX11 ? safeX11 stdenv && lib.versionOlder version "4.09"
|
2019-11-23 07:19:47 +00:00
|
|
|
, aflSupport ? false
|
2017-12-20 22:43:24 +00:00
|
|
|
, flambdaSupport ? false
|
2020-07-17 14:00:33 +00:00
|
|
|
, spaceTimeSupport ? false
|
2023-01-12 13:17:40 +00:00
|
|
|
, unsafeStringSupport ? false
|
2023-03-12 20:17:07 +00:00
|
|
|
, framePointerSupport ? false
|
2017-12-20 22:43:24 +00:00
|
|
|
}:
|
2016-07-13 12:52:50 +00:00
|
|
|
|
2021-08-14 12:00:00 +00:00
|
|
|
assert useX11 -> safeX11 stdenv;
|
2021-01-22 11:25:31 +00:00
|
|
|
assert aflSupport -> lib.versionAtLeast version "4.05";
|
|
|
|
assert flambdaSupport -> lib.versionAtLeast version "4.03";
|
2023-02-19 16:42:53 +00:00
|
|
|
assert spaceTimeSupport -> lib.versionAtLeast version "4.04" && lib.versionOlder version "4.12";
|
2023-01-12 13:17:40 +00:00
|
|
|
assert unsafeStringSupport -> lib.versionAtLeast version "4.06" && lib.versionOlder version "5.0";
|
2023-03-12 20:17:07 +00:00
|
|
|
assert framePointerSupport -> lib.versionAtLeast version "4.01";
|
2016-07-13 12:52:50 +00:00
|
|
|
|
2020-11-18 07:10:35 +00:00
|
|
|
let
|
|
|
|
src = args.src or (fetchurl {
|
|
|
|
url = args.url or "http://caml.inria.fr/pub/distrib/ocaml-${versionNoPatch}/ocaml-${version}.tar.xz";
|
|
|
|
inherit (args) sha256;
|
|
|
|
});
|
|
|
|
in
|
|
|
|
|
2016-07-13 12:52:50 +00:00
|
|
|
let
|
2023-03-12 20:17:07 +00:00
|
|
|
useNativeCompilers = !stdenv.hostPlatform.isMips;
|
|
|
|
inherit (lib) optional optionals optionalString strings concatStrings;
|
|
|
|
pname = concatStrings [ "ocaml"
|
|
|
|
(optionalString aflSupport "+afl")
|
|
|
|
(optionalString spaceTimeSupport "+spacetime")
|
|
|
|
(optionalString flambdaSupport "+flambda")
|
|
|
|
(optionalString framePointerSupport "+fp")
|
|
|
|
];
|
2016-07-13 12:52:50 +00:00
|
|
|
in
|
|
|
|
|
2018-12-10 19:59:56 +00:00
|
|
|
let
|
2018-12-31 03:40:47 +00:00
|
|
|
x11env = buildEnv { name = "x11env"; paths = [libX11 xorgproto]; };
|
2016-07-13 12:52:50 +00:00
|
|
|
x11lib = x11env + "/lib";
|
|
|
|
x11inc = x11env + "/include";
|
2021-10-08 11:21:25 +00:00
|
|
|
|
|
|
|
fetchpatch' = x: if builtins.isAttrs x then fetchpatch x else x;
|
2018-12-10 19:59:56 +00:00
|
|
|
in
|
|
|
|
|
2019-08-13 21:52:01 +00:00
|
|
|
stdenv.mkDerivation (args // {
|
2016-07-13 12:52:50 +00:00
|
|
|
|
2022-03-01 13:55:45 +00:00
|
|
|
inherit pname version src;
|
2016-07-13 12:52:50 +00:00
|
|
|
|
2021-10-08 11:21:25 +00:00
|
|
|
patches = map fetchpatch' patches;
|
2021-09-30 19:18:53 +00:00
|
|
|
|
2021-08-11 12:00:00 +00:00
|
|
|
strictDeps = true;
|
|
|
|
|
2016-07-13 12:52:50 +00:00
|
|
|
prefixKey = "-prefix ";
|
2019-11-23 07:19:42 +00:00
|
|
|
configureFlags =
|
|
|
|
let flags = new: old:
|
2021-01-22 11:25:31 +00:00
|
|
|
if lib.versionAtLeast version "4.08"
|
2019-11-23 07:19:42 +00:00
|
|
|
then new else old
|
|
|
|
; in
|
|
|
|
optionals useX11 (flags
|
|
|
|
[ "--x-libraries=${x11lib}" "--x-includes=${x11inc}"]
|
|
|
|
[ "-x11lib" x11lib "-x11include" x11inc ])
|
2019-11-23 07:19:47 +00:00
|
|
|
++ optional aflSupport (flags "--with-afl" "-afl-instrument")
|
2019-11-23 07:19:42 +00:00
|
|
|
++ optional flambdaSupport (flags "--enable-flambda" "-flambda")
|
2020-07-17 14:00:33 +00:00
|
|
|
++ optional spaceTimeSupport (flags "--enable-spacetime" "-spacetime")
|
2023-03-12 20:17:07 +00:00
|
|
|
++ optional framePointerSupport (flags "--enable-frame-pointers" "-with-frame-pointers")
|
2023-01-12 13:17:40 +00:00
|
|
|
++ optionals unsafeStringSupport [
|
|
|
|
"--disable-force-safe-string"
|
|
|
|
"DEFAULT_STRING=unsafe"
|
|
|
|
]
|
2021-08-05 12:00:00 +00:00
|
|
|
++ optional (stdenv.hostPlatform.isStatic && (lib.versionOlder version "4.08")) "-no-shared-libs"
|
|
|
|
++ optionals (stdenv.hostPlatform != stdenv.buildPlatform && lib.versionOlder version "4.08") [
|
|
|
|
"-host ${stdenv.hostPlatform.config}"
|
|
|
|
"-target ${stdenv.targetPlatform.config}"
|
|
|
|
];
|
|
|
|
dontAddStaticConfigureFlags = lib.versionOlder version "4.08";
|
2021-11-22 20:14:18 +00:00
|
|
|
|
|
|
|
# on aarch64-darwin using --host and --target causes the build to invoke
|
|
|
|
# `aarch64-apple-darwin-clang` while using assembler. However, such binary
|
|
|
|
# does not exist. So, disable these configure flags on `aarch64-darwin`.
|
|
|
|
# See #144785 for details.
|
|
|
|
configurePlatforms = lib.optionals (lib.versionAtLeast version "4.08" && !(stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64)) [ "host" "target" ];
|
2021-08-05 12:00:00 +00:00
|
|
|
# x86_64-unknown-linux-musl-ld: -r and -pie may not be used together
|
2021-11-25 21:13:12 +00:00
|
|
|
hardeningDisable = lib.optional (lib.versionAtLeast version "4.09" && stdenv.hostPlatform.isMusl) "pie"
|
2022-10-15 14:41:15 +00:00
|
|
|
++ lib.optional (lib.versionAtLeast version "5.0" && stdenv.cc.isClang) "strictoverflow"
|
2021-11-25 21:13:12 +00:00
|
|
|
++ lib.optionals (args ? hardeningDisable) args.hardeningDisable;
|
2016-07-13 12:52:50 +00:00
|
|
|
|
ocaml: enable parallel building
Enable parallel building for ocaml-4.08 and above. tested as:
$ nix build -f. ocaml-ng.ocamlPackages_{4_{00_1,01_0,02,03,04,05,06,07,08,09,10,11,12,13},latest}.ocaml --keep-going
ocaml build system supports parallel building, but but for multiple
top-level targets at the same time as it usually spawns subprocess
$(MAKE) that occasionally conflict with one another. To work it around
we use tiny Makefile with a single rule that calls top-level targets
sequentially as makefile calls:
nixpkgs_world_bootstrap_world_opt:
$(MAKE) world
$(MAKE) bootstrap
$(MAKE) world.opt
On a 16-core machine ocaml-4.12 build speeds up from 6m55s to 1m35s.
Releases 4_00_1, 4_01_0, 4_04 and 4_05 still have some race in them.
Thus this change enables parallel builds only for ocaml-4.06 and above.
Adapted from #142723
upstreams's CI tests the parallel makefile: https://github.com/ocaml/ocaml/issues/10235#issuecomment-782100584
The limit was chosen to be 4.08 because it was released in 2019, not too
long before the above link.
2021-10-24 08:39:21 +00:00
|
|
|
# Older versions have some race:
|
|
|
|
# cp: cannot stat 'boot/ocamlrun': No such file or directory
|
|
|
|
# make[2]: *** [Makefile:199: backup] Error 1
|
|
|
|
enableParallelBuilding = lib.versionAtLeast version "4.08";
|
|
|
|
|
2023-03-02 22:00:52 +00:00
|
|
|
# Workaround missing dependencies for install parallelism:
|
|
|
|
# install: target '...-ocaml-4.14.0/lib/ocaml/threads': No such file or directory
|
|
|
|
# make[1]: *** [Makefile:140: installopt] Error 1
|
|
|
|
enableParallelInstalling = false;
|
|
|
|
|
ocaml: enable parallel building
Enable parallel building for ocaml-4.08 and above. tested as:
$ nix build -f. ocaml-ng.ocamlPackages_{4_{00_1,01_0,02,03,04,05,06,07,08,09,10,11,12,13},latest}.ocaml --keep-going
ocaml build system supports parallel building, but but for multiple
top-level targets at the same time as it usually spawns subprocess
$(MAKE) that occasionally conflict with one another. To work it around
we use tiny Makefile with a single rule that calls top-level targets
sequentially as makefile calls:
nixpkgs_world_bootstrap_world_opt:
$(MAKE) world
$(MAKE) bootstrap
$(MAKE) world.opt
On a 16-core machine ocaml-4.12 build speeds up from 6m55s to 1m35s.
Releases 4_00_1, 4_01_0, 4_04 and 4_05 still have some race in them.
Thus this change enables parallel builds only for ocaml-4.06 and above.
Adapted from #142723
upstreams's CI tests the parallel makefile: https://github.com/ocaml/ocaml/issues/10235#issuecomment-782100584
The limit was chosen to be 4.08 because it was released in 2019, not too
long before the above link.
2021-10-24 08:39:21 +00:00
|
|
|
# Workaround lack of parallelism support among top-level targets:
|
|
|
|
# we place nixpkgs-specific targets to a separate file and set
|
|
|
|
# sequential order among them as a single rule.
|
|
|
|
makefile = ./Makefile.nixpkgs;
|
|
|
|
buildFlags = if useNativeCompilers
|
2024-11-05 03:41:40 +00:00
|
|
|
then [(if lib.versionOlder version "5.2"
|
|
|
|
then "nixpkgs_world_bootstrap_world_opt"
|
|
|
|
else "defaultentry")]
|
ocaml: enable parallel building
Enable parallel building for ocaml-4.08 and above. tested as:
$ nix build -f. ocaml-ng.ocamlPackages_{4_{00_1,01_0,02,03,04,05,06,07,08,09,10,11,12,13},latest}.ocaml --keep-going
ocaml build system supports parallel building, but but for multiple
top-level targets at the same time as it usually spawns subprocess
$(MAKE) that occasionally conflict with one another. To work it around
we use tiny Makefile with a single rule that calls top-level targets
sequentially as makefile calls:
nixpkgs_world_bootstrap_world_opt:
$(MAKE) world
$(MAKE) bootstrap
$(MAKE) world.opt
On a 16-core machine ocaml-4.12 build speeds up from 6m55s to 1m35s.
Releases 4_00_1, 4_01_0, 4_04 and 4_05 still have some race in them.
Thus this change enables parallel builds only for ocaml-4.06 and above.
Adapted from #142723
upstreams's CI tests the parallel makefile: https://github.com/ocaml/ocaml/issues/10235#issuecomment-782100584
The limit was chosen to be 4.08 because it was released in 2019, not too
long before the above link.
2021-10-24 08:39:21 +00:00
|
|
|
else ["nixpkgs_world"];
|
2022-04-25 20:35:24 +00:00
|
|
|
buildInputs = optional (lib.versionOlder version "4.07") ncurses
|
2018-12-31 03:40:47 +00:00
|
|
|
++ optionals useX11 [ libX11 xorgproto ];
|
2024-11-28 07:37:34 +00:00
|
|
|
depsBuildBuild = lib.optionals (!stdenv.hostPlatform.isDarwin) [ binutils ];
|
2020-07-17 14:00:33 +00:00
|
|
|
propagatedBuildInputs = optional spaceTimeSupport libunwind;
|
2019-10-27 13:03:25 +00:00
|
|
|
installTargets = [ "install" ] ++ optional useNativeCompilers "installopt";
|
2022-04-25 20:35:24 +00:00
|
|
|
preConfigure = optionalString (lib.versionOlder version "4.04") ''
|
2016-07-13 12:52:50 +00:00
|
|
|
CAT=$(type -tp cat)
|
|
|
|
sed -e "s@/bin/cat@$CAT@" -i config/auto-aux/sharpbang
|
2022-10-23 02:16:47 +00:00
|
|
|
'' + optionalString (stdenv.hostPlatform.isDarwin) ''
|
2021-02-27 04:20:19 +00:00
|
|
|
# Do what upstream does by default now: https://github.com/ocaml/ocaml/pull/10176
|
|
|
|
# This is required for aarch64-darwin, everything else works as is.
|
|
|
|
AS="${stdenv.cc}/bin/cc -c" ASPP="${stdenv.cc}/bin/cc -c"
|
2021-08-05 12:00:00 +00:00
|
|
|
'' + optionalString (lib.versionOlder version "4.08" && stdenv.hostPlatform.isStatic) ''
|
|
|
|
configureFlagsArray+=("-cc" "$CC" "-as" "$AS" "-partialld" "$LD -r")
|
2016-07-13 12:52:50 +00:00
|
|
|
'';
|
|
|
|
postBuild = ''
|
|
|
|
mkdir -p $out/include
|
|
|
|
ln -sv $out/lib/ocaml/caml $out/include/caml
|
|
|
|
'';
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
nativeCompilers = useNativeCompilers;
|
|
|
|
};
|
|
|
|
|
2021-01-22 11:25:31 +00:00
|
|
|
meta = with lib; {
|
2021-06-03 14:16:27 +00:00
|
|
|
homepage = "https://ocaml.org/";
|
2016-11-26 09:35:23 +00:00
|
|
|
branch = versionNoPatch;
|
2016-07-13 12:52:50 +00:00
|
|
|
license = with licenses; [
|
|
|
|
qpl /* compiler */
|
|
|
|
lgpl2 /* library */
|
|
|
|
];
|
2021-06-03 14:16:27 +00:00
|
|
|
description = "OCaml is an industrial-strength programming language supporting functional, imperative and object-oriented styles";
|
|
|
|
|
|
|
|
longDescription = ''
|
|
|
|
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.
|
|
|
|
|
|
|
|
Strengths:
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* Automatic memory management, thanks to a fast, unobtrusive, incremental garbage collector.
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
In addition, OCaml features:
|
|
|
|
* A sophisticated module system, which allows organizing modules hierarchically and parameterizing a module over a number of other modules.
|
|
|
|
* An expressive object-oriented layer, featuring multiple inheritance, parametric and virtual classes.
|
|
|
|
* Efficient native code compilers. In addition to its bytecode compiler, OCaml offers a compiler that produces efficient machine code for many architectures.
|
|
|
|
|
|
|
|
Learn more at: https://ocaml.org/learn/description.html
|
|
|
|
'';
|
2016-07-13 12:52:50 +00:00
|
|
|
|
|
|
|
platforms = with platforms; linux ++ darwin;
|
2023-01-16 19:58:27 +00:00
|
|
|
broken = stdenv.hostPlatform.isAarch64 && lib.versionOlder version (if stdenv.hostPlatform.isDarwin then "4.10" else "4.02");
|
2016-07-13 12:52:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})
|