Skip to content

Commit dd6ce8c

Browse files
ggreifpeti
authored andcommitted
ghc: add new version 8.8.4
1 parent 5217492 commit dd6ce8c

2 files changed

Lines changed: 253 additions & 0 deletions

File tree

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
{ stdenv, pkgsBuildTarget, targetPackages
2+
3+
# build-tools
4+
, bootPkgs
5+
, autoconf, automake, coreutils, fetchurl, perl, python3, m4, sphinx
6+
, bash
7+
8+
, libiconv ? null, ncurses
9+
10+
, # GHC can be built with system libffi or a bundled one.
11+
libffi ? null
12+
13+
, useLLVM ? !stdenv.targetPlatform.isx86
14+
, # LLVM is conceptually a run-time-only depedendency, but for
15+
# non-x86, we need LLVM to bootstrap later stages, so it becomes a
16+
# build-time dependency too.
17+
buildLlvmPackages, llvmPackages
18+
19+
, # If enabled, GHC will be built with the GPL-free but slower integer-simple
20+
# library instead of the faster but GPLed integer-gmp library.
21+
enableIntegerSimple ? !(stdenv.lib.any (stdenv.lib.meta.platformMatch stdenv.hostPlatform) gmp.meta.platforms), gmp
22+
23+
, # If enabled, use -fPIC when compiling static libs.
24+
enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform
25+
26+
, # Whether to build dynamic libs for the standard library (on the target
27+
# platform). Static libs are always built.
28+
enableShared ? !stdenv.targetPlatform.isWindows && !stdenv.targetPlatform.useiOSPrebuilt
29+
30+
, # Whether to build terminfo.
31+
enableTerminfo ? !stdenv.targetPlatform.isWindows
32+
33+
, # What flavour to build. An empty string indicates no
34+
# specific flavour and falls back to ghc default values.
35+
ghcFlavour ? stdenv.lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)
36+
(if useLLVM then "perf-cross" else "perf-cross-ncg")
37+
38+
, # Whether to disable the large address space allocator
39+
# necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
40+
disableLargeAddressSpace ? stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64
41+
}:
42+
43+
assert !enableIntegerSimple -> gmp != null;
44+
45+
let
46+
inherit (stdenv) buildPlatform hostPlatform targetPlatform;
47+
48+
inherit (bootPkgs) ghc;
49+
50+
# TODO(@Ericson2314) Make unconditional
51+
targetPrefix = stdenv.lib.optionalString
52+
(targetPlatform != hostPlatform)
53+
"${targetPlatform.config}-";
54+
55+
buildMK = ''
56+
BuildFlavour = ${ghcFlavour}
57+
ifneq \"\$(BuildFlavour)\" \"\"
58+
include mk/flavours/\$(BuildFlavour).mk
59+
endif
60+
DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
61+
INTEGER_LIBRARY = ${if enableIntegerSimple then "integer-simple" else "integer-gmp"}
62+
'' + stdenv.lib.optionalString (targetPlatform != hostPlatform) ''
63+
Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"}
64+
CrossCompilePrefix = ${targetPrefix}
65+
HADDOCK_DOCS = NO
66+
BUILD_SPHINX_HTML = NO
67+
BUILD_SPHINX_PDF = NO
68+
'' + stdenv.lib.optionalString enableRelocatedStaticLibs ''
69+
GhcLibHcOpts += -fPIC
70+
GhcRtsHcOpts += -fPIC
71+
'' + stdenv.lib.optionalString targetPlatform.useAndroidPrebuilt ''
72+
EXTRA_CC_OPTS += -std=gnu99
73+
'';
74+
75+
# Splicer will pull out correct variations
76+
libDeps = platform: stdenv.lib.optional enableTerminfo ncurses
77+
++ [libffi]
78+
++ stdenv.lib.optional (!enableIntegerSimple) gmp
79+
++ stdenv.lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv;
80+
81+
toolsForTarget = [
82+
pkgsBuildTarget.targetPackages.stdenv.cc
83+
] ++ stdenv.lib.optional useLLVM buildLlvmPackages.llvm;
84+
85+
targetCC = builtins.head toolsForTarget;
86+
87+
# ld.gold is disabled for musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856
88+
# see #84670 and #49071 for more background.
89+
useLdGold = targetPlatform.isLinux && !(targetPlatform.useLLVM or false) && !targetPlatform.isMusl;
90+
91+
in
92+
stdenv.mkDerivation (rec {
93+
version = "8.8.4";
94+
name = "${targetPrefix}ghc-${version}";
95+
96+
src = fetchurl {
97+
url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz";
98+
sha256 = "0bgwbxxvdn56l91bp9p5d083gzcfdi6z8l8b17qzjpr3n8w5wl7h";
99+
};
100+
101+
enableParallelBuilding = true;
102+
103+
outputs = [ "out" "doc" ];
104+
105+
postPatch = "patchShebangs .";
106+
107+
# GHC is a bit confused on its cross terminology.
108+
preConfigure = ''
109+
for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
110+
export "''${env#TARGET_}=''${!env}"
111+
done
112+
# GHC is a bit confused on its cross terminology, as these would normally be
113+
# the *host* tools.
114+
export CC="${targetCC}/bin/${targetCC.targetPrefix}cc"
115+
export CXX="${targetCC}/bin/${targetCC.targetPrefix}cxx"
116+
# Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
117+
export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${stdenv.lib.optionalString useLdGold ".gold"}"
118+
export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as"
119+
export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar"
120+
export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"
121+
export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib"
122+
export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf"
123+
export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip"
124+
125+
echo -n "${buildMK}" > mk/build.mk
126+
sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
127+
'' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
128+
export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}"
129+
'' + stdenv.lib.optionalString stdenv.isDarwin ''
130+
export NIX_LDFLAGS+=" -no_dtrace_dof"
131+
'' + stdenv.lib.optionalString targetPlatform.useAndroidPrebuilt ''
132+
sed -i -e '5i ,("armv7a-unknown-linux-androideabi", ("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", "cortex-a8", ""))' llvm-targets
133+
'' + stdenv.lib.optionalString targetPlatform.isMusl ''
134+
echo "patching llvm-targets for musl targets..."
135+
echo "Cloning these existing '*-linux-gnu*' targets:"
136+
grep linux-gnu llvm-targets | sed 's/^/ /'
137+
echo "(go go gadget sed)"
138+
sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets
139+
echo "llvm-targets now contains these '*-linux-musl*' targets:"
140+
grep linux-musl llvm-targets | sed 's/^/ /'
141+
142+
echo "And now patching to preserve '-musleabi' as done with '-gnueabi'"
143+
# (aclocal.m4 is actual source, but patch configure as well since we don't re-gen)
144+
for x in configure aclocal.m4; do
145+
substituteInPlace $x \
146+
--replace '*-android*|*-gnueabi*)' \
147+
'*-android*|*-gnueabi*|*-musleabi*)'
148+
done
149+
'';
150+
151+
# TODO(@Ericson2314): Always pass "--target" and always prefix.
152+
configurePlatforms = [ "build" "host" ]
153+
++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
154+
155+
# `--with` flags for libraries needed for RTS linker
156+
configureFlags = [
157+
"--datadir=$doc/share/doc/ghc"
158+
"--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
159+
] ++ stdenv.lib.optionals (libffi != null) [
160+
"--with-system-libffi"
161+
"--with-ffi-includes=${targetPackages.libffi.dev}/include"
162+
"--with-ffi-libraries=${targetPackages.libffi.out}/lib"
163+
] ++ stdenv.lib.optionals (targetPlatform == hostPlatform && !enableIntegerSimple) [
164+
"--with-gmp-includes=${targetPackages.gmp.dev}/include"
165+
"--with-gmp-libraries=${targetPackages.gmp.out}/lib"
166+
] ++ stdenv.lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
167+
"--with-iconv-includes=${libiconv}/include"
168+
"--with-iconv-libraries=${libiconv}/lib"
169+
] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [
170+
"--enable-bootstrap-with-devel-snapshot"
171+
] ++ stdenv.lib.optionals useLdGold [
172+
"CFLAGS=-fuse-ld=gold"
173+
"CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
174+
"CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
175+
] ++ stdenv.lib.optionals (disableLargeAddressSpace) [
176+
"--disable-large-address-space"
177+
];
178+
179+
# Make sure we never relax`$PATH` and hooks support for compatibility.
180+
strictDeps = true;
181+
182+
# Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself.
183+
dontAddExtraLibs = true;
184+
185+
nativeBuildInputs = [
186+
perl autoconf automake m4 python3 sphinx
187+
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
188+
];
189+
190+
# For building runtime libs
191+
depsBuildTarget = toolsForTarget;
192+
193+
buildInputs = [ perl bash ] ++ (libDeps hostPlatform);
194+
195+
propagatedBuildInputs = [ targetPackages.stdenv.cc ]
196+
++ stdenv.lib.optional useLLVM llvmPackages.llvm;
197+
198+
depsTargetTarget = map stdenv.lib.getDev (libDeps targetPlatform);
199+
depsTargetTargetPropagated = map (stdenv.lib.getOutput "out") (libDeps targetPlatform);
200+
201+
# required, because otherwise all symbols from HSffi.o are stripped, and
202+
# that in turn causes GHCi to abort
203+
stripDebugFlags = [ "-S" ] ++ stdenv.lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols";
204+
205+
checkTarget = "test";
206+
207+
hardeningDisable = [ "format" ] ++ stdenv.lib.optional stdenv.targetPlatform.isMusl "pie";
208+
209+
postInstall = ''
210+
# Install the bash completion file.
211+
install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc
212+
213+
# Patch scripts to include "readelf" and "cat" in $PATH.
214+
for i in "$out/bin/"*; do
215+
test ! -h $i || continue
216+
egrep --quiet '^#!' <(head -n 1 $i) || continue
217+
sed -i -e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ targetPackages.stdenv.cc.bintools coreutils ]}"' $i
218+
done
219+
'';
220+
221+
passthru = {
222+
inherit bootPkgs targetPrefix;
223+
224+
inherit llvmPackages;
225+
inherit enableShared;
226+
227+
# Our Cabal compiler name
228+
haskellCompilerName = "ghc-${version}";
229+
};
230+
231+
meta = {
232+
homepage = "http://haskell.org/ghc";
233+
description = "The Glasgow Haskell Compiler";
234+
maintainers = with stdenv.lib.maintainers; [ marcweber andres peti ];
235+
inherit (ghc.meta) license platforms;
236+
};
237+
238+
} // stdenv.lib.optionalAttrs targetPlatform.useAndroidPrebuilt {
239+
dontStrip = true;
240+
dontPatchELF = true;
241+
noAuditTmpdir = true;
242+
})

