@@ -3,7 +3,7 @@
3# haskell.nix ships its own version of the ghc expression as it needs more
3# haskell.nix ships its own version of the ghc expression as it needs more
4# control over the expression to isolate it against varying <nixpkgs> and
4# control over the expression to isolate it against varying <nixpkgs> and
5# allow us to customize it to the way haskell.nix works.
5# allow us to customize it to the way haskell.nix works.
6−{ stdenv, targetPackages
6+{ stdenv, haskell-nix, targetPackages
8# build-tools
8# build-tools
@@ -33,15 +33,24 @@
34, # Whether to build dynamic libs for the standard library (on the target
34, # Whether to build dynamic libs for the standard library (on the target
35 # platform). Static libs are always built.
35 # platform). Static libs are always built.
36− enableShared ? !stdenv.targetPlatform.isWindows && !stdenv.targetPlatform.useiOSPrebuilt
36+ enableShared ? !haskell-nix.haskellLib.isCrossTarget
38−, # Whetherto build terminfo.
38+, # Whetherto build terminfo. Musl fails to build terminfo as ncurses seems to be linked to glibc
39− enableTerminfo ? !stdenv.targetPlatform.isWindows
39+ enableTerminfo ? !stdenv.targetPlatform.isWindows && !stdenv.targetPlatform.isMusl
41, # What flavour to build. An empty string indicates no
41, # What flavour to build. An empty string indicates no
42 # specific flavour and falls back to ghc default values.
42 # specific flavour and falls back to ghc default values.
43− ghcFlavour ? stdenv.lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)
43+ ghcFlavour ? stdenv.lib.optionalString haskell-nix.haskellLib.isCrossTarget (
46+ # TODO check if the issues with qemu and Aarch32 persist. See
47+ # https://github.com/input-output-hk/haskell.nix/pull/411/commits/1986264683067198e7fdc1d665351622b664712e
48+ if stdenv.targetPlatform.isAarch32
44− (if useLLVM then "quick-cross" else "perf-cross-ncg")
52+ else "perf-cross-ncg"
46, # Whether to disable the large address space allocator
55, # Whether to disable the large address space allocator
47 # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
56 # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
@@ -59,9 +68,15 @@ assert !enableIntegerSimple -> gmp != null;
61 inherit (stdenv) buildPlatform hostPlatform targetPlatform;
70 inherit (stdenv) buildPlatform hostPlatform targetPlatform;
71+ inherit (haskell-nix.haskellLib) isCrossTarget;
63 inherit (bootPkgs) ghc;
73 inherit (bootPkgs) ghc;
75+ # TODO check if this posible fix for segfaults works or not.
76+ libffiStaticEnabled = if libffi == null || !stdenv.targetPlatform.isMusl
78+ else targetPackages.libffi.overrideAttrs (old: { dontDisableStatic = true; });
65 # TODO(@Ericson2314) Make unconditional
80 # TODO(@Ericson2314) Make unconditional
66 targetPrefix = stdenv.lib.optionalString
81 targetPrefix = stdenv.lib.optionalString
67 (targetPlatform != hostPlatform)
82 (targetPlatform != hostPlatform)
@@ -75,8 +90,9 @@ let
75 DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
90 DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
76 INTEGER_LIBRARY = ${if enableIntegerSimple then "integer-simple" else "integer-gmp"}
91 INTEGER_LIBRARY = ${if enableIntegerSimple then "integer-simple" else "integer-gmp"}
77 '' + stdenv.lib.optionalString (targetPlatform != hostPlatform) ''
92 '' + stdenv.lib.optionalString (targetPlatform != hostPlatform) ''
78− Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"}
79 CrossCompilePrefix = ${targetPrefix}
93 CrossCompilePrefix = ${targetPrefix}
94+ '' + stdenv.lib.optionalString isCrossTarget ''
95+ Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"}
80 HADDOCK_DOCS = NO
96 HADDOCK_DOCS = NO
81 BUILD_SPHINX_HTML = NO
97 BUILD_SPHINX_HTML = NO
82 BUILD_SPHINX_PDF = NO
98 BUILD_SPHINX_PDF = NO
@@ -88,11 +104,19 @@ let
88 '' + stdenv.lib.optionalString useLLVM ''
104 '' + stdenv.lib.optionalString useLLVM ''
89 GhcStage2HcOpts += -fast-llvm
105 GhcStage2HcOpts += -fast-llvm
90 GhcLibHcOpts += -fast-llvm
106 GhcLibHcOpts += -fast-llvm
107+ '' + stdenv.lib.optionalString (!enableTerminfo) ''
110+ # While split sections are now enabled by default in ghc 8.8 for windows,
111+ # the seem to lead to `too many sections` errors when building base for
113+ + stdenv.lib.optionalString targetPlatform.isWindows ''
93 # Splicer will pull out correct variations
117 # Splicer will pull out correct variations
94 libDeps = platform: stdenv.lib.optional enableTerminfo [ ncurses ]
118 libDeps = platform: stdenv.lib.optional enableTerminfo [ ncurses ]
95− ++ [libffi]
119+ ++ [libffiStaticEnabled]
96 ++ stdenv.lib.optional (!enableIntegerSimple) gmp
120 ++ stdenv.lib.optional (!enableIntegerSimple) gmp
97 ++ stdenv.lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv;
121 ++ stdenv.lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv;
@@ -184,7 +208,7 @@ in let configured-src = stdenv.mkDerivation (rec {
184 configureFlags = [
208 configureFlags = [
185 "--datadir=$doc/share/doc/ghc"
209 "--datadir=$doc/share/doc/ghc"
186 "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
210 "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
187− ] ++ stdenv.lib.optionals (libffi != null) ["--with-system-libffi" "--with-ffi-includes=${targetPackages.libffi.dev}/include" "--with-ffi-libraries=${targetPackages.libffi.out}/lib"
211+ ] ++ stdenv.lib.optionals (libffiStaticEnabled != null) ["--with-system-libffi" "--with-ffi-includes=${libffiStaticEnabled.dev}/include" "--with-ffi-libraries=${libffiStaticEnabled.out}/lib"
188 ] ++ stdenv.lib.optional (!enableIntegerSimple) [
212 ] ++ stdenv.lib.optional (!enableIntegerSimple) [
189 "--with-gmp-includes=${targetPackages.gmp.dev}/include" "--with-gmp-libraries=${targetPackages.gmp.out}/lib"
213 "--with-gmp-includes=${targetPackages.gmp.dev}/include" "--with-gmp-libraries=${targetPackages.gmp.out}/lib"
190 ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
214 ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
@@ -298,7 +322,12 @@ in let configured-src = stdenv.mkDerivation (rec {
298 for i in "$out/bin/"*; do
322 for i in "$out/bin/"*; do
299 test ! -h $i || continue
323 test ! -h $i || continue
300 egrep --quiet '^#!' <(head -n 1 $i) || continue
324 egrep --quiet '^#!' <(head -n 1 $i) || continue
325+ # The ghcprog fixup is for musl (where runhaskell script just needs to point to the correct
326+ # ghc program to work).
301− sed -i -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ targetPackages.stdenv.cc.bintools coreutils ]}"' $i
328+ -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ targetPackages.stdenv.cc.bintools coreutils ]}"' \
329+ -e 's/ghcprog="ghc-/ghcprog="${targetPrefix}ghc-/' \
303 '' + installDeps targetPrefix;
332 '' + installDeps targetPrefix;