about summary refs log tree commit diff
path: root/pkgs/development/compilers/ocaml
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/compilers/ocaml')
-rw-r--r--pkgs/development/compilers/ocaml/4.10.nix3
-rw-r--r--pkgs/development/compilers/ocaml/4.11.nix3
-rw-r--r--pkgs/development/compilers/ocaml/4.12.nix5
-rw-r--r--pkgs/development/compilers/ocaml/Makefile.nixpkgs16
-rw-r--r--pkgs/development/compilers/ocaml/generic.nix26
-rw-r--r--pkgs/development/compilers/ocaml/glibc-2.34-for-ocaml-4.10-and-11.patch37
6 files changed, 83 insertions, 7 deletions
diff --git a/pkgs/development/compilers/ocaml/4.10.nix b/pkgs/development/compilers/ocaml/4.10.nix
index 78051040b5718..48d01a5a8c8d2 100644
--- a/pkgs/development/compilers/ocaml/4.10.nix
+++ b/pkgs/development/compilers/ocaml/4.10.nix
@@ -3,4 +3,7 @@ import ./generic.nix {
   minor_version = "10";
   patch_version = "2";
   sha256 = "sha256-locUYQeCgtXbAiB32JveJchfteN2YStE+MN9ToTwAOM=";
+  patches = [
+    ./glibc-2.34-for-ocaml-4.10-and-11.patch
+  ];
 }
diff --git a/pkgs/development/compilers/ocaml/4.11.nix b/pkgs/development/compilers/ocaml/4.11.nix
index 3e5aefc11f1ce..6a2e4f61f80e2 100644
--- a/pkgs/development/compilers/ocaml/4.11.nix
+++ b/pkgs/development/compilers/ocaml/4.11.nix
@@ -3,4 +3,7 @@ import ./generic.nix {
   minor_version = "11";
   patch_version = "2";
   sha256 = "1m3wrgkkv3f77wvcymjm0i2srxzmx62y6jln3i0a2px07ng08l9z";
+  patches = [
+    ./glibc-2.34-for-ocaml-4.10-and-11.patch
+  ];
 }
diff --git a/pkgs/development/compilers/ocaml/4.12.nix b/pkgs/development/compilers/ocaml/4.12.nix
index 4be2bcf5f9d03..2066d0d5ad314 100644
--- a/pkgs/development/compilers/ocaml/4.12.nix
+++ b/pkgs/development/compilers/ocaml/4.12.nix
@@ -3,4 +3,9 @@ import ./generic.nix {
   minor_version = "12";
   patch_version = "1";
   sha256 = "1jbjjnmqq6ymsy81x188i256bz4z5jrz1pws8g1qf59c32ganjkf";
+  patches = [
+    { url = "https://src.fedoraproject.org/rpms/ocaml/raw/129153b85109944bf0b2922949f77ef8f32b39a1/f/0004-Dynamically-allocate-the-alternate-signal-stack-1026.patch";
+      sha256 = "sha256-FdQ1HkMKHU9QvgLPUBvMdPiEa7w7IL3+1F3SLv63Gog=";
+    }
+  ];
 }
