Skip to content

Commit 1bfa84e

Browse files
Try #1569:
2 parents 33ac5a1 + 5063712 commit 1bfa84e

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

compiler/ghc/default.nix

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ let self =
3131
, # If enabled, GHC will be built with the GPL-free but slower integer-simple
3232
# library instead of the faster but GPLed integer-gmp library.
3333
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)
3437

3538
, # If enabled, use -fPIC when compiling static libs.
3639
enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform && !stdenv.targetPlatform.isAarch32
@@ -71,14 +74,29 @@ let self =
7174
, extra-passthru ? {}
7275
}@args:
7376

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;
7582

7683
let
7784
inherit (stdenv) buildPlatform hostPlatform targetPlatform;
7885
inherit (haskell-nix.haskellLib) isCrossTarget;
7986

8087
inherit (bootPkgs) ghc;
8188

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+
82100
# TODO check if this possible fix for segfaults works or not.
83101
targetLibffi =
84102
# on native platforms targetPlatform.{libffi, gmp} do not exist; thus fall back
@@ -106,7 +124,7 @@ let
106124
include mk/flavours/\$(BuildFlavour).mk
107125
endif
108126
DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
109-
INTEGER_LIBRARY = ${if enableIntegerSimple then "integer-simple" else "integer-gmp"}
127+
'' + bignumSpec + ''
110128
EXTRA_HADDOCK_OPTS += --quickjump --hyperlinked-source
111129
'' + lib.optionalString (targetPlatform != hostPlatform) ''
112130
CrossCompilePrefix = ${targetPrefix}
@@ -121,6 +139,10 @@ let
121139
'' + lib.optionalString enableRelocatedStaticLibs ''
122140
GhcLibHcOpts += -fPIC
123141
GhcRtsHcOpts += -fPIC
142+
GhcRtsCcOpts += -fPIC
143+
'' + lib.optionalString (enableRelocatedStaticLibs && targetPlatform.isx86_64 && !targetPlatform.isWindows) ''
144+
GhcLibHcOpts += -fexternal-dynamic-refs
145+
GhcRtsHcOpts += -fexternal-dynamic-refs
124146
'' + lib.optionalString enableDWARF ''
125147
GhcLibHcOpts += -g3
126148
GhcRtsHcOpts += -g3

overlays/ghc.nix

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
final: prev: with prev;
22
# sadly we need to patch GHC a bit.
3-
let
4-
ghcPkgOverrides = {
5-
enableIntegerSimple = false;
6-
};
3+
let
4+
# The new implementation appeared in GHC 9.0
5+
hasNativeBignum = name: !lib.hasPrefix "ghc8" name;
6+
7+
ghcPkgOverrides = name: { enableIntegerSimple = false; } // lib.optionalAttrs (hasNativeBignum name) {
8+
enableNativeBignum = false;
9+
};
10+
711
ghcDrvOverrides = drv: {
812
hardeningDisable = (drv.hardeningDisable or []) ++ [ "stackprotector" "format" ] ++ lib.optionals prev.stdenv.hostPlatform.isAarch32 [ "pic" "pie" ];
913
};
@@ -20,13 +24,13 @@ final: prev: with prev;
2024
&& !lib.hasPrefix "ghc82" name
2125
&& !lib.hasPrefix "ghcjs" name
2226
&& !lib.hasSuffix "Binary" name;
23-
overrideCompiler = compiler:
24-
((compiler.override ghcPkgOverrides).overrideAttrs ghcDrvOverrides) // {
27+
overrideCompiler = name: compiler:
28+
((compiler.override (ghcPkgOverrides name)).overrideAttrs ghcDrvOverrides) // {
2529
dwarf = overrideCompiler compiler.dwarf;
2630
};
2731
in
2832
lib.recursiveUpdate prev.haskell-nix {
29-
compiler = lib.mapAttrs (_name: overrideCompiler)
33+
compiler = lib.mapAttrs overrideCompiler
3034
(lib.filterAttrs (name: _value: needsPatches name) prev.haskell-nix.compiler);
3135
};
3236
}

release.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# 'supportedSystems' restricts the set of systems that we will evaluate for. Useful when you're evaluating
22
# on a machine with e.g. no way to build the Darwin IFDs you need!
33
{ supportedSystems ? [ "x86_64-linux" "x86_64-darwin" ]
4-
, ifdLevel ? 3
4+
, ifdLevel ? 1
55
, checkMaterialization ? false }:
66

77
let

0 commit comments

Comments
 (0)