@@ -31,6 +31,9 @@ let self =
31
31
, # If enabled, GHC will be built with the GPL-free but slower integer-simple
32
32
# library instead of the faster but GPLed integer-gmp library.
33
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
38
, # If enabled, use -fPIC when compiling static libs.
36
39
enableRelocatedStaticLibs ? stdenv . targetPlatform != stdenv . hostPlatform && ! stdenv . targetPlatform . isAarch32
@@ -71,14 +74,29 @@ let self =
71
74
, extra-passthru ? { }
72
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
76
83
let
77
84
inherit ( stdenv ) buildPlatform hostPlatform targetPlatform ;
78
85
inherit ( haskell-nix . haskellLib ) isCrossTarget ;
79
86
80
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
100
# TODO check if this possible fix for segfaults works or not.
83
101
targetLibffi =
84
102
# on native platforms targetPlatform.{libffi, gmp} do not exist; thus fall back
106
124
include mk/flavours/\$(BuildFlavour).mk
107
125
endif
108
126
DYNAMIC_GHC_PROGRAMS = ${ if enableShared then "YES" else "NO" }
109
- INTEGER_LIBRARY = ${ if enableIntegerSimple then "integer-simple" else "integer-gmp" }
127
+ '' + bignumSpec + ''
110
128
EXTRA_HADDOCK_OPTS += --quickjump --hyperlinked-source
111
129
'' + lib . optionalString ( targetPlatform != hostPlatform ) ''
112
130
CrossCompilePrefix = ${ targetPrefix }
121
139
'' + lib . optionalString enableRelocatedStaticLibs ''
122
140
GhcLibHcOpts += -fPIC
123
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
146
'' + lib . optionalString enableDWARF ''
125
147
GhcLibHcOpts += -g3
126
148
GhcRtsHcOpts += -g3
0 commit comments