on iko/ghcjs-patch-master help sign in
Support native bignum (including static builds) (#1569)
1ccfd29Hamish Mackenzie
compiler/ghc/default.nix+24−2
@@ -31,6 +31,9 @@ let self =
31, # If enabled, GHC will be built with the GPL-free but slower integer-simple
31, # If enabled, GHC will be built with the GPL-free but slower integer-simple
32 # library instead of the faster but GPLed integer-gmp library.
32 # library instead of the faster but GPLed integer-gmp library.
33 enableIntegerSimple ? !(lib.any (lib.meta.platformMatch stdenv.hostPlatform) gmp.meta.platforms), gmp
33 enableIntegerSimple ? !(lib.any (lib.meta.platformMatch stdenv.hostPlatform) gmp.meta.platforms), gmp
34+, # If enabled, GHC will be built with the GPL-free native backend of the
35+ # bignum library that is nearly as fast as GMP
36+ enableNativeBignum ? !((lib.any (lib.meta.platformMatch stdenv.hostPlatform) gmp.meta.platforms) || enableIntegerSimple)
34
37
35, # If enabled, use -fPIC when compiling static libs.
38, # If enabled, use -fPIC when compiling static libs.
36 enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform && !stdenv.targetPlatform.isAarch32
39 enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform && !stdenv.targetPlatform.isAarch32
@@ -71,7 +74,11 @@ let self =
71, extra-passthru ? {}
74, extra-passthru ? {}
72}@args:
75}@args:
73
76
74−assert !enableIntegerSimple -> gmp != null;
77+assert !(enableIntegerSimple || enableNativeBignum) -> gmp != null;
78+
79+# Early check to make sure only one of these is enabled
80+assert enableNativeBignum -> !enableIntegerSimple;
81+assert enableIntegerSimple -> !enableNativeBignum;
75
82
76let
83let
77 inherit (stdenv) buildPlatform hostPlatform targetPlatform;
84 inherit (stdenv) buildPlatform hostPlatform targetPlatform;
@@ -79,6 +86,17 @@ let
79
86
80 inherit (bootPkgs) ghc;
87 inherit (bootPkgs) ghc;
81
88
89+ ghcHasNativeBignum = builtins.compareVersions ghc-version "9.0" >= 0;
90+
91+ bignumSpec =
92+ assert ghcHasNativeBignum -> !enableIntegerSimple;
93+ assert !ghcHasNativeBignum -> !enableNativeBignum;
94+ if ghcHasNativeBignum then ''
95+ BIGNUM_BACKEND = ${if enableNativeBignum then "native" else "gmp"}
96+ '' else ''
97+ INTEGER_LIBRARY = ${if enableIntegerSimple then "integer-simple" else "integer-gmp"}
98+ '';
99+
82 # TODO check if this possible fix for segfaults works or not.
100 # TODO check if this possible fix for segfaults works or not.
83 targetLibffi =
101 targetLibffi =
84 # on native platforms targetPlatform.{libffi, gmp} do not exist; thus fall back
102 # on native platforms targetPlatform.{libffi, gmp} do not exist; thus fall back
@@ -106,7 +124,7 @@ let
106 include mk/flavours/\$(BuildFlavour).mk
124 include mk/flavours/\$(BuildFlavour).mk
107 endif
125 endif
108 DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
126 DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
109− INTEGER_LIBRARY = ${if enableIntegerSimple then "integer-simple" else "integer-gmp"}
127+ '' + bignumSpec + ''
110 EXTRA_HADDOCK_OPTS += --quickjump --hyperlinked-source
128 EXTRA_HADDOCK_OPTS += --quickjump --hyperlinked-source
111 '' + lib.optionalString (targetPlatform != hostPlatform) ''
129 '' + lib.optionalString (targetPlatform != hostPlatform) ''
112 CrossCompilePrefix = ${targetPrefix}
130 CrossCompilePrefix = ${targetPrefix}
@@ -121,6 +139,10 @@ let
121 '' + lib.optionalString enableRelocatedStaticLibs ''
139 '' + lib.optionalString enableRelocatedStaticLibs ''
122 GhcLibHcOpts += -fPIC
140 GhcLibHcOpts += -fPIC
123 GhcRtsHcOpts += -fPIC
141 GhcRtsHcOpts += -fPIC
142+ GhcRtsCcOpts += -fPIC
143+ '' + lib.optionalString (enableRelocatedStaticLibs && targetPlatform.isx86_64 && !targetPlatform.isWindows) ''
144+ GhcLibHcOpts += -fexternal-dynamic-refs
145+ GhcRtsHcOpts += -fexternal-dynamic-refs
124 '' + lib.optionalString enableDWARF ''
146 '' + lib.optionalString enableDWARF ''
125 GhcLibHcOpts += -g3
147 GhcLibHcOpts += -g3
126 GhcRtsHcOpts += -g3
148 GhcRtsHcOpts += -g3
overlays/ghc.nix+12−8
@@ -1,9 +1,13 @@
1final: prev: with prev;
1final: prev: with prev;
2 # sadly we need to patch GHC a bit.
2 # sadly we need to patch GHC a bit.
3− let
3+ let
4− ghcPkgOverrides = {
4+ # The new implementation appeared in GHC 9.0
5+ hasNativeBignum = name: !lib.hasPrefix "ghc8" name;
6+
5− enableIntegerSimple = false;
7+ ghcPkgOverrides = name: { enableIntegerSimple = false; } // lib.optionalAttrs (hasNativeBignum name) {
8+ enableNativeBignum = false;
6− };
9+ };
10+
7 ghcDrvOverrides = drv: {
11 ghcDrvOverrides = drv: {
8 hardeningDisable = (drv.hardeningDisable or []) ++ [ "stackprotector" "format" ] ++ lib.optionals prev.stdenv.hostPlatform.isAarch32 [ "pic" "pie" ];
12 hardeningDisable = (drv.hardeningDisable or []) ++ [ "stackprotector" "format" ] ++ lib.optionals prev.stdenv.hostPlatform.isAarch32 [ "pic" "pie" ];
9 };
13 };
@@ -20,13 +24,13 @@ final: prev: with prev;
20 && !lib.hasPrefix "ghc82" name
24 && !lib.hasPrefix "ghc82" name
21 && !lib.hasPrefix "ghcjs" name
25 && !lib.hasPrefix "ghcjs" name
22 && !lib.hasSuffix "Binary" name;
26 && !lib.hasSuffix "Binary" name;
23− overrideCompiler = compiler:
27+ overrideCompiler = name: compiler:
24− ((compiler.override ghcPkgOverrides).overrideAttrs ghcDrvOverrides) // {
28+ ((compiler.override (ghcPkgOverrides name)).overrideAttrs ghcDrvOverrides) // {
25− dwarf = overrideCompiler compiler.dwarf;
29+ dwarf = overrideCompiler name compiler.dwarf;
26 };
30 };
27 in
31 in
28 lib.recursiveUpdate prev.haskell-nix {
32 lib.recursiveUpdate prev.haskell-nix {
29− compiler = lib.mapAttrs (_name: overrideCompiler)
33+ compiler = lib.mapAttrs overrideCompiler
30 (lib.filterAttrs (name: _value: needsPatches name) prev.haskell-nix.compiler);
34 (lib.filterAttrs (name: _value: needsPatches name) prev.haskell-nix.compiler);
31 };
35 };
32 }
36 }