pkgs/top-level/haskell-packages.nix

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ in {
6868
buildLlvmPackages = buildPackages.llvmPackages_7;
6969
llvmPackages = pkgs.llvmPackages_7;
7070
};
71+
ghc884 = callPackage ../development/compilers/ghc/8.8.4.nix {
72+
bootPkgs = packages.ghc865Binary;
73+
inherit (buildPackages.python3Packages) sphinx;
74+
buildLlvmPackages = buildPackages.llvmPackages_7;
75+
llvmPackages = pkgs.llvmPackages_7;
76+
};
7177
ghc8101 = callPackage ../development/compilers/ghc/8.10.1.nix {
7278
bootPkgs = packages.ghc865Binary;
7379
inherit (buildPackages.python3Packages) sphinx;
@@ -138,6 +144,11 @@ in {
138144
ghc = bh.compiler.ghc883;
139145
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-8.8.x.nix { };
140146
};
147+
ghc884 = callPackage ../development/haskell-modules {
148+
buildHaskellPackages = bh.packages.ghc884;
149+
ghc = bh.compiler.ghc884;
150+
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-8.8.x.nix { };
151+
};
141152
ghc8101 = callPackage ../development/haskell-modules {
142153
buildHaskellPackages = bh.packages.ghc8101;
143154
ghc = bh.compiler.ghc8101;

0 commit comments

Comments
 (0)