on iko/ghcjs-patch-master help sign in
Split configured-src out of ghc/default.nix
commite238451d42fbbc6c86a1d2c44382534b58873120 authorMoritz Angermann <moritz.angermann@gmail.com> dateWed 17 Jun 2020, 15:06 (6 years ago) parent22aa350
2 files changed+134−109
compiler/ghc/configured-src.nix+113 compiler/ghc/default.nix+21−109
compiler/ghc/configured-src.nixnew file+113
@@ -0,0 +1,113 @@
1+{ stdenv, fetchurl,
2+, ghc-version, ghc-patches, src-spec
3+, targetPrefix,
4+, targetPlatform, hostPlatform
5+, targetPackages
6+, perl, autoconf, automake, m4, python3, sphinx, ghc, bootPkgs
7+, autoreconfHook, toolsForTarget, bash
8+, libDeps
9+, useLLVM, llvmPackages
10+, targetCC
11+, enableIntegerSimple, targetGmp
12+, ncurses, targetLibffi, libiconv
13+, disableLargeAddressSpace
14+}:
15+stdenv.mkDerivation (rec {
16+
17+ version = ghc-version;
18+ patches = ghc-patches;
19+ name = "${targetPrefix}ghc-${ghc-version}-configured-src";
20+
21+ # Make sure we never relax`$PATH` and hooks support for compatability.
22+ strictDeps = true;
23+
24+ nativeBuildInputs = [
25+ perl autoconf automake m4 python3 sphinx
26+ ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
27+ ] ++ stdenv.lib.optional (patches != []) autoreconfHook;
28+
29+ # For building runtime libs
30+ depsBuildTarget = toolsForTarget;
31+
32+ buildInputs = [ perl bash ] ++ (libDeps hostPlatform);
33+
34+ propagatedBuildInputs = [ targetPackages.stdenv.cc ]
35+ ++ stdenv.lib.optional useLLVM llvmPackages.llvm;
36+
37+ depsTargetTarget = map stdenv.lib.getDev (libDeps targetPlatform);
38+ depsTargetTargetPropagated = map (stdenv.lib.getOutput "out") (libDeps targetPlatform);
39+
40+ postPatch = "patchShebangs .";
41+
42+ src = fetchurl { inherit (src-spec) url sha256; };
43+
44+ # GHC is a bit confused on its cross terminology.
45+ preConfigure = ''
46+ for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
47+ export "''${env#TARGET_}=''${!env}"
48+ done
49+ # GHC is a bit confused on its cross terminology, as these would normally be
50+ # the *host* tools.
51+ export CC="${targetCC}/bin/${targetCC.targetPrefix}cc"
52+ export CXX="${targetCC}/bin/${targetCC.targetPrefix}cxx"
53+ # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
54+ export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${stdenv.lib.optionalString targetPlatform.isAarch32 ".gold"}"
55+ export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as"
56+ export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar"
57+ export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"
58+ export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib"
59+ export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf"
60+ export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip"
61+
62+ echo -n "${buildMK}" > mk/build.mk
63+ sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
64+ '' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
65+ export NIX_LDFLAGS+=" -rpath $out/lib/${targetPrefix}ghc-${version}"
66+ '' + stdenv.lib.optionalString stdenv.isDarwin ''
67+ export NIX_LDFLAGS+=" -no_dtrace_dof"
68+ '' + stdenv.lib.optionalString targetPlatform.useAndroidPrebuilt ''
69+ 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
70+ '' + stdenv.lib.optionalString targetPlatform.isMusl ''
71+ echo "patching llvm-targets for musl targets..."
72+ echo "Cloning these existing '*-linux-gnu*' targets:"
73+ grep linux-gnu llvm-targets | sed 's/^/ /'
74+ echo "(go go gadget sed)"
75+ sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets
76+ echo "llvm-targets now contains these '*-linux-musl*' targets:"
77+ grep linux-musl llvm-targets | sed 's/^/ /'
78+
79+ echo "And now patching to preserve '-musleabi' as done with '-gnueabi'"
80+ # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen)
81+ for x in configure aclocal.m4; do
82+ substituteInPlace $x \
83+ --replace '*-android*|*-gnueabi*)' \
84+ '*-android*|*-gnueabi*|*-musleabi*)'
85+ done
86+ '';
87+
88+ configurePlatforms = [ "build" "host" "target" ];
89+ # `--with` flags for libraries needed for RTS linker
90+ configureFlags = [
91+ "--datadir=$doc/share/doc/ghc"
92+ "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
93+ ] ++ stdenv.lib.optionals (targetLibffi != null) ["--with-system-libffi" "--with-ffi-includes=${targetLibffi.dev}/include" "--with-ffi-libraries=${targetLibffi.out}/lib"
94+ ] ++ stdenv.lib.optional (!enableIntegerSimple) [
95+ "--with-gmp-includes=${targetGmp.dev}/include" "--with-gmp-libraries=${targetGmp.out}/lib"
96+ ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
97+ "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
98+ ] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [
99+ "--enable-bootstrap-with-devel-snapshot"
100+ ] ++ stdenv.lib.optionals (disableLargeAddressSpace) [
101+ "--disable-large-address-space"
102+ ] ++ stdenv.lib.optionals (targetPlatform.isAarch32) [
103+ "CFLAGS=-fuse-ld=gold"
104+ "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
105+ "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
106+ ] ;
107+
108+ outputs = [ "out" ];
109+ phases = [ "unpackPhase" "patchPhase" ]
110+ ++ stdenv.lib.optional (ghc-patches != []) "autoreconfPhase"
111+ ++ [ "configurePhase" "installPhase" ];
112+ installPhase = "cp -r . $out";
113+});
compiler/ghc/default.nix+21−109
@@ -131,109 +131,23 @@ let
131131
132132 targetCC = builtins.head toolsForTarget;
133133
134−in let configured-src = stdenv.mkDerivation (rec {
135−
136− version = ghc-version;
137−
138− patches = ghc-patches;
139−
140− name = "${targetPrefix}ghc-${ghc-version}-configured-src";
141−
142− # Make sure we never relax`$PATH` and hooks support for compatability.
143− strictDeps = true;
144−
145− nativeBuildInputs = [
146− perl autoconf automake m4 python3 sphinx
147− ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
148− ] ++ stdenv.lib.optional (patches != []) autoreconfHook;
149−
150− # For building runtime libs
151− depsBuildTarget = toolsForTarget;
152−
153− buildInputs = [ perl bash ] ++ (libDeps hostPlatform);
154−
155− propagatedBuildInputs = [ targetPackages.stdenv.cc ]
156− ++ stdenv.lib.optional useLLVM llvmPackages.llvm;
157−
158− depsTargetTarget = map stdenv.lib.getDev (libDeps targetPlatform);
159− depsTargetTargetPropagated = map (stdenv.lib.getOutput "out") (libDeps targetPlatform);
160−
161− postPatch = "patchShebangs .";
162−
163− src = fetchurl { inherit (src-spec) url sha256; };
164−
165− # GHC is a bit confused on its cross terminology.
166− preConfigure = ''
167− for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
168− export "''${env#TARGET_}=''${!env}"
169− done
170− # GHC is a bit confused on its cross terminology, as these would normally be
171− # the *host* tools.
172− export CC="${targetCC}/bin/${targetCC.targetPrefix}cc"
173− export CXX="${targetCC}/bin/${targetCC.targetPrefix}cxx"
174− # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
175− export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${stdenv.lib.optionalString targetPlatform.isAarch32 ".gold"}"
176− export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as"
177− export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar"
178− export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"
179− export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib"
180− export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf"
181− export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip"
182−
183− echo -n "${buildMK}" > mk/build.mk
184− sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
185− '' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
186− export NIX_LDFLAGS+=" -rpath $out/lib/${targetPrefix}ghc-${version}"
187− '' + stdenv.lib.optionalString stdenv.isDarwin ''
188− export NIX_LDFLAGS+=" -no_dtrace_dof"
189− '' + stdenv.lib.optionalString targetPlatform.useAndroidPrebuilt ''
190− 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
191− '' + stdenv.lib.optionalString targetPlatform.isMusl ''
192− echo "patching llvm-targets for musl targets..."
193− echo "Cloning these existing '*-linux-gnu*' targets:"
194− grep linux-gnu llvm-targets | sed 's/^/ /'
195− echo "(go go gadget sed)"
196− sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets
197− echo "llvm-targets now contains these '*-linux-musl*' targets:"
198− grep linux-musl llvm-targets | sed 's/^/ /'
199−
200− echo "And now patching to preserve '-musleabi' as done with '-gnueabi'"
201− # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen)
202− for x in configure aclocal.m4; do
203− substituteInPlace $x \
204− --replace '*-android*|*-gnueabi*)' \
205− '*-android*|*-gnueabi*|*-musleabi*)'
206− done
207− '';
208−
209− configurePlatforms = [ "build" "host" "target" ];
210− # `--with` flags for libraries needed for RTS linker
211− configureFlags = [
212− "--datadir=$doc/share/doc/ghc"
213− "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
214− ] ++ stdenv.lib.optionals (targetLibffi != null) ["--with-system-libffi" "--with-ffi-includes=${targetLibffi.dev}/include" "--with-ffi-libraries=${targetLibffi.out}/lib"
215− ] ++ stdenv.lib.optional (!enableIntegerSimple) [
216− "--with-gmp-includes=${targetGmp.dev}/include" "--with-gmp-libraries=${targetGmp.out}/lib"
217− ] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
218− "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
219− ] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [
220− "--enable-bootstrap-with-devel-snapshot"
221− ] ++ stdenv.lib.optionals (disableLargeAddressSpace) [
222− "--disable-large-address-space"
223− ] ++ stdenv.lib.optionals (targetPlatform.isAarch32) [
224− "CFLAGS=-fuse-ld=gold"
225− "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
226− "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
227− ] ;
228−
229− outputs = [ "out" ];
230− phases = [ "unpackPhase" "patchPhase" ]
231− ++ stdenv.lib.optional (ghc-patches != []) "autoreconfPhase"
232− ++ [ "configurePhase" "installPhase" ];
233− installPhase = "cp -r . $out";
234− });
235−
236− drv =stdenv.mkDerivation (rec {
134+ configured-src = import ./configured-src {
135+ stdenv fetchurl
136+ ghc-version ghc-patches src-spec
137+ targetPrefix
138+ targetPlatform hostPlatform
139+ targetPackages
140+ perl autoconf automake m4 python3 sphinx ghc bootPkgs
141+ autoreconfHook toolsForTarget bash
142+ libDeps
143+ useLLVM llvmPackages
144+ targetCC
145+ enableIntegerSimple targetGmp
146+ ncurses targetLibffi libiconv
147+ disableLargeAddressSpace
148+ };
149+in
150+stdenv.mkDerivation (rec {
237151 version = ghc-version;
238152 name = "${targetPrefix}ghc-${version}";
239153
@@ -368,15 +282,15 @@ in let configured-src = stdenv.mkDerivation (rec {
368282 if [[ ! -f "$out/bin/${targetPrefix}ghc-pkg" ]]; then
369283 echo "ERROR: Missing file $out/bin/${targetPrefix}ghc-pkg"
370284 exit 0
371− fi
285+ fi
372286 if [[ ! -d "$out/lib/${targetPrefix}ghc-${version}" ]]; then
373287 echo "ERROR: Missing directory $out/lib/${targetPrefix}ghc-${version}"
374288 exit 0
375− fi
289+ fi
376290 if (( $(ls -1 "$out/lib/${targetPrefix}ghc-${version}" | wc -l) < 30 )); then
377291 echo "ERROR: Expected more files in $out/lib/${targetPrefix}ghc-${version}"
378292 exit 0
379− fi
293+ fi
380294 '';
381295
382296 passthru = {
@@ -405,6 +319,4 @@ in let configured-src = stdenv.mkDerivation (rec {
405319 dontStrip = true;
406320 dontPatchELF = true;
407321 noAuditTmpdir = true;
408−});
409−
410−in drv
322+});