mirror of
https://github.com/ilyakooo0/haskell.nix.git
synced 2024-09-11 06:55:40 +03:00
Support native bignum (including static builds) (#1569)
Co-authored-by: Mikaela Allan <mikaela@vitalbio.com> Co-authored-by: Travis Whitaker <pi.boy.travis@gmail.com>
This commit is contained in:
parent
2f49f0a0c6
commit
1ccfd295aa
@ -31,6 +31,9 @@ let self =
|
|||||||
, # If enabled, GHC will be built with the GPL-free but slower integer-simple
|
, # If enabled, GHC will be built with the GPL-free but slower integer-simple
|
||||||
# library instead of the faster but GPLed integer-gmp library.
|
# library instead of the faster but GPLed integer-gmp library.
|
||||||
enableIntegerSimple ? !(lib.any (lib.meta.platformMatch stdenv.hostPlatform) gmp.meta.platforms), gmp
|
enableIntegerSimple ? !(lib.any (lib.meta.platformMatch stdenv.hostPlatform) gmp.meta.platforms), gmp
|
||||||
|
, # If enabled, GHC will be built with the GPL-free native backend of the
|
||||||
|
# bignum library that is nearly as fast as GMP
|
||||||
|
enableNativeBignum ? !((lib.any (lib.meta.platformMatch stdenv.hostPlatform) gmp.meta.platforms) || enableIntegerSimple)
|
||||||
|
|
||||||
, # If enabled, use -fPIC when compiling static libs.
|
, # If enabled, use -fPIC when compiling static libs.
|
||||||
enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform && !stdenv.targetPlatform.isAarch32
|
enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform && !stdenv.targetPlatform.isAarch32
|
||||||
@ -71,7 +74,11 @@ let self =
|
|||||||
, extra-passthru ? {}
|
, extra-passthru ? {}
|
||||||
}@args:
|
}@args:
|
||||||
|
|
||||||
assert !enableIntegerSimple -> gmp != null;
|
assert !(enableIntegerSimple || enableNativeBignum) -> gmp != null;
|
||||||
|
|
||||||
|
# Early check to make sure only one of these is enabled
|
||||||
|
assert enableNativeBignum -> !enableIntegerSimple;
|
||||||
|
assert enableIntegerSimple -> !enableNativeBignum;
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (stdenv) buildPlatform hostPlatform targetPlatform;
|
inherit (stdenv) buildPlatform hostPlatform targetPlatform;
|
||||||
@ -79,6 +86,17 @@ let
|
|||||||
|
|
||||||
inherit (bootPkgs) ghc;
|
inherit (bootPkgs) ghc;
|
||||||
|
|
||||||
|
ghcHasNativeBignum = builtins.compareVersions ghc-version "9.0" >= 0;
|
||||||
|
|
||||||
|
bignumSpec =
|
||||||
|
assert ghcHasNativeBignum -> !enableIntegerSimple;
|
||||||
|
assert !ghcHasNativeBignum -> !enableNativeBignum;
|
||||||
|
if ghcHasNativeBignum then ''
|
||||||
|
BIGNUM_BACKEND = ${if enableNativeBignum then "native" else "gmp"}
|
||||||
|
'' else ''
|
||||||
|
INTEGER_LIBRARY = ${if enableIntegerSimple then "integer-simple" else "integer-gmp"}
|
||||||
|
'';
|
||||||
|
|
||||||
# TODO check if this possible fix for segfaults works or not.
|
# TODO check if this possible fix for segfaults works or not.
|
||||||
targetLibffi =
|
targetLibffi =
|
||||||
# on native platforms targetPlatform.{libffi, gmp} do not exist; thus fall back
|
# on native platforms targetPlatform.{libffi, gmp} do not exist; thus fall back
|
||||||
@ -106,7 +124,7 @@ let
|
|||||||
include mk/flavours/\$(BuildFlavour).mk
|
include mk/flavours/\$(BuildFlavour).mk
|
||||||
endif
|
endif
|
||||||
DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
|
DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
|
||||||
INTEGER_LIBRARY = ${if enableIntegerSimple then "integer-simple" else "integer-gmp"}
|
'' + bignumSpec + ''
|
||||||
EXTRA_HADDOCK_OPTS += --quickjump --hyperlinked-source
|
EXTRA_HADDOCK_OPTS += --quickjump --hyperlinked-source
|
||||||
'' + lib.optionalString (targetPlatform != hostPlatform) ''
|
'' + lib.optionalString (targetPlatform != hostPlatform) ''
|
||||||
CrossCompilePrefix = ${targetPrefix}
|
CrossCompilePrefix = ${targetPrefix}
|
||||||
@ -121,6 +139,10 @@ let
|
|||||||
'' + lib.optionalString enableRelocatedStaticLibs ''
|
'' + lib.optionalString enableRelocatedStaticLibs ''
|
||||||
GhcLibHcOpts += -fPIC
|
GhcLibHcOpts += -fPIC
|
||||||
GhcRtsHcOpts += -fPIC
|
GhcRtsHcOpts += -fPIC
|
||||||
|
GhcRtsCcOpts += -fPIC
|
||||||
|
'' + lib.optionalString (enableRelocatedStaticLibs && targetPlatform.isx86_64 && !targetPlatform.isWindows) ''
|
||||||
|
GhcLibHcOpts += -fexternal-dynamic-refs
|
||||||
|
GhcRtsHcOpts += -fexternal-dynamic-refs
|
||||||
'' + lib.optionalString enableDWARF ''
|
'' + lib.optionalString enableDWARF ''
|
||||||
GhcLibHcOpts += -g3
|
GhcLibHcOpts += -g3
|
||||||
GhcRtsHcOpts += -g3
|
GhcRtsHcOpts += -g3
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
final: prev: with prev;
|
final: prev: with prev;
|
||||||
# sadly we need to patch GHC a bit.
|
# sadly we need to patch GHC a bit.
|
||||||
let
|
let
|
||||||
ghcPkgOverrides = {
|
# The new implementation appeared in GHC 9.0
|
||||||
enableIntegerSimple = false;
|
hasNativeBignum = name: !lib.hasPrefix "ghc8" name;
|
||||||
};
|
|
||||||
|
ghcPkgOverrides = name: { enableIntegerSimple = false; } // lib.optionalAttrs (hasNativeBignum name) {
|
||||||
|
enableNativeBignum = false;
|
||||||
|
};
|
||||||
|
|
||||||
ghcDrvOverrides = drv: {
|
ghcDrvOverrides = drv: {
|
||||||
hardeningDisable = (drv.hardeningDisable or []) ++ [ "stackprotector" "format" ] ++ lib.optionals prev.stdenv.hostPlatform.isAarch32 [ "pic" "pie" ];
|
hardeningDisable = (drv.hardeningDisable or []) ++ [ "stackprotector" "format" ] ++ lib.optionals prev.stdenv.hostPlatform.isAarch32 [ "pic" "pie" ];
|
||||||
};
|
};
|
||||||
@ -20,13 +24,13 @@ final: prev: with prev;
|
|||||||
&& !lib.hasPrefix "ghc82" name
|
&& !lib.hasPrefix "ghc82" name
|
||||||
&& !lib.hasPrefix "ghcjs" name
|
&& !lib.hasPrefix "ghcjs" name
|
||||||
&& !lib.hasSuffix "Binary" name;
|
&& !lib.hasSuffix "Binary" name;
|
||||||
overrideCompiler = compiler:
|
overrideCompiler = name: compiler:
|
||||||
((compiler.override ghcPkgOverrides).overrideAttrs ghcDrvOverrides) // {
|
((compiler.override (ghcPkgOverrides name)).overrideAttrs ghcDrvOverrides) // {
|
||||||
dwarf = overrideCompiler compiler.dwarf;
|
dwarf = overrideCompiler name compiler.dwarf;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
lib.recursiveUpdate prev.haskell-nix {
|
lib.recursiveUpdate prev.haskell-nix {
|
||||||
compiler = lib.mapAttrs (_name: overrideCompiler)
|
compiler = lib.mapAttrs overrideCompiler
|
||||||
(lib.filterAttrs (name: _value: needsPatches name) prev.haskell-nix.compiler);
|
(lib.filterAttrs (name: _value: needsPatches name) prev.haskell-nix.compiler);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user