diff --git a/pkgs/development/compilers/ocaml/Makefile.nixpkgs b/pkgs/development/compilers/ocaml/Makefile.nixpkgs
new file mode 100644
index 0000000000000..2d6457852fc9a
--- /dev/null
+++ b/pkgs/development/compilers/ocaml/Makefile.nixpkgs
@@ -0,0 +1,16 @@
+# ocaml build system does not allow for parallel building of some
+# top-level targets like 'world', 'bootstrap', 'world.opt' as
+# then spawn '$(MAKE) all' subprocesses that conflict among each
+# other. But we would still like to run each target in parallel
+# individually. This file defines such entry points.
+
+# Re-export all existing phases to make 'make install' work as is.
+include Makefile
+
+nixpkgs_world:
+	$(MAKE) world
+
+nixpkgs_world_bootstrap_world_opt:
+	$(MAKE) world
+	$(MAKE) bootstrap
+	$(MAKE) world.opt
diff --git a/pkgs/development/compilers/ocaml/generic.nix b/pkgs/development/compilers/ocaml/generic.nix
index ec52e56c1faa2..0573b43f5e231 100644
--- a/pkgs/development/compilers/ocaml/generic.nix
+++ b/pkgs/development/compilers/ocaml/generic.nix
@@ -1,4 +1,4 @@
-{ minor_version, major_version, patch_version
+{ minor_version, major_version, patch_version, patches ? []
 , ...}@args:
 let
   versionNoPatch = "${toString major_version}.${toString minor_version}";
@@ -6,7 +6,7 @@ let
   safeX11 = stdenv: !(stdenv.isAarch32 || stdenv.isMips || stdenv.hostPlatform.isStatic);
 in
 
-{ lib, stdenv, fetchurl, ncurses, buildEnv, libunwind
+{ lib, stdenv, fetchurl, ncurses, buildEnv, libunwind, fetchpatch
 , libX11, xorgproto, useX11 ? safeX11 stdenv && !lib.versionAtLeast version "4.09"
 , aflSupport ? false
 , flambdaSupport ? false
@@ -28,21 +28,22 @@ in
 let
    useNativeCompilers = !stdenv.isMips;
    inherit (lib) optional optionals optionalString;
-   name = "ocaml${optionalString aflSupport "+afl"}${optionalString spaceTimeSupport "+spacetime"}${optionalString flambdaSupport "+flambda"}-${version}";
+   pname = "ocaml${optionalString aflSupport "+afl"}${optionalString spaceTimeSupport "+spacetime"}${optionalString flambdaSupport "+flambda"}";
 in
 
 let
   x11env = buildEnv { name = "x11env"; paths = [libX11 xorgproto]; };
   x11lib = x11env + "/lib";
   x11inc = x11env + "/include";
+
+  fetchpatch' = x: if builtins.isAttrs x then fetchpatch x else x;
 in
 
 stdenv.mkDerivation (args // {
 
-  inherit name;
-  inherit version;
+  inherit pname version src;
 
-  inherit src;
+  patches = map fetchpatch' patches;
 
   strictDeps = true;
 
@@ -74,7 +75,18 @@ stdenv.mkDerivation (args // {
   hardeningDisable = lib.optional (lib.versionAtLeast version "4.09" && stdenv.hostPlatform.isMusl) "pie"
     ++ lib.optionals (args ? hardeningDisable) args.hardeningDisable;
 
-  buildFlags = [ "world" ] ++ optionals useNativeCompilers [ "bootstrap" "world.opt" ];
+  # 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";
+
+  # 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
+    then ["nixpkgs_world_bootstrap_world_opt"]
+    else ["nixpkgs_world"];
   buildInputs = optional (!lib.versionAtLeast version "4.07") ncurses
     ++ optionals useX11 [ libX11 xorgproto ];
   propagatedBuildInputs = optional spaceTimeSupport libunwind;
diff --git a/pkgs/development/compilers/ocaml/glibc-2.34-for-ocaml-4.10-and-11.patch b/pkgs/development/compilers/ocaml/glibc-2.34-for-ocaml-4.10-and-11.patch
new file mode 100644
index 0000000000000..4ff9e6fddba57
--- /dev/null
+++ b/pkgs/development/compilers/ocaml/glibc-2.34-for-ocaml-4.10-and-11.patch
@@ -0,0 +1,37 @@
+From dfb5e954a04f59b0456cc4c0ddf3acaf22e0ff07 Mon Sep 17 00:00:00 2001
+From: Richard W.M. Jones <rjones@redhat.com>
+Date: Feb 28 2021 20:45:47 +0000
+Subject: Workaround for glibc non-constant SIGSTKSZ
+
+
+https://github.com/ocaml/ocaml/issues/10250
+
+Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
+
+---
+
+diff --git a/runtime/signals_nat.c b/runtime/signals_nat.c
+index 8b64ab4..7f0a975 100644
+--- a/runtime/signals_nat.c
++++ b/runtime/signals_nat.c
+@@ -181,7 +181,19 @@ DECLARE_SIGNAL_HANDLER(trap_handler)
+ #error "CONTEXT_SP is required if HAS_STACK_OVERFLOW_DETECTION is defined"
+ #endif
+ 
++#ifndef __GLIBC__
+ static char sig_alt_stack[SIGSTKSZ];
++#else
++/* glibc 2.34 has non-constant SIGSTKSZ */
++static char *sig_alt_stack;
++
++static void allocate_sig_alt_stack(void) __attribute__((constructor));
++static void
++allocate_sig_alt_stack(void)
++{
++  sig_alt_stack = malloc(SIGSTKSZ);
++}
++#endif
+ 
+ /* Code compiled with ocamlopt never accesses more than
+    EXTRA_STACK bytes below the stack pointer. */